How do i write a histogram code without the built in functions ?
4 次查看(过去 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 ?
0 个评论
回答(1 个)
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!