creating a loop to input photos into the code
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am very new to Matlab. I am trying to create a loop to input photos in, so I do not have to put in imread in 100 times. The file all the photos are in is called "Pathtoimages". I am trying to upload photos to have the machine recongizie and classify if a photo is a pengiun or a dog. I am not sure how to set this up. Any Help would be greatly appreiated . this is what I found on the internet but I do not understand sprintf or the "pentan1h_6uLmin_0%3d.tif" ( how do you create a file like that or is there a way to do it with a .m file?) . Any help would be greatly appreciated. Thank you.
for n=1:10
images{n}= imread(sprintf('pentan1h_6uLmin_0%3d.tif',n));
imshow(Images{n},[],'initialmagnification','fit');
end
0 commentaires
Réponses (1)
Mathieu NOE
le 29 Jan 2021
hello
this code example reads all tif files in the current directory
the for loop will open each individual file and do a few operations (like cropping here)
it's up to you to adapt it to your specific needs....
% select appropriate options below and adapt code to your specific needs ...
% files = dir('*.tif'); % list all tif files in current directory
files = dir('handheld*.tif'); % as example : only list tiff files with "handheld" in the filename
% % resize options (sacle factor or pixels)
% scale_factor = 0.5;
% select portion of the image
% 451*279*3. I will like to extract a portion with dimensions of 120*80*3
x_dim = 120;
y_dim = 80;
x_offset = 100; % please make sure the "corner" of the cropped image is correct
y_offset = 50;
% main loop
for ck = 1:length(files)
Filename = files(ck).name;
img = imread(Filename);
% % resize
% H{ck}= imresize(img, scale_factor);
% select (crop)
H{ck}= img(x_offset+(1:x_dim),y_offset+(1:y_dim),: );
% plot (just to check)
figure(ck), imagesc(H{ck});
% insert your own code here (save for example)
end
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!