- because you pass a 1x1 x value and a 1x2 y value to line, it actually plots two points, not a line. One point at (thresholdLevel, y(1)) the other at (thresholdLevel, (y(2)).
- graythresh return a normalised threshold in the range [0 1], so to plot your line on your histogram you need to scale the threshold back to the intensity range of your image
How to find pixel counts from an Histogram for 2D uint16 images
조회 수: 4 (최근 30일)
이전 댓글 표시
I have double MR image (2D uint16), I have plotted hitogram of my original image and I want to find the Otsu threshold level and display it on the histogram. There is my code : How could I correct it please. Thank you.
subplot(2, 4, 2);
h=histogram(grayImage);
title('Histogram of Original Image');
thresholdLevel = graythresh(grayImage);
y = ylim();
line(thresholdLevel, y,'Color', 'r');
grid on;
댓글 수: 0
채택된 답변
Guillaume
2018년 1월 18일
You made two mistakes:
So the fix:
line(repelem(threshold * intmax('uint16'), 2), y, 'Color', 'r')
댓글 수: 0
추가 답변 (1개)
Image Analyst
2018년 1월 18일
Try this:
h=histogram(grayImage);
title('Histogram of Original Image');
thresholdLevel = graythresh(grayImage)
% Convert to an actual gray level.
thresholdLevel = thresholdLevel * intmax(class(grayImage))
line([thresholdLevel, thresholdLevel], ylim, 'Color', 'r', 'LineWidth', 2); % Plot vertical line.
grid on;
% Threshold the image.
binaryImage = grayImage > thresholdLevel;
댓글 수: 8
Guillaume
2018년 1월 22일
Note that there shouldn't be any difference difference between using the threshold returned by graythresh and calling imbinarize with no options, since both end up calling otsuthresh, using 256 bins, after having converted the image to uint8.
The problem with using
thresholdLevel = thresholdLevel * intmax(class(grayImage))
is that it is only valid for unsigned classes (which was the case in the original question, but no longer is for the dicom image given). For signed classes, the formula should be:
classrange = [intmin(class(grayImage)), intmax(class(grayImage))];
thresholdLevel = thresholdLevel*diff(classrange) + classrange(1);
That is, for int16 images the threshold is between -32768 and 32767, not 0 and 32767.
Note 2: you should remove the metadata from the images you post here, particularly patient information, unless it's made up.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!