How can I get the difference between two region triangle wise?
1 回表示 (過去 30 日間)
古いコメントを表示
I have found the boundary of the blob and the bounding box.Then I have added the centroid to the vertices of the box.Now I am trying to get the differences between the boundary and the box for each triangle.How can I do that?
I have added my code with the output:

9 件のコメント
Image Analyst
2020 年 4 月 30 日
編集済み: Image Analyst
2020 年 4 月 30 日
I think you did give a screenshot. Just click and drag the above image in your browser and you'll see there is a white frame around it for some reason. Is that in your program? If so use imclearborder. Also fill holes.
mask = imclearborder(mask);
mask = imfill(mask, 'holes');
Each point on your yellow bounding box will have a distance to every point on your blob boundary. Do you want the closest? So that for each point on the bounding box, find the distance to the nearest boundary point of the blob? So now you'll have a distance for every point on the boundary. So then do you want the average of all the closest distances in the triangle? So you'll have one average distance for each side of the bounding box?
採用された回答
Rik
2020 年 4 月 30 日
The code below is most of the way there. It only needs to have an encoding for the distance along the edge, so the line doesn't make a lot of sense yet.
%read binary mask
mask = imread('image.bmp');
mask=mask(41:616,128:894,1)>128;
%fill all holes:
%flip mask and select everything that is not the outer area
mask= bwlabel(~mask,4) ~= 1;
%find the edge pixels with something like imerode
SE=true(3*ones(1,ndims(mask)));%structuring element
edge= mask & ~( mask & convn(mask,SE,'same')==sum(SE(:)) );
%find the bounding box with 1 px margin
colind_first=find(sum(mask,1),1,'first')-1;
colind_last =find(sum(mask,1),1,'last')+1;
rowind_first=find(sum(mask,2),1,'first')-1;
rowind_last =find(sum(mask,2),1,'last')+1;
box=false(size(mask));
box([rowind_first rowind_last], colind_first:colind_last )=true;
box( rowind_first:rowind_last ,[colind_first colind_last])=true;
%add the diagonal lines to the box
x=false(size(mask));
p=polyfit([rowind_first rowind_last],[colind_first colind_last],1);
row=rowind_first:rowind_last;
col=round(polyval(p,row));
x(sub2ind(size(x),row,col))=true;
%add other diagonal to x
p=polyfit([rowind_first rowind_last],[colind_last colind_first],1);
col=round(polyval(p,row));
x(sub2ind(size(x),row,col))=true;
dist2xbox=bwdist(box | x);
distance=dist2xbox(edge);
figure(1),clf(1)
subplot(1,2,1)
imshow(edge | box | x)
subplot(1,2,2)
plot(distance)
14 件のコメント
Rik
2020 年 6 月 18 日
No, but you will lose the margin, so if you remove it, the box will overlap with the outer margin of your object. If your image doesn't have a margin, the method to fill all holes might have failed as well.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Image Processing and Computer Vision についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!