how to convert 1 channel grayscale image into 3 channel?

6 views (last 30 days)
I have to train my images through vgg16, for which i need to convert my 1 channel grayscale images to 3 channel. i have used rgbimage=I(:,:,[1 1 1]) also repmat, but when i apply this command it changes my image into binary. I just need to change number of channels by keeping it grayscale. Help please!
  1 Comment
Adam
Adam on 30 Jul 2018
Edited: Adam on 30 Jul 2018
cat( 3, I, I, I )
should work, though looks ugly. Repmat, done correctly, should work too I would have thought. I imagine there is an Image Processing Toolbox function that does it though I can't remember off hand.

Sign in to comment.

Answers (1)

Jan
Jan on 30 Jul 2018
These are equivalent and working:
RGB = repmat(I, [1, 1, 3])
RGB = I(:, :, [1, 1, 1])
RGB = repelem(I, [1, 1, 3])
They do not change the class of the image or the values. Your impression, that this changes your "image to binary" is not correct. Either the observation is not correct or another command is responsible for the effect. Please post the relevant part of the code and mention, why you assume, that the image is changed.
  2 Comments
Saira charan
Saira charan on 30 Jul 2018
I=imread('mdb120.png'); RGB = repmat(I, [1, 1, 3]) imwrite(I.*uint8(I),'mdb120.png')
Can you suggest what is wrong in this? My images are grayscale 1 channel. And using these commands does change it into 3 channel but the images are converted to binary. As i am dealing with mammograms i cannot get results from images that are just black n white. I hope i am clear now.
Adam
Adam on 31 Jul 2018
Edited: Adam on 31 Jul 2018
What is the range of I.*uint8(I)? If you plot I and plot that you should see if one or other is wrong before just saving them to file.

Sign in to comment.

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!