# of counts in whole image vs #counts in masked image +mask? shoul be same or not???

1 Ansicht (letzte 30 Tage)
Dear all,
I did histograms of :
1. whole image
2. image masked
3. image with inverted masked
I would expect sum of counts in 2+3 shall be same as in 1. But it is not. So is this because of the mask line width (I do masking with imfreehand).. and double assigning of some pixels to masked and reversed masked region?, or is my procedure somehow wrong. Scheme is as follows
masked_image=whole_image.*mask;
inverse_masked_image=whole_image.*(~mask)
the numbers differ like 1=65536, and(2+3)=78086..
thanks!
  4 Kommentare
Image Analyst
Image Analyst am 17 Mai 2014
I don't have that image. Can you illustrate with a standard demo image like cameraman.tif or something?
Aga
Aga am 17 Mai 2014
thank you..here it is test with cameramn, and now with single file all works fine as it should and as you said-:) Also the sum of nelements in all images is same. And as expected if I add sum of the counts of masked and inversely masked image is also same as the one from whole image.
My real images are 4D (slices). So I guess I do something wrong with indexing while masking. I am new in Matlab and still unsure. And again since these are histograms I am interested in , is the problem with masked pixel as explained in reply to your second comment that puzzles me.Shall I really remove 0 pixels, or can I really set them to NaN so that they are separated from "in ROI" )-pixels (I tried, it did not work). Well but now I am bit more puzzled.. I did also histograms for cameramann images.. and there are now counts for 0. So it seems to be correctly accounted for? Than what I did wiht manually removing 0 pixels is wrong?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 17 Mai 2014
All images are the same size (unless you cropped them), so all images should have the same number of counts . The fact that some pixels have been set to 0 or 255 (masked) does not affect the number of pixels they have and so the count from imhist() or hist() or histc() will be the same, which is numel(grayImage).
  1 Kommentar
Aga
Aga am 17 Mai 2014
thank you very much.The images were not cropped. But I guess I must have done something wrong (it could be that I remove some pixels =0, and forgot it) and than easily run into panic. When i just simply add masked+ inverted mask image I end up with nice whole image, as expected. Can I ask you another question?What is the right method of removing masked pixels from histogram? I used find to find the ncenters that were either equal to 0 , or first biggest and last smaller, and remove that pixels.But than I remove also true pixels from not masked region. I tohugh setting masked pixel to NaN would help, but these are also recognised as 0.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by