MATLAB: How to put or replace color in rgb/greyscale picture

blobscolorImage Processing Toolboximage segmentationmaskthreshold

Hello!
Need some assistance here
Anyone knows how to put the blue color as presented in these pictures below?
Seems like the bubbles blobs (White/grey) has the same rgb value to the other non-bubble area. Black blobs are pores.

Best Answer

Try this:
rgbImage = imread('image.jpeg');
subplot(2, 1, 1);
imshow(rgbImage);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Get the yellow mask
yellowMask = redChannel > 128 & greenChannel > 128;
% Get the white mask
whiteMask = redChannel > 128 & greenChannel > 128 & blueChannel > 128;
% Make yellow mask green
redChannel(yellowMask) = 0;
greenChannel(yellowMask) = 255;
blueChannel(yellowMask) = 0;
% Make the white mask blue
redChannel(whiteMask) = 0;
greenChannel(whiteMask) = 0;
blueChannel(whiteMask) = 255;
% Recombine separate color channels into a single, true color RGB image.
rgbImage2 = cat(3, redChannel, greenChannel, blueChannel);
subplot(2, 1, 2);
imshow(rgbImage2);