converting gray to rgb - problem

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

mohammed
mohammed 2012년 11월 3일
هلو احمد شونك ...... اني اريد انفذ نفس الخوارزمية ماعرف اشتغلت عندك او لا ؟
Image Analyst
Image Analyst 2012년 11월 3일
Sorry - I can't read this.
Durgesh Naik
Durgesh Naik 2015년 4월 11일
use tool in matlab gray to RGB
Image Analyst
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개)

Walter Roberson
Walter Roberson 2011년 4월 10일

0 개 추천

gray2rgb = @(Image) double(cat(3,Image,Image,Image))./255;
Image Analyst
Image Analyst 2012년 11월 3일

0 개 추천

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
hayet hadfi
hayet hadfi 2015년 4월 11일

0 개 추천

how to Create model hardware Conversion Blockset RGB to Gray using simulink

댓글 수: 1

Image Analyst
Image Analyst 2015년 4월 11일
I suggest you start your own question with a subject line "Conversion Blockset RGB to Gray using Simulink"

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

카테고리

도움말 센터File Exchange에서 Blue에 대해 자세히 알아보기

질문:

2011년 4월 10일

댓글:

2015년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by