i have 60 slice grey image. how want to convert to RGB image? as attached is my grey image (grey.jpg). rgb.jpg is from internet what i want like. this is my coding, but got error. P = zeros(103, 103, 60); for K = 1 : 60 K_file=30+10*K; petname = sprintf('I%d.dcm', K_file); P(:,:,K) = dicomread(petname); scale = 130/103 ; Pi(:,:,K) = imresize(P(:,:,K),scale) ; % where P is your 103*103 3D matrix end rgbImage = gray2rgb(Pi); imshow3D(rgbImage) this is my function 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 BUT GOT ERROR. Unable to perform assignment because the size of the left side is 130-by-7800 and the size of the right side is 130-by-130-by-60. Error in gray2rgb (line 6) rgb(:,:,1)=Image; Error in sliderspect1 (line 12) rgbImage = gray2rgb(Pi);
Prashant Kumar answered .
2025-11-20
[r,c,m] = size(Pi); rgbImage = repmat(reshape(Pi / 255, [r, c, 1, m]), [1, 1, 3, 1]);