plotting the histogram of images (difference in MATLAB and ImageJ)

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

If you do not want to use imhist (for whatever reason), why dont you use one of the others like histogram?
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?
It is more likely that your data or your interpretation of the histogram is corrupted or wrong rather than the imhist function.
Thanks for your response: here is the filtering both by matlab and imagej.
As it can be seen in imagej the domain becomes shorter and the peak value increase but in matlab it seems that the domain in the X axis has become wider.
Also, there is a lot of difference between the images and histograms that is plotted by the two software. P.S. I have attached the original pic in the ZIp file because dicom files are not supported here.
Thanks in advance
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.
Do you mean that ImageJ smoothed the images automatically? ( because imagej besides filtering have a plugin for smoothing which I did not use in this case) the last two images have been filtered by the radius 7, one with ImageJ and the other with MATLAB with nothing more of filtering, smoothing or else.
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.
Thanks for your time answering my questions. As I found, the filtering in imagej is in a circular form (setting a radius for filtration) and matlab is in square,rectangle. Might it be the reason? Also, would you please let me know what is wrong with my code in the first comment? Thanks

Sign in to comment.

Answers (0)

Asked:

on 9 Aug 2018

Commented:

on 15 Aug 2018

Community Treasure Hunt

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

Start Hunting!