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.
0 个评论
回答(1 个)
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
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!