I am reading a ebook called Basic image processing in Mathematica which can download free in the iBooks. In the page 114,it introduce a function ImageApplyIndexed.

i = ConstantImage[Black, {50, 50}];
{width, height} = ImageDimensions@i;
f[pixel_, pos_] := 
Module[{dis = Norm[{width/2, height/2} - pos]}, 
pixel + dis/Norm[Min[width/2, height/2]]];
ImageApplyIndexed[f, i]

output: enter image description here

But if I change the ImageSize of i:

 i = ConstantImage[Black, {100, 50}];

output:enter image description here

I don't know why the center of the black circle not in the center of the image?


1 Answer 1


ImageApplyIndexed passes an index to your function, not X/Y coordinates, i.e. a list containing the row index and the column index (in that order). So you need to you Norm[{height/2, width/2} - pos. Because height is the number of rows, and width is the number of columns.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.