Smooth segmented region line in an image

조회 수: 5 (최근 30일)
Ciara
Ciara 2014년 3월 28일
댓글: Ciara 2014년 3월 28일
Hi i have performed segmentation on an image to segment the black area at the top left hand corner seen in the first image below. I now need to smooth this line by finding four points along this segmented area, and then using the straight line equation. The resulting image should look like the second image. Can anyone help me the first part, finding four points along the segemented area?
Any help would be reallyyyy appreciated!
Thanks!

답변 (1개)

Image Analyst
Image Analyst 2014년 3월 28일
Assuming, like you said, that you have segmented out the upper left black part all by itself. Let's call that "binaryImage". Then you can just run bwboundaries to get the coordinates.
boundaries = bwboundaries(binaryImage);
x = bwboundaries{1}(:,1); % Think this is the right syntax but not sure.
y = bwboundaries{1}(:,2); % Think this is the right syntax but not sure.
Then find any x values that are 1 and remove those coordinates. Then find any y values that are 1 and remove those points too. Now you have just the ragged points. Pass them into polyfit
coefficients = polyfit(x, y, 1);
Now find out where the line intersects the y=1 and x=1 edges. Then construct a triangle from the 3 coordinates and use poly2mask to create a binary image.
mask = poly2mask(triX, tryY, rows, columns);
Then blacken above the line my masking
newBinaryImage = binaryImage;
newBinaryImage(mask) = false;
However about half of the ragged black part will be below the fitted line and you'll need to fill those in. This can be done by finding them by ANDing your original image with the inverse of the triangle mask.
raggedSpots = binaryImage & ~mask;
Now fill them in in the newBinaryImage image.
newBinaryImage(raggedSpots) = true;
This was totally just off the top of my head and untested. There's still a little for you to do, I'm sure. Come back with your code and original image if you need me to debug it for you. Good luck.
  댓글 수: 1
Ciara
Ciara 2014년 3월 28일
Thank you! I will give this a try!!

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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by