How to change 1 channel image to 3 channel

조회 수: 56 (최근 30일)
evianita dewi
evianita dewi 2019년 12월 13일
답변: DGM 2022년 5월 2일
I have several grayscale images with channel 1, then I want to convert it to RGB channel 3 image, how do I change it?

채택된 답변

Image Analyst
Image Analyst 2019년 12월 13일
Try cat() to stack the gray scale image into 3 slices (color channels):
rgbImage = cat(3, grayImage, grayImage, grayImage);
It will be an RGB image though the only colors will be gray since there is no difference between the three different color channels. It will be a 3-D image with the z-direction (third index) being the color channel index.
  댓글 수: 2
evianita dewi
evianita dewi 2019년 12월 26일
this is very helpful, thank you!!
Muhammad Kamran
Muhammad Kamran 2021년 3월 25일
Thanks a lot.
It's very helpful.

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

추가 답변 (1개)

DGM
DGM 2022년 5월 2일
Alternative to using cat(), the same can also be done a couple other ways.
You can use repmat()
rgbpict = repmat(graypict,[1 1 3]);
... or you can even use basic indexing:
rgbpict = graypict(:,:,[1 1 1]);

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by