Mehdi - you need to describe the steps that the user would follow when using your GUI. Does he/she
- select some files for cropping
- crop the images
- press a button to save the cropped images
- select a (new) folder to those cropped images
Or does the above occur in some other order? You have supplied a callback for a textfield, which seems to have the code for creating a directory, and then crops the images. It is unclear though why or how this textfield is to be used - why should its callback (and not a button?) be used to create the directory and crop the images? As well, are the directory and Cropbillede functions in separate m files, or declared within the GUI?
From your directory function, you do the following
function handles = directory( handles )
direct = uigetdir(pwd, 'Select Directory');
handles.myData.direct = direct;
end
So the user selects a directory (new or existing) and the value gets saved to the handles.myData.direct field. The updated handles gets returned and in the textfield callback the structure is saved using guidata. Then Croppbillede is called and has two blocks of code where data is written
SequenceName = 'CroppedBone' ;
for k = 1:length(ImagesToRead)
ExportedName = sprintf('%s%03d.tif',SequenceName,k);
imwrite(CroppedImageCell{k}...
,ExportedName,...
'tif','WriteMode','overwrite','Compression','none');
end
for k = 1:length(ImagesToRead)
imwrite(CroppedImageCell{k},handles.myData.direct,SequenceName,...
'tif','WriteMode','append','Compression','none');
end
The first block seems to be writing a number of images to file, all whose name is something like CroppedBoneXYZ.tig where XYZ is a three digit number. But you don't specify the directory/folder for these files. Should the folder be that which was selected from the directory function? If so, then replace your ExportedName initialization with
ExportedName = fullfile(handles.myData.direct,sprintf('%s%03d.tif',SequenceName,k));
which will add the directory to ExportedName and so the files should be saved there.
In your second for loop, you don't specify a file per se, but seem to expect that the same image (?) will be appended to the existing file since you are providing the directory to save the file and the SequenceName which is just CroppedBone. I suspect that this block would cause an error to be thrown - are you not observing this?
I suggest that you comment out the second for loop and check to make sure that the first for loop (once updated with the directory/folder to save the files) is working correctly, and then decide whether you need this extra code or not.
Best Answer