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

32 vues (au cours des 30 derniers jours)
abdullah al-dulaimi
abdullah al-dulaimi le 4 Nov 2022
Commenté : Walter Roberson le 7 Déc 2023 à 4:17
i have images with 224 x 224 x 1 size i want to convert it to 224 x 224 x 3

Réponse acceptée

Kevin Holly
Kevin Holly le 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 commentaires
abdullah al-dulaimi
abdullah al-dulaimi le 4 Nov 2022
broth i have path with 200 images , how can i convert all images in one time
Kevin Holly
Kevin Holly le 4 Nov 2022
Modifié(e) : Kevin Holly le 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

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 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.
  2 commentaires
Rev
Rev le 7 Déc 2023 à 3:27
How do you do that?
Walter Roberson
Walter Roberson le 7 Déc 2023 à 4:17
unzip('MerchData.zip');
imds = imageDatastore('MerchData', ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
augds = augmentedImageDatastore([224 224], imds, 'ColorPreprocessing', 'gray2rgb');
[imdsTrain,imdsValidation] = splitEachLabel(augds,0.7);
and so on.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by