1
$\begingroup$

Normally, we can ask for the mean, median, etc. underlying pixel values for morphological components with the command:

ComponentMeasurements[{MorphologicalComponents[img], img}, "MeanIntensity"]

I'm looking to use SelectComponents to select components based on their mean or median underlying pixel values. However, commands like the following:

SelectComponents[{MorphologicalComponents[img], img}, "MeanIntensity", # < 0.4 &];

Seem to simply fail. Is there a way to proceed?

Clarification - Actually, let me be a bit more specific about my question. I mean to first select MorphologicalComponents of a modified version of the image, specifically after running a filter on it. I then want to prune morphological components based on pixel values in the original unfiltered image. So I'd like to do something like this:

SelectComponents[{MorphologicalComponents[LaplacianFilter[img,3]], img}, "MeanIntensity", # < 0.4 &];
$\endgroup$
6
  • $\begingroup$ So maybe you want to work on MeanFilter[img, r] instead of img? $\endgroup$
    – Kuba
    Aug 6, 2013 at 7:49
  • $\begingroup$ @Kuba Hmm, that doesn't quite do what I'd like. I need to use this as a filter for MorphologicalComponents selected by some metric, and MeanFilter also smears out the image a bit. $\endgroup$
    – Uninstall
    Aug 6, 2013 at 7:58
  • $\begingroup$ "to select components based on their mean or median underlying pixel values" - I understand this as using ComponentMeasurements on MeanFilter[img, r], later you can reffer those positions to postions in orginal image. But maybe I have misunderstood your question, if so, I'm sorry :) $\endgroup$
    – Kuba
    Aug 6, 2013 at 8:03
  • $\begingroup$ You can just supply the image to SelectComponents and it will compute the MorphologicalComponents automatically: SelectComponents[img, "MeanIntensity", # < 0.4 &]; $\endgroup$ Aug 6, 2013 at 8:45
  • $\begingroup$ @SimonWoods Huh... never thought to try that. $\endgroup$
    – Uninstall
    Aug 6, 2013 at 8:52

1 Answer 1

1
$\begingroup$

You could use ComponentMeasurements and explicitly remove those components which don't satisfy the requirement:

m = MorphologicalComponents[LaplacianFilter[img, 3]];
test = # < 0.4 &;

m /. Cases[ComponentMeasurements[{m, img}, "MeanIntensity"], 
    HoldPattern[i_ -> v_] /; ! test[v] :> (i -> 0)]

Alternatively, it looks like the internal implementation of SelectComponents takes separate arguments for an image and a component matrix:

Image`MorphologicalOperationsDump`oSelectComponents[img, m, "MeanIntensity", test, Null]
$\endgroup$
1
  • $\begingroup$ Thanks for your answer - it's very good. $\endgroup$
    – Uninstall
    Aug 6, 2013 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.