rgbImage=imread('new2.png');
subplot(2, 3, 1);
imshow(rgbImage);
title('Original Color Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
binaryImageR = redChannel > 233;
binaryImageG = redChannel > 25 & redChannel < 30;
binaryImageB = blueChannel > 35 & blueChannel < 40;
subplot(2, 3, 2);
imshow(binaryImageR);
title('Red Binary Image', 'FontSize', fontSize);
subplot(2, 3, 3);
imshow(binaryImageG);
title('Green Binary Image', 'FontSize', fontSize);
subplot(2, 3, 4);
imshow(binaryImageB);
title('Red Binary Image', 'FontSize', fontSize);
binaryImage = binaryImageR & binaryImageG & binaryImageB;
subplot(2, 3, 5);
imshow(binaryImage);
title('Overall Binary Image', 'FontSize', fontSize);
maskedRgbImage = bsxfun(@times, rgbImage, cast(binaryImage,class(rgbImage)));
subplot(2, 3, 6);
imshow(maskedRgbImage);
title('Masked Color Image', 'FontSize', fontSize);
Best Answer