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

1 view (last 30 days)
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
jonas on 13 Aug 2018
Edited: jonas 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
Shel on 15 Aug 2018
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)

Community Treasure Hunt

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

Start Hunting!