I simply crop images and save them with a number.For example i have Grain #1,Grain #2,Grain #3.If i move to another image and crop further images i cannot create images Grain #4 ,Grain #5 etc and instead there are overwritten images…Here is my code.Where is my mistake??
clear all;clc;addpath(genpath('C:\Users\User\Desktop\TEI'));imtool close all; k=input('How many times do you want to repeat the cropping?');IMAGE = uigetfile('*.jpg','Pick an image');A=imread(IMAGE);figure,imshow(IMAGE);folder=('C:\Users\User\Desktop\TEI\BEE_POLLEN _PROJECT\Scripts');for i=1:k f = sprintf('Select a ROI and double click to crop #%d',i); uiwait(warndlg(f)); [B, rect] = imcrop(A); baseFileName = sprintf('Grain #%d.jpg',i); fullFileName = fullfile(folder, baseFileName); baseFileName2 = sprintf('Grain #%d .jpg', (i+1)); fullFileName2 = fullfile(folder, baseFileName2); if exist(fullFileName) imwrite(B, fullFileName2); else imwrite(B, fullFileName); end if i==k f=sprintf('FINISHED!!'); uiwait(warndlg(f)); endend
Best Answer