how to get image from specific folder and resize each image and save them is a new folder
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i try below code, but it show error at 'thisimage' variable. whats the problem.
clc;
close all;
clear;
OutputFolder = 'D:\Datasets\handwritten-signatures\sample_Signature\edited'; % Set as needed [EDITED]
dinfo = dir('D:\Datasets\handwritten-signatures\sample_Signature\genuine\*.png');% image extension
for K = 1 : length(dinfo)
thisimage = dinfo(K).name;
Img = imread(thisimage);
Y = imshow(Img);
Gray = rgb2gray(Img);
i = imresize(Img, [227, 227], 'bilinear');
imwrite(i, fullfile(OutputFolder, thisimage)); % [EDITED]
end
2 commentaires
Jan
le 27 Mai 2019
"it show error at 'thisimage' variable" - please post the complete error message. For solving a problem it is important to know, what the problem is.
Réponse acceptée
Murugan C
le 27 Mai 2019
Modifié(e) : Rik
le 27 Mai 2019
HI,
Before reading the image (imread), you shoud change directory, where the files are present, as like as below
clc;
close all;
clear;
OutputFolder = 'D:\Datasets\handwritten-signatures\sample_Signature\edited'; % Set as needed [EDITED]
dinfo = dir('D:\Datasets\handwritten-signatures\sample_Signature\genuine\*.png');% image extension
for K = 1 : length(dinfo)
thisimage = dinfo(K).name;
cd 'D:\Datasets\handwritten-signatures\sample_Signature\genuine\'
Img = imread(thisimage);
cd ..
Y = imshow(Img);
Gray = rgb2gray(Img);
i = imresize(Img, [227, 227], 'bilinear');
imwrite(i, fullfile(OutputFolder, thisimage)); % [EDITED]
end
2 commentaires
Murugan C
le 27 Mai 2019
Refer below link also.
Rik
le 27 Mai 2019
You shouldn't be using cd in your functions. imread will accept a full path without requiring the current folder to be changed. Also, why are you using clc,close all,clear? Most of the times that is cargo cult programming. (and you should use the layout tools to make your code more readable)
Plus de réponses (1)
Rik
le 27 Mai 2019
This is how you can provide the full path to imread:
for K = 1 : length(dinfo)
thisimage = dinfo(K).name;
Img = imread(fullfile(dinfo(K).folder,thisimage));
Y = imshow(Img);
Gray = rgb2gray(Img);
i = imresize(Img, [227, 227], 'bilinear');
imwrite(i, fullfile(OutputFolder, thisimage));
end
0 commentaires
Voir également
Catégories
En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!