Splitting up values from variables

1 回表示 (過去 30 日間)
Frank
Frank 2011 年 5 月 18 日
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

採用された回答

Matt Fig
Matt Fig 2011 年 5 月 18 日
x = Displacement(1);
or
Displacement = Displacement(1);
  2 件のコメント
Frank
Frank 2011 年 5 月 18 日
I didn't know which one to accept, they both worked :P
Frank
Frank 2011 年 5 月 18 日
Thanks!

サインインしてコメントする。

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2011 年 5 月 18 日
Displacement(1)
? Seems too simple to answer your question.
  2 件のコメント
Matt Fig
Matt Fig 2011 年 5 月 18 日
I'll second that comment.
Frank
Frank 2011 年 5 月 18 日
Thanks!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by