plotting the histogram of images (difference in MATLAB and ImageJ)
Show older comments
I need to plot the histogram of a medical image (512*512) in MATLAB but as I could not find how to set a good range for the x-y axis and I was not sure about the accuracy of imhist command (it looked somehow strange!) I tried to write the code as following however it does not work. I will highly appreciate any suggestions on how to remove the error(s) and plot the histogram of the image in this regard.
A=dicomread('med.dcm');
C := matrix (255,2);
B := matrix(512 512);
binwidth = max(A(:))- min(A(:));
for k=1:512
for l=1:512
for j=0:256
A(k,l) = min (A(:))+j*binwidth;
if A(k,l)<A(k,l)+binwidth/2
B(k,l)== A(k,l);
elseif A(k,l)== A(k,l)+binwidth/2
B(k,l)== A(k,l);
else
B(k,l)== A(k,l)+binwidth
end
end
end
end
s==0;
for i=min(A(:)): max(A(:))
for p=1:262144
for k=1:512
for l=1:512
if B(k,l)== i
C(p,2)==s+1;
else
i=i+binwidth;
C(p,2)==s;
C(p,1)==i;
end
end
end
end
end
hist(C(:))
9 Comments
jonas
on 9 Aug 2018
If you do not want to use imhist (for whatever reason), why dont you use one of the others like histogram?
Image Analyst
on 9 Aug 2018
Edited: Image Analyst
on 9 Aug 2018
Why do you think imhist is inaccurate? Can you attach your dcm file? And a screenshot of what it looks like, and what you expected it to look like?
Shel
on 10 Aug 2018
Shel
on 10 Aug 2018
Correct me if I'm wrong, but those two last images do not look the same. The one from ImageJ has clearly been filtered (smoothing?), and that's why the tails of the histogram are gone. You can clearly see a difference in texture.
The first images look more alike, but their histograms are also very similar. The difference could be related to number of bins or some artifact from the image import. You should compare mean and std to see if they are truly different or if it is a matter of perception.
Shel
on 13 Aug 2018
Well, I've never used ImageJ, but to me it seems quite obvious that those two images are not identical. See attached figure. My eyes, as well as the features of the histogram, tells me that the ImageJ one has been tampered with somehow. My guess is that the filter you applied is not the same in MATLAB as in ImageJ. Perhaps the unit of 7 differs, or perhaps it is the method involved that is different.
And no, I'm not saying that ImageJ does anything automatically. The others images you uploaded does not have the same smooth features.
Shel
on 15 Aug 2018
Answers (0)
Categories
Find more on Histograms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!