4
$\begingroup$

I want to systematically measure image intensity around each of the points in this 256x256 image.

i0:

Original image

I already have centroid locating code to figure out the centers of each of these points. To measure the intensity around each point within a set radius I was planning on using ImageMeasurements with a systematically created Mask using Graphics.

The masking graphic for a particular point:

mask = Graphics[{Black, Rectangle[{0, 0}, {256, 256}], White, 
Disk[Abs[{0, 256} - pos], 7]}];

Where pos is the position of the particular point of interest, in this case {66.6664, 8.74333}. The Abs[{0, 256} - pos] is to get the disk in the disk in the correct position due to different image indexing and graphic indexing.

i1:

Masking image

Next I planned to use

ImageMeasurements[i0,"Mean",Masking->i1]

However to check whether the mask was measuring what I thought it was I took a look at ImageMultiply. What worries me is this: when I do ImageMultiply[i0,i1] the result is:

i0 * i1

enter image description here

I found a work around by using

ImageMultiply[i0,Image[Show[i0,i1]]]

i0 * Image[Show[i0,i1]]

enter image description here

And indeed the two masks: i1 and Image[Show[i0,i1]] give different results with ImageMeasurements. I'm inclined to think the later mask gives the right answer. But I am wondering why ImageMultiply[i0,i1] produces such a noticeably undesired result. I found this article to be interesting, as it discusses how ImageSize can possibly mess things up because one function displays in "printer pixel" sizes (72 ppi) and the other in "screen resolution" pixel sizes.

Does anybody know what options I am missing with ImageMultiply[i0,i1]? Why it does not work correctly? Or know a better approach to my problem?

Much thanks

$\endgroup$
2
  • $\begingroup$ please provide traj or modify your code so that it is not needed $\endgroup$
    – chris
    Commented May 2, 2015 at 7:28
  • $\begingroup$ The answer is simple: i1 // ImageDimensions is not the same as i0 // ImageDimensions $\endgroup$
    – chris
    Commented May 2, 2015 at 7:35

2 Answers 2

3
$\begingroup$

The problem is caused by padding that is added around the Graphics scene by default.

visible padding

You can disable it by setting PlotRangePadding to 0 or None:

mask = Graphics[{Black, Rectangle[{0, 0}, {256, 256}], White, 
   Disk[Abs[{0, 256} - pos], 7]}, PlotRangePadding -> 0]
$\endgroup$
1
  • $\begingroup$ @DarrenM if an answer solves your problem you should mark it as "accepted" it by clicking the gray check mark (✓) on the left side of the answer. $\endgroup$
    – shrx
    Commented May 3, 2015 at 8:35
0
$\begingroup$
mask2 = mask // ImageResize[#, ImageDimensions[img]] &;
mask2 // ImageDimensions 

(* {256,256} *)

ImageMultiply[img, mask2]

Mathematica graphics

ImageMeasurements[img, "Mean", Masking -> mask2]

(* {0.281368,0.281368,0.281368} *)

$\endgroup$
2
  • $\begingroup$ Thank you Chris. But, that doesn't work for me for some reason. When I use the i1 graphics mask I get 0.281 as you did. And when I use the i0 * Image[Show[i0,i1]] mask I get 0.339. $\endgroup$
    – DarrenM
    Commented May 2, 2015 at 8:12
  • $\begingroup$ Thank you Chris. But, that doesn't work for me for some reason. When I use the i1 graphics mask I get 0.281 as you did. And when I use the i0 * Image[Show[i0,i1]] mask I get 0.339. When I use the resize function you described I get 0.281, and when I use the ImageMultiply[i0, "resized" image], I get the same weird border like in the i0 * i1 image I posted above. It seems odd that the code gave you the correct mask (which it didn't for me) but the same ImageMeasurement as the incorrect mask (i1). Thoughts? $\endgroup$
    – DarrenM
    Commented May 2, 2015 at 8:18

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.