我在图像中找到两个斑点的质心,并通过直线连接了这些质心。我想用线条保存图像,怎么办?
请完成以下Matlab代码:
I = imread('C:\Data\uploaded_video\Static_Occlusion_frames_of_big_blob_Croped2\static_occ_id003_6\frame0062.jpg');
Ibw = im2bw(I);
Ibw = imfill(Ibw,'holes');
Ilabel = bwlabel(Ibw);
stat = regionprops(Ilabel,'centroid');
figure,imshow(I);
hold on;
for x = 1: numel(stat)-1
line([round(stat(x).Centroid(1)) round(stat(x+1).Centroid(1))],[round(stat(x).Centroid(2)) round(stat(x+1).Centroid(2))],'Color','w','LineWidth',1);
end
用线条保存图像。
答案 0 :(得分:0)
我找到了问题的解答,并按如下方式编辑了Matlab代码:
I = imread('C:\Data\uploaded_video\Static_Occlusion_frames_of_big_blob_Croped2\static_occ_id003_6\frame0062.jpg');
Ibw = im2bw(I);
Ibw = imfill(Ibw,'holes');
Ilabel = bwlabel(Ibw);
stat = regionprops(Ilabel,'centroid');
figure('visible', 'off'),imshow(I);
hold on;
for x = 1: numel(stat)-1
line([round(stat(x).Centroid(1)) round(stat(x+1).Centroid(1))],[round(stat(x).Centroid(2)) round(stat(x+1).Centroid(2))],'Color','w','LineWidth',1);
end
hold off
F = getframe ;
% save the image:
imwrite(F.cdata, 'C:\Data\1.jpg')
close(figure)