Let's try to perform color isolation for our lake fence photograph. The goal will be to convert the whole image to grayscale, except the fence tips, that should remain red. Here are the steps to accomplish this:
First, we will load the image and generate the same mask as before, using thresholding, cleaning, and dilation:
>> img = imread('my_image_color.bmp'); >> [output2] = RGBThreshold(img,[160 130 130]); >> output2(1:100,:) = 0; >> mask = imdilate(output2,strel('disk', 2));
Then, we must use the process described above to separate the color channels:
>> R = img(:,:,1); % store R channel in new matrix >> G = img(:,:,2); % store G channel in new matrix >> B = img(:,:,3); % store B channel in new matrix
Now it is time to perform masking. We want all pixels outside our regions of interest to turn to grayscale, which can be achieved by assigning to all channels the same values (which can be acquired by
rgb2gray
). All these...