Another technique we have already covered, that is changed in the task of color image processing, is image thresholding. Color images must be thresholded in each channel separately using a proper threshold and then the results must be combined together. Let's try to do this using the automated Otsu thresholding technique we presented in Chapter 2, Working with Pixels in Grayscale Images.
First, the color channels should be thresholded one by one. Let's see how, writing a script under the name ColorOtsuThresholding.m
:
img_color = imread('my_image_color.bmp'); % Load image red = im2bw(img_color(:,:,1)); % Threshold red channel green = im2bw(img_color(:,:,2)); % Threshold green channel blue = im2bw(img_color(:,:,3)); % Threshold blue channel bin_image_or = red | green | blue; % Find union using OR bin_image_and = red & green & blue; % Find intersection using AND subplot(1,3,1),imshow(img_color),title('Original Image') subplot(1,3,2),imshow(bin_image_or),title...