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 CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by