I have an RGB image (of type uint8) and I want to perform the following process:
- Quantize the image to 16 levels (for each layer)
- calculate the histogram of each RGB combination: first I need a 16*16*16 matrix to hold those values - i.e if we denote the histogram matrix
hist
thenhist(2,9,3)
should hold the amount of pixels in the histogram with intensity levels of r=2, g=9, b=3 etc. the next stage is to reshape it into a 4096*1 vector (but that's the easy part)
for now I have the following implementation:
function hist = compRGBHist(I)
I = I./16 % quantize to 16 color levels
hist = zeros(16,16,16);
[m, n, ~] = size(I);
for i=1:m
for j = 1:n
rgb = impixel(I,j,i);
r = rgb(1);
g = rgb(2);
b = rgb(3);
A(r,g,b) = A(r,g,b) + 1;
end
end
hist = reshape(hist, 4096, 1);
end
this implementation works, but it is VERY slow - I need to repeat the process a 100 times (as part of implementing a particle filter), and even though performing it on quite small images (actually image portions) of size ~80*40 it takes very long time. I'm looking for a more efficient way to do this. thanks!