How to apply mask when using rescale filter

Hi, I am implementing a modified version of the filtering approach in this tutorial: Segment Blood Vessels With Multi-Scale Hessian-Based Measure — v5.3.0

However, my images contain tissue for which I do not want to apply the filter (i.e., GM and CSF). I already have a mask of the tissue that I do want to apply the filter to (WM). Is there a way to apply a mask when filtering so it is only calculated with the voxels inside the mask?

Thanks for your time!

I don’t think that either HessianToObjectnessMeasureImageFilter or MultiScaleHessianBasedMeasureImageFilter accept a mask. Changing their code to accept a mask should not be hard, though.

Thanks for the info! I am currently using the Python wrapper for ITK as I have no experience with C++ code. I am happy to give this a try though. Is there any template code you could point me to that implements masking already?

I meant changing C++ library code to suit your needs.

You can accomplish the same thing by masking the results image, at the cost of the computation being slower than absolutely necessary.

Oh I see, I think I am misunderstanding the implementation of the mask. Since the filters I am trying to use are based on relative intensities surrounding the voxels of interest, my results are being overwhelmed by the zeros in the image. I want to calculation to only be performed within the mask, not just mask the results of the overall calculation (hopefully that makes sense). To explain further, I am using these filters to detect “vesselness”, but since the lateral ventricles are “vessel-like” according to the filter, the focus of the resulting mask is in the ventricles and the areas of actual interest in the white matter are de-emphasized or ignored.

The only other solution I could think of is a patch-based method but I would like a more elegant solution if possible.

Thanks again

I don’t think there is code for what you want. Masking, then computing vesselness, seems to be closest to what you want, by using existing code.