how to convert 1 channel grayscale image into 3 channel?

조회 수: 7 (최근 30일)
Saira charan
Saira charan 2018년 7월 30일
편집: Adam 2018년 7월 31일
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
Adam
Adam 2018년 7월 30일
편집: Adam 2018년 7월 30일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2018년 7월 30일
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
Saira charan
Saira charan 2018년 7월 30일
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 2018년 7월 31일
편집: Adam 2018년 7월 31일
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.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by