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

1 visualizzazione (ultimi 30 giorni)
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 ?

Risposte (1)

Image Analyst
Image Analyst il 27 Mar 2021
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 Commento
nissrine Neyy
nissrine Neyy il 27 Mar 2021
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 ?

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by