如何找到直方图的值?

时间:2012-11-14 09:50:12

标签: matlab user-interface histogram

我使用matlab GUI。这是我的代码:

data = guidata(gcbo);

for i = 1:5
  citra3{i} = imread(['D:\,,TA,,\Skripsi Saya\Minggu, 6 Mei 2012\Tugas_Akhir1\Pelatihan\temulawak\' num2str(i) '.jpg']);

    graylawak{i}=rgb2gray(citra3{i});
    citra3{i} = imresize(graylawak{i}, [20 15]);

如何在不使用imhist的情况下找到图像直方图的值?因为直方图的值我会用来计算相似度。我非常感谢你给予的帮助。

1 个答案:

答案 0 :(得分:1)

我假设您想要获得citra3数组的每个元素中灰度值的直方图。 要做到这一点,你可以这样做:

% This turns the 2D image into a vector:
foo = reshape(citra3{i},1,numel(citra3{i}));
% As the pixel values are in uint8, they can have 8 bit (2^8=256) different values.
% Make one bin for each possible pixel value:
numberOfBins = 256;
% Convert the image data (uint8) to double precision values:
foobar = double(foo);
% Calculate the distribution of values within the bins:
[n,xout] = hist(foobar,numberOfBins); 
% Plot the resulting histogram:
bar(xout,n)

这是否回答了这个问题?