Setting up a loop: Round 1
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello!
I've narrowed down what I want this script to do, but I want it to loop through every specified image in a folder through a multiple select with "uiget" and then deposit the looped images into a different folder. However, I don't know how to set it up for a loop. Can anyone help?
- I'm using the first image as a reference to the other images, so the loop function would run through the second image.
Thanks!
-Frank
Code:
%First Image
i = imread('343b #10000.tif');
j = size(i);
imtool(i);
for k = 1:j(1)
for l = 1:j(2)
if i(k,l) > 160 & i(k,l) > 160
d(k,l) = 1;
else
d(k,l) = 0;
end
end
end
imtool(d);
labela = bwlabel(d);
imagesc(labela);
[labela,num] = bwlabel(d,4);
stats = regionprops(labela,'basic');
stats(1).Area
stats(1).Centroid
max_area = max([stats.Area]);
biggrain = find([stats.Area]== max_area);
p = stats(biggrain).Centroid
%Second Image
z = uigetfile('*tif') %select a file for displacement
a = imread(z); %reads the selected file
b = size(a); %gauges the size of the selected file
imtool(a);
for c = 1:b(1)
for l = 1:b(2)
if a(c,l) > 160 & a(c,l) > 160
e(c,l) = 1;
else
e(c,l) = 0;
end
end
end
imtool(e);
labelb = bwlabel(e);
imagesc(labelb);
[labelb,num] = bwlabel(e,4);
stats = regionprops(labelb,'basic');
stats(1).Area
stats(1).Centroid
max_area = max([stats.Area]);
biggrain = find([stats.Area]== max_area);
o = stats(biggrain).Centroid
%Calculates the differences in the centroid
displacement = p -o %Calculates the difference in centroids
x = displacement(1); %Places x value from displacement into x
%%IM Translate
a2 = imtranslate(a, [0 x]); %Note: [y x] for imtranslate, if it's negative make it positive
imshow(a2)
imwrite(a2, z, 'tif')
0 commentaires
Réponse acceptée
Andrew Newell
le 18 Mai 2011
You could set up a loop like this:
%Second Image
z = uigetfile('*tif'); %select a file for displacement
while ~isequal(z,0) %if no file is selected, uigetfile returns 0
% process the image here
o = stats(biggrain).Centroid;
z = uigetfile('*tif');
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Biomedical Imaging dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!