MATLAB: How to get image from specific folder and resize each image and save them is a new folder

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

Best Answer

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