[英]Make histogram diagram without imhist
我正在嘗試不使用imhist函數制作圖像的直方圖。 如何在不使用imhist的情況下復制它?
originalImage = imread('hips.png');
imhist(originalImage); title('Histogram with Matlab');
我知道我應該創建一個2D數組,並使用2 for循環轉到每個像素,但是我不知道下一步該怎么做。
謝謝。
您可以使用hist函數獲取每個頻率值的像素數。 然后,您需要實現繪圖部分。
代碼如下所示:
function myimhist(img)
img = im2uint8(img);
[count,bin] = hist(img(:), 0:255);
stem(bin,count, 'Marker','none')
hAx = gca;
set(hAx, 'XLim',[0 255], 'XTickLabel',[], 'Box','on')
%# create axes, and draw grayscale colorbar
hAx2 = axes('Position',get(hAx,'Position'), 'HitTest','off');
image(0:255, [0 1], repmat(linspace(0,1,256),[1 1 3]), 'Parent',hAx2)
set(hAx2, 'XLim',[0 255], 'YLim',[0 1], 'YTick',[], 'Box','on')
%# resize the axis to make room for the colorbar
set(hAx, 'Units','pixels')
p = get(hAx, 'Position');
set(hAx, 'Position',[p(1) p(2)+26 p(3) p(4)-26])
set(hAx, 'Units','normalized')
%# position colorbar at bottom
set(hAx2, 'Units','pixels')
p = get(hAx2, 'Position');
set(hAx2, 'Position',[p(1:3) 26])
set(hAx2, 'Units','normalized')
%# link x-limits of the two axes
linkaxes([hAx;hAx2], 'x')
set(gcf, 'CurrentAxes',hAx)
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.