How do i write a histogram code without the built in functions ?

1 次查看(过去 30 天)
I want to creat a histogram code, knowing that it'll be counting the number of occurence of 3 values of a pixel.
the idea is i have 3 matrices (L1im, L2im, L3im) representing information extracted from an image, size of each of them is 256*226, and i want to compute how many times a combination of let's say (52,6,40) occures (each number correspends to a matrix/component but they're all of the same pixel)
for i = 1 : 256
for j = 1 : 256
for k = 1 : 256
if (L1im == i) & (L2im == j) & (L3im == k)
myhist(i,j,k)= myhist(i,j,k)+1;
end
end
end
end
can anyone help please ?

回答(1 个)

Image Analyst
Image Analyst 2021-3-27
That's obviously not correct. Try this 3 dimensional histogram
[L1im, L2im, L3im] = imsplit(rgbImage) % Optionasl, if you want to do this instead of operating on the RGB image directly in the loop
[rows, columns, numberOfColorChannels] = size(rgbImage)
myhist = zeros(256, 256, 256); % histogram for uint8 where gray levels go up to 255
for col = 1 : columns
for row = 1 : rows
r = L1im(row, col);
g = L2im(row, col);
b = L3im(row, col);
myhist = myhist(r, g, b) + 1;
end
end
  1 个评论
nissrine Neyy
nissrine Neyy 2021-3-27
Thank you@Image Analyst for you response, i tryed it and i get this error :
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in lbp_pca (line 89)
myhist = myhist(r, g, b) + 1;
how can i fixe it ?

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by