Transform RGB image to grayscale but keep format as RBG

6 views (last 30 days)
Hi all,
I have a imageDatastore of jpeg images, and I'm trying to transform all the images to grayscale, however I want to keep dimensions of the images the same (m x n, 3).
I was hoping to use rbg2gray, however I cannot compare the original and grayscale images as the dimensions are not consistent.
Thanks.

Answers (1)

darova
darova on 18 Feb 2020
You can use repmat or cat to create 3D matrix
I1 = rgb2gray(I);
I2 = cat(3,I1,I1,I1); % gray image as 3D matrix
%I2 = repmat(I1,[1 1 3]); % gray image as 3D matrix

Tags

Products

Community Treasure Hunt

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

Start Hunting!