Zoubeir - I'm noticing the same with your code for a 3744x5616 RGB image. It seems though that the bottleneck is with the "second" part of the code where you update the blue matrix. Since you haven't defined a size for it, it is constantly being resized on all subsequent iterations of your for loops. I suggest that you pre-size this matrix as
blue = zeros(x,y,3,'uint8');
for i=1:x
for j=1:y
blue(i,j,1) = R(i,j);
blue(i,j,2) = G(i,j);
blue(i,j,3) = B(i,j);
end
end
There may be some other optimizations to your first set of for loops but I would start with the pre-sizing of blue. (Note that with this modification, it took about five seconds to execute your code. With the previous version, I killed the processing after a couple of minutes.)
Best Answer