I am trying to access 4k images and crop some ROI based areas (4 ROI in my case) and store them in some directory. So far everything is working okay except the loops handling of the filename.
Below is my code attached. I am accessing N
4k images, crop and resize them to my desired resolution. In the end, when I tried to save the data the images got overwritten.
N=2;
for img = 1:N
x = gTruth.LabelData.crack{img,1}
for i=1:4
Cells = x(i,1:4)
baseFileName = theFiles(img).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
CroP = imcrop(imageArray,Cells);
imshow(CroP);
B = imresize(CroP,[256 256]);
imshow(B);
imwrite(B,strcat('C:\Users\USER\Desktop\Directory\imagefile_00',num2str(i),'.png'));
end
end
My question is that after loop i
runs, it saves 4 images and for img
again it saves four values. Now when the code runs it saves only last 4 images and not 8. I should get a i*N
number of total images, but I'm getting only 4 and rest are overwritten.
How can I adapt my program to save all files?