How to change image size from 224 x 224 x 1 to 224 x 224 x 3

73 views (last 30 days)
i have images with 224 x 224 x 1 size i want to convert it to 224 x 224 x 3

Accepted Answer

Kevin Holly
Kevin Holly on 4 Nov 2022
Img = rand(224,224,1);
imshow(Img)
new(:,:,1) = Img;
new(:,:,2) = Img;
new(:,:,3) = Img;
imshow(new)
size(Img)
ans = 1×2
224 224
size(new)
ans = 1×3
224 224 3
  2 Comments
Kevin Holly
Kevin Holly on 4 Nov 2022
Edited: Kevin Holly on 4 Nov 2022
folder = uigetdir;
files = dir(fullfile(folder,'*.png'));
for ii = 1:length(files)
grayImage = imread(fullfile(folder,files(ii).name));
rgbImage = cat(3, grayImage, grayImage, grayImage);
imwrite(rgbImage,[fullfile(folder,files(ii).name) '_rgb.png'])
end

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 4 Nov 2022
I recommend that you consider using an imageDatastore followed by an augmentedImageDatastore -- the augmented store can automatically resize your images and can automatically convert to RGB or grayscale.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!