Reputation: 1075
I have a code to run, which uses an original image and a mask image. The code assumes that the original image is RGB, but my original image is gray scale. This must be the result of the MATLAB whos
command when I run the code:
Name Size Bytes Class Attributes
mask 308x206 63448 logical
origImg 308x206x3 190344 uint8
The mask is produced by making part of the image white and the rest is black (in a simple software like windows paint).
I want to use a gray-scale image as the origImg
and produce the mask from the origImg
in windows paint, but the result of the MATLAB whos
command is as follows when I want to use custom photos with attributes as I said:
Name Size Bytes Class Attributes
mask 490x640x3 940800 uint8
origImg 490x640 313600 uint8
I have to convert the origImage
dimension to x3 and remove the x3 from the mask, and also convert its class from unit8 to logical. In that case, I think that the code should work properly.
What should I do here in order to prepare the origImg
and mask
for that goal?
origImg=imread('G:\the_path\to\my_custom\image.png');
mask=imread('G:\the_path\to\my_custom\image_mask.png');
% I have to do something here to make it work.
whos;
% Rest of the code...
Upvotes: 0
Views: 742
Reputation: 1351
I am not sure if I understand you correctly.
To make a RGB image out of a gray-scale image, which still shows up as a gray-scale image, you can use
origImg = repmat(origImg,1,1,3);
which just repeats your gray-scale image for every channel of the RGB image.
For the mask, you have to do the opposite. since I don't know your image_mask.png
file, I assume that it is a RGB image that uses only black and white. In this case, all three channels are the same and you could simply use one of them for the mask, doesn't matter which one:
mask = mask(:,:,1);
To convert it to logical, use
mask=logical(mask);
Upvotes: 1