how to convert 1 channel grayscale image into 3 channel?

7 visualizzazioni (ultimi 30 giorni)
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 Commento
Adam
Adam il 30 Lug 2018
Modificato: Adam il 30 Lug 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.

Accedi per commentare.

Risposte (1)

Jan
Jan il 30 Lug 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 Commenti
Saira charan
Saira charan il 30 Lug 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 il 31 Lug 2018
Modificato: Adam il 31 Lug 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.

Accedi per commentare.

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by