how to convert 1 channel grayscale image into 3 channel?

12 ビュー (過去 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