I am taking a lot of measurements from regions of interest in microscopy images and am finding that generating binary masks to use with ComponentMeasurements is rather slow (at least it's slow the way I am doing it). Are there any faster ways to generate a label matrix than going through Binarize and Graphics or can Binarize and Graphics functions be made faster with Compile and/or Parallel? Below is how I make a binarized polygon mask the same size as the cropped microscopy image I am working with:

   imageIn_] := (

   binMaskFromPtsIn = 
     Graphics[{White, Polygon[ptsIn]}, 
      PlotRange -> {{1, 600}, {1, 600}}, 
      ImageSize -> {600, 600}, AspectRatio -> 1, 
      ImagePadding -> {{0, 0}, {0, 0}}, Background -> Black];

   compMeasureStatsFromMaskOnImage = 
      imageIn}, {"MeanIntensity", "StandardDeviationIntensity", 
      "TotalIntensity", "Area"}];

   (* stats returned for the mask all have label 1 in the matrix \
generated by MorphologicalComponents *)

   compMeasureStatsFromMaskOnImage$Label1Stats = 
    1 /. compMeasureStatsFromMaskOnImage


Typical AbsoluteTiming I get is around 0.40 seconds and generating the binarized mask (binMaskFromPtsIn) seems to be the slow step.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.