help needed in image segmentation.

Hallo
After segmentation with 5 cluster i got this image. but it giving me more then 5 region . i want to keep the 5 largest region of each color and if there any smallest region it would take the color of that region.
please help me...............

답변 (1개)

Image Analyst
Image Analyst 2013년 11월 4일

0 개 추천

See my demo, attached below. The code will let you extract the N largest or smallest blobs. However deciding which label to assign to the small blobs that get merged is not so straightforward, particularly when they may have 2 or more neighbors with different labels. For example, that olive green blob in the upper middle borders orange, brown, magenta, and green blobs. So which color should it take on?

댓글 수: 8

mohammed
mohammed 2013년 11월 4일
편집: mohammed 2013년 11월 4일
thanks for your reply.
i have already go through this code but i am not facing a problem in finding an largest region but how to emerged that extra small regions with their respective surrounding region......
Image Analyst
Image Analyst 2013년 11월 4일
Like I said, what if they have 4 "surrounding" regions? Which one do you merge it with? Do you have a measurement of some kind, like the mean or std dev of the region, that you will be comparing to, and assign it to the closest one?
Image Analyst
Image Analyst 2013년 11월 4일
First you need to measure the area of each region. You can do that with a simple histogram or with regionprops. Then you need to call graycomatrix so that you know what regions touch other regions. Then you need to loop over all regions, starting with the smallest and working your way up. Get the areas of touching regions and identify the largest touching region. Then merge it in, and you need to start the process all over again, because the areas have changed. Keep going until you have only 5 regions left.
Image Analyst
Image Analyst 2013년 11월 4일
편집: Image Analyst 2013년 11월 4일
graycomatrix() will tall you if one gray level is adjacent to another gray level. You have to call it 8 times, once for each direction. Why did you tag it "graph cut"?
mohammed
mohammed 2013년 11월 5일
Because i am using graphCut method..
Image Analyst
Image Analyst 2013년 11월 11일
OK - it just wasn't talked about in the question, and whatever method you used to produce the segmentation, classification, or labeled image is not relevant to finding the 5 largest blobs. So if I answered that question, can you mark it as accepted. Otherwise provide information or an image to finish the question. Thanks.
mohammed
mohammed 2013년 11월 14일
still not able to solve the way u show me . plz help me..
Here's the code simplified to pull out exactly the 5 largest blobs:
% Get all the blob properties.
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
blobMeasurements = regionprops(labeledImage, 'area');
% Get all the areas
allAreas = [blobMeasurements.Area];
numberToExtract = 5;
% Sort in order of largest to smallest.
[sortedAreas, sortIndexes] = sort(allAreas, 'descend');
% Extract the "numberToExtract" largest blobs using ismember().
biggestBlob = ismember(labeledImage, sortIndexes(1:numberToExtract));
% Convert from integer labeled image into binary (logical) image.
binaryImage = biggestBlob > 0;

이 질문은 마감되었습니다.

질문:

2013년 11월 4일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by