0
votes

Links I checked before asking this question:

  1. Convert RGB Image to Grayscale and Grayscale to RGB Image?

  2. Conversion to unit8 data class in MATLAB

I have an image img. I want to visualize the pixel values in a matrix (after some manipulation) in MATLAB. R1, R2 and R3 are the three matrices I created to store pixel values of R, G and B respectively.

for i=1:30

R1(:,1:30:) = toeplitz(img(i,:,1)); 
R2(:,1:30,:) = toeplitz(img(i,:,2)); 
R3(:,1:30,:) = toeplitz(img(i,:,3)); 
R = (R1+ R2+ R3)/3 ;  %%I know this part is incorrect

end

However, imshow(R) shows grayscale image but I want to visualize in RGB. What I can understand it is taking the pixel values from 0 to 255 as 0:Black and 255:White. What I am trying to achieve is that it averages the pixel value of the 3rd dimension in R1, R2 and R3 and show me the pixel in the color.

Any help will be appreciated.

Reference: https://www.mathworks.com/help/matlab/ref/toeplitz.html

1

1 Answers

0
votes

imshow requires an m-by-n-by-3 array (see documenation) so in order to create such an array, you require three m-by-n matrices (in your case R1, R2, R3) Then you can concatenate them in the third dimension via

imshow(cat(3,R1,R2,R3))

That should result in the desired RGB image.