필터 지우기
필터 지우기

poly2mask not creating filled mask

조회 수: 3 (최근 30일)
Afzal
Afzal 2020년 3월 4일
댓글: Image Analyst 2020년 3월 5일
I am trying to create a mask from the attached image (sampleEdges.png), which was obtaiend by applying the edge command to the sample image (sampleImage.jpg). I have obtained the coordinates of the area I want to mask using regionprops. The MaskBoundary looks like as shown in MaskBoundary.png. I now want to create a mask from the MaskBoundary coordinates using poly2mask, but it does not create a filled mask (mask.png)
sample = imread('sampleImage.jpg')
sampleEdges = edge(rgb2gray(sample),'canny',0.1,25);
regions = regionprops(sampleEdges, 'all');
[~,index] = sortrows([regions.Area].'); % Sort by descending area
regions = regions(index(end:-1:1));
MaskBoundary = bwtraceboundary(sampleEdges,[regions(2).PixelList(1,2) regions(2).PixelList(1,1)],'n');
MaskX = MaskBoundary(:,2);
MaskY = MaskBoundary(:,1);
Mask = poly2mask(MaskX,MaskY,size(sample,1),size(sample,2))
The two regions are the ones that enclose the red markings in ROI.png. But regionprops can only find the right one.

답변 (1개)

Image Analyst
Image Analyst 2020년 3월 4일
Use bwboundaries() instead of bwtraceboundary().
  댓글 수: 2
Afzal
Afzal 2020년 3월 4일
편집: Afzal 2020년 3월 4일
With bwboundaries() I cannot specify the start point, and it does not seem to find the region I want. I am also having issues getting the left ROI (see edited post)
Image Analyst
Image Analyst 2020년 3월 5일
How do you identify the one you want? A week or two ago I gave you code to identify the curved bar. Why did you discard that approach?

댓글을 달려면 로그인하십시오.

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by