필터 지우기
필터 지우기

gray2rgb conversion

조회 수: 12 (최근 30일)
kamarthi vanitha
kamarthi vanitha 2019년 7월 16일
답변: Walter Roberson 2019년 7월 16일
Unable to perform assignment because the size of the left side is 245-by-744 and the size of the right side is 245-by-248-by-3.
Error in untitled>gray2rgb (line 20)
rgb(:,:,1)=Image;
Error in untitled (line 8)
rgb=gray2rgb(I);
  댓글 수: 1
Shashank Sharma
Shashank Sharma 2019년 7월 16일
RGB Images are three channel. Each pixel has it's own R, G, B values.
A grayscale has only one channel.
The gray2rgb function returns a m by n by 3 matrix for an input of m by n image.
If you have predifined the size of rgb it will cause the above error.

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

답변 (1개)

Walter Roberson
Walter Roberson 2019년 7월 16일
When you allocated memory for the rgb array, you used something like,
[rows, cols] = size(Image);
rgb = zeros(rows, cols, 3);
This is not correct code when Image is RGB. When you have
[var1, var2, var3, ..., varn] = size(Array)
and Array has more than n dimensions, then the last entry (varn here) will be the product of all remaining dimensions.
[rows, cols] = size(Image);
is not the same as
image_size = size(Image);
rows = image_size(1); cols = image_size(2);
What you should use is
rgb = zeros(size(Image));

카테고리

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

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by