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...............

Respuestas (1)

Image Analyst
Image Analyst el 4 de Nov. de 2013

0 votos

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 comentarios

mohammed
mohammed el 4 de Nov. de 2013
Editada: mohammed el 4 de Nov. de 2013
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 el 4 de Nov. de 2013
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 el 4 de Nov. de 2013
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 el 4 de Nov. de 2013
Editada: Image Analyst el 4 de Nov. de 2013
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 el 5 de Nov. de 2013
Because i am using graphCut method..
Image Analyst
Image Analyst el 11 de Nov. de 2013
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 el 14 de Nov. de 2013
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;

La pregunta está cerrada.

Preguntada:

el 4 de Nov. de 2013

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by