Can you download individual images from the image labeling app onto an external hard drive?

2 views (last 30 days)
Madeline Fryer
Madeline Fryer on 28 May 2022
Edited: Stephen23 on 28 May 2022
Is there a way to download rectangle images created in the image labeling software onto an external hard drive? I have numerous photos that I have added labels to, and I would like to download the individual labels as photos onto an external hard drive. (There are hundreds of them, so I can't download them onto my computer). I have looked at other question forums and figured out the general code, but I can't figure out a way to set the hard drive as the folder I want to save my images in. Thank you for your time. The code I have is below:
% set your directory to the folder, where you want to save the individual images
cd '/Users/TOSHIBA EXT/'
% to find the number of pictures in your table "labels1" use e.g.:
number_pictures = height(labels1);
% find the number of labeled rectangles:
for c = 1:number_pictures
number_rectangles = (numel(labels1.imageFilename{c,1})/4);
% export the rectangles as individual images
for d = 1:number_rectangles
name = labels1.imageFilename{c}; % path to the image used in the Image Labeler session
picture = imread(labels1.imageFilename{c}); % imports the image into Matlab
picture_crop = imcrop(picture,[labels1.beverage_bottles{c}(d,1),labels1.beverage_bottles{c}(d,2),labels1.beverage_bottles{c}(d,3),labels1.beverage_bottles{c}(d,4)]); % crops the individual label using the coordinates
imwrite(picture_crop,[name,num2str(d),'.jpg'],'Quality',100); % saves the rectangles as .jpg image to your directory
clear name
clear picture
clear picture_crop
clear number_rectangles
end
end

Answers (1)

Stephen23
Stephen23 on 28 May 2022
Edited: Stephen23 on 28 May 2022
"but I can't figure out a way to set the hard drive as the folder I want to save my images in"
Don't.
Do not set/change to other directories just to access data files. Do not use CD just to access data files.
It is much simpler to use absolute/relative filenames. You should use absolute/relative filenames.
A simple abbreviated example:
Pinp = '/Users/path to where the files are saved/'; % input path
Pout = '/Users/TOSHIBA EXT/'; % output path
for ..
..
Finp = fullfile(Pinp,labels1.imageFilename{c});
picture = imread(F); % imports the image into Matlab
..
[~,name] = fileparts(name); % optional
Fout = fullfile(Pout,sprintf('%s%d.jpg',name,d));
imwrite(picture_crop,Fout,'Quality',100);
end
Tip: get rid of all of those superfluous CLEAR calls. it is very unlikely that you need those inside a FOR loop like that.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!