Message Boards Message Boards

Superpose subimages obtained by clustering?

Posted 8 years ago

I have to cluster an image (named "Degrad"), and I would like to insert the sub-images associated with different classes into the frame corresponding to the complete image. I used the option PlotRange->{} with the hope that the different sub-images exactly fit in the original frame, but it doesn't work (see the separate representation in the attached notebook)! In addition, when I try to rebuild the original image by superposing these subimages, there are a lot of "holes": It seems that a number of pixels are shifted or ill-dimensioned...

So, here is a 20X14 image I want to cluster:

Original

Five clusters can be obtained from:

TrucMed = ClusteringComponents[Degrad, 5, Method -> "KMedoids"];

Then, I tried to locate these classes in the original image, through the instruction:

Map[Show[#[[2]], 
PlotRange -> {{0, First@ ImageDimensions@Degrad - 1}, {0, 
Last@ ImageDimensions@Degrad - 1}}, ImageSize -> Automatic, 
Frame -> True] &, 
ComponentMeasurements[{Degrad, TrucMed}, "MaskedImage"]]

The obtained subimages were:

enter image description here

I used the option PlotRange->{} with the hope that the different "standardized" subimages exactly fit in the original 24X10 frame, but it doesn't work. For instance, the superposition of these "standardized" subimages is full of white holes:

enter image description here

What should I do?

Regards, Claude

Attachments:
POSTED BY: Claude Mante
3 Replies

Fine! Thank you very much.

Claude

POSTED BY: Claude Mante

"MaskedImage" isn't quite the right property you should use for this purpose. Try instead to extract the mask for each component, as done with the code below:

SetOptions[Image, ImageSize -> 200];

masks = Image /@ 
  ComponentMeasurements[{Degrad, TrucMed}, "Mask"][[All, 2]];
GraphicsRow@masks

ImageAdd @@ Map[ImageMultiply[#, Degrad] &, masks]

You should get these masks:

enter image description here

and this recombination: enter image description here

POSTED BY: massimo fazio

Dear @Claude Mante, it is great that you added images. But you do not need to make a new comment with the almost same content. You can just edit the original post. Please also make sure that you code is formatted properly as described here: https://wolfr.am/READ-1ST

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract