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...............
0 件のコメント
回答 (1 件)
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 件のコメント
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
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
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
2013 年 11 月 5 日
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
2013 年 11 月 14 日
Image Analyst
2013 年 11 月 14 日
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;
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!