Splitting up values from variables
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!