That's not a gray scale image you attached, it's an RGB image. So try this
rgbImage = imread('C1fig.jpg');
whos rgbImage
subplot(2, 1, 1);
imshow(rgbImage);
title('Original RGB image C1fig.jpg');
axis('on', 'image');
impixelinfo
mask = rgbImage(:, :, 1) == 0;
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
redChannel(mask) = 255;
greenChannel(mask) = 0;
blueChannel(mask) = 0;
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
subplot(2, 1, 2);
imshow(rgbImage);
axis('on', 'image');
impixelinfo
title('Altered RGB image');
If it really is a gray scale image, you can try this:
grayImage = imread('C1fig.jpg');
if ndims(grayImage) == 3;
grayImage = rgb2gray(grayImage);
end
whos grayImage
subplot(2, 1, 1);
imshow(grayImage);
title('Original image C1fig.jpg');
axis('on', 'image');
impixelinfo
mask = grayImage == 0;
redChannel = grayImage;
greenChannel = grayImage;
blueChannel = grayImage;
redChannel(mask) = 255;
greenChannel(mask) = 0;
blueChannel(mask) = 0;
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
subplot(2, 1, 2);
imshow(rgbImage);
axis('on', 'image');
impixelinfo
title('Altered RGB image');
Best Answer