Effacer les filtres
Effacer les filtres

Splitting up values from variables

1 vue (au cours des 30 derniers jours)
Frank
Frank le 18 Mai 2011
I've written a script that obtains the centroid of an object in my image. I store that value as a reference and calculate the difference from the other images so I can align them to the first. However the coordinates are stored in the variable "displacement" and I only want the x coordinate. Is there a way I can get it automatically?
Code
o = imread('343TESTA.tif');
p = size(o);
imtool(o);
for k = 1:p(1)
for l = 1:p(2)
if o(k,l) > 160 & o(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
a = imread('343TEST.tif');
b = size(a);
imtool(a);
for c = 1:b(1)
for l = 1:b(2)
if i(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
%%IM Translate
a2 = imtranslate(a, [0 -1.0376]); %Note: [y x] for imtranslate, if it's negative make it positive
subplot(1,2,1), imshow(v)
subplot(1,2,2), imshow(u2)
imwrite(a2, '343TEST11','tif');
Output (example):
Displacement =
-1.036 -6.7288
I only want the -1.036 portion

Réponse acceptée

Matt Fig
Matt Fig le 18 Mai 2011
x = Displacement(1);
or
Displacement = Displacement(1);
  2 commentaires
Frank
Frank le 18 Mai 2011
I didn't know which one to accept, they both worked :P
Frank
Frank le 18 Mai 2011
Thanks!

Connectez-vous pour commenter.

Plus de réponses (1)

Sean de Wolski
Sean de Wolski le 18 Mai 2011
Displacement(1)
? Seems too simple to answer your question.
  2 commentaires
Matt Fig
Matt Fig le 18 Mai 2011
I'll second that comment.
Frank
Frank le 18 Mai 2011
Thanks!

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by