Saving multiple cropped images to a different folder
2 views (last 30 days)
Show older comments
So I am new to matlab and having trouble using the imwrite() function. I uncollaged an image (137 seperate images) and want to save the individual images to a new folder. How do I use the imwrite() function to save all the cropped images? I was using this post ... https://www.mathworks.com/matlabcentral/answers/73719-uncollage-a-collage-image
Code...
message = sprintf('Would you like to crop out and save each individual images?');
reply = questdlg(message, 'Extract Individual Images?', 'Yes', 'No', 'Yes');
% Note: reply will = '' for Upper right X, 'Yes' for Yes, and 'No' for No.
if strcmpi(reply, 'Yes')
figure; % Create a new figure window.
% Maximize the figure window.
set(gcf, 'Units','Normalized','OuterPosition',[0 0 1 1]);
for k = 1 : numberOfBlobs % Loop through all blobs.
% Find the bounding box of each blob.
thisBlobsBoundingBox = blobMeasurements(k).BoundingBox; % Get list of pixels in current blob.
% Extract out this zoop into it's own image.
subImage = imcrop(originalImage, thisBlobsBoundingBox);
% Saving the cropped image
**imwrite(subImage,'path to folder') ?? **
end
end
0 Comments
Accepted Answer
Image Analyst
on 26 Aug 2019
folder = 'c:/wherever';
thisBaseFileName = sprintf('Image %3.3d', k);
thisFullFileName = fullfile(folder, thisBaseFileName);
imwrite(subImage, thisFullFileName);
0 Comments
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!