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

조회 수: 1 (최근 30일)
nissrine Neyy
nissrine Neyy 2021년 3월 27일
댓글: nissrine Neyy 2021년 3월 27일
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 ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by