converting gray to rgb - problem
조회 수: 7 (최근 30일)
이전 댓글 표시
I have a picture in Gray scale ones and zeros
and for some multiplications characteristics to apply functions of convolution i will need to convert it to rgb with a matrix that consist of 3
how can i do gray2rgb? I've tried some defining new function for this that i took from the shared files in this website but didn't work.
mentioning that my version is (MATLAB 7.6.0 r2008a)
I get this message: Function definitions are not permitted at the prompt or in scripts.
Whenever I define this function:
MATLAB code
Image=imread('input.bmp')
function [Image]=gray2rgb(Image)
%Gives a grayscale image an extra dimension
%in order to use color within it
[m n]=size(Image);
rgb=zeros(m,n,3);
rgb(:,:,1)=Image;
rgb(:,:,2)=rgb(:,:,1);
rgb(:,:,3)=rgb(:,:,1);
Image=rgb/255;
end
댓글 수: 4
Image Analyst
2015년 4월 11일
There is a function ind2rgb() but that requires a colormap, which he does not have, so that function won't work. Other than that, the function to use is cat() like Walter and I already recommended below.
답변 (3개)
Image Analyst
2012년 11월 3일
For a floating point RGB image in the range 0.0 - 1.0, which will let it be seen with imshow(), you can do what Walter suggests. You can't view an RGB image as floating point unless it's in the range 0-1. You can convert it to uint8 but you lose precision of up to 1/2 a gray level. If you want a uint8 image that has the same range of values as your convolved/manipulated image has then just concatenate and convert to uint8, which will round:
rgbUint8 = uint8(cat(3, singleImage, singleImage, singleImage));
or it could be a double image instead of a single image, just use whatever you have. This will allow you to view it with imshow() and also allow you to save it with imwrite() since it's now uint8. So the drawbacks are that you lose precision of up to 1/2 a gray level, but has the advantages that the intensity range is the same and you can now display and save it with ease. It's your call which way to do it
댓글 수: 0
hayet hadfi
2015년 4월 11일
how to Create model hardware Conversion Blockset RGB to Gray using simulink
댓글 수: 1
Image Analyst
2015년 4월 11일
I suggest you start your own question with a subject line "Conversion Blockset RGB to Gray using Simulink"
참고 항목
카테고리
Help Center 및 File Exchange에서 Blue에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!