The problem is likely caused by the fact that your images are actually written to a different directory than you think.
I strongly recommend using fullfile rather than trying to concatenate paths and filenames.
Start with something like this:
D = 'E:\phd\zahra taati\extract only heart\crop100-112\';
S = dir(fullfile(D,'*.jpg'));
for k = 1:numel(S)
F = fullfile(D,S(k).name);
I = imread(F);
J = ...
G = fullfile(D,['cropped',S(k).name]);
imwrite(J,G);
end
If you want to change the file extension then use fileparts to get the filename, then simply append the desired extension to the name.
Best Answer