Transform RGB image to grayscale but keep format as RBG

6 次查看(过去 30 天)
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.

回答(1 个)

darova
darova 2020-2-18
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

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by