[Matlab] Constructing a 3d histogram from a picture
I wrote a function for constructing histogram for an arbitrary picture. It reads only R (red) and G(green) channel.
When I read a picture with imread command, and I call a function with myhistogram2RG(image,10) I get an error.
function H = myhistogram2RG(img1, bins)
%Here you make eqaul distribution for the pixels
img1 = floor(double(img1)*(bins) / 255 ) + 1 ;
%Matrice bins * bins all of zeroes
H = zeros(bins, bins);
for i=1:size(img1, 1)
for j = 1:size(img1, 2)
R = img1(i,j,1);
G = img1(i,j,2);
%When the pixel is the right colour add one to corresponding
%element in the matrice
H(R,G) = H(R,G) + 1;
H = H / sum(sum(H));
I don't understand why isn't working. Thank you for your help.
Attempted to access H(11,8); index out of bounds because
Re: [Matlab] Constructing a 3d histogram from a picture