/ / Vytvorte histogramový diagram bez

Vytvorte diagram histogramu bez imhist - matlab

Snažím sa vytvoriť histogram obrázka bez použitia imhistickej funkcie. Ako to môžem replikovať bez použitia imhistov?

originalImage = imread("hips.png");
imhist(originalImage); title("Histogram with Matlab");

Viem, že by som mal vytvoriť 2D pole a prejsť na každý pixel s 2 pre slučku, ale neviem, čo ďalej.

Ďakujem.

odpovede:

3 pre odpoveď č. 1

Pomocou funkcie hist môžete získať počet pixelov pre každú hodnotu frekvencie. Potom musíte implementovať časť vykreslenia.

Kód je uvedený nižšie:

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