I have the following image. Now I want to separate the black and white pixel from the image so that I can fit an ellipse to each black pixel area and find the length of the major axis of each ellipse. How can I separate black pixel from the white pixel and fit an ellipse?

 채택된 답변

Image Analyst
Image Analyst 2016년 9월 6일

0 개 추천

Basically, here are the steps.
% Invert your image so the black things are white.
binaryImage = grayImage < 128;
% Call bwlabel
[labeledImage, numberOfRegions] = bwlabel(binaryImage);
% Call regionprops
props = regionprops(labeledImage, 'MajorAxisLength', 'Orientation');
It's all shown in Steve's blog:

댓글 수: 5

sheli whitson
sheli whitson 2016년 9월 6일
Thank you Image Analyst.
Eyup Demir
Eyup Demir 2022년 4월 11일
@Image Analyst In the image you attached from @Steve Eddins, two white regions in the middle are merged under one ellipse, because there is a one pixel touching. Is there a way to merge them if there was 2 or 3 pixel between them? I want to be able to control some white regions to be merged based on the closest distance between them.
Walter Roberson
Walter Roberson 2022년 4월 11일
https://www.mathworks.com/help/images/ref/imclose.html
imclose() with a structuring element as large as the distance you want to merge.
Eyup Demir
Eyup Demir 2022년 4월 11일
I think, I found what I was looking for! It is almost-connected-compenent labeling Thank you Steve! https://blogs.mathworks.com/steve/2010/09/07/almost-connected-component-labeling/
Image Analyst
Image Analyst 2022년 4월 11일
Sometimes you can reduce this effect by using 4-connected labeling instead of the default 8-connected labeling.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2016년 9월 6일

댓글:

2022년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by