Hi I have loaded an image, thus creating a 3D matrix.
img1 = imread('bluebird.jpg')
I know that for a vector, i can create another vector based on a logic test and use this other vector as index like this:
speeds = [20 77 55 90 87 65 67 72 55]
invalid = speed > 70
speeds(invalid) = 0
This will set all invalid speed in speeds to 0.
But I have not figured out how to do it with a 3D matrix (an image).
What I want to do is swap color components 1 (red) and 3 (blue) for every pixel where the blue component is at least 20% higher than the average of the three components (the gray scale).
I have tried this:
img1 = imread('bluebird.jpg');
img2 = img1;
m = mean(img1, 3);
blues = img1(:,:,3) > 1.2*m;
img2(blues, [3,2,1]) = img1(blues, [1,2,3]);
But that did not work. The variable blues successfully get the pixels I want (the ones with a dominant blue component), but I get a illegal syntax on the last line.
Is it possible to do what I want? If so, how?
Thanks in advance.