Run length matrix using mask


(Paulo Freire) #1

Hello, everyone.

I’m using the itkScalarImageToRunLengthMatrixFilter to extract texture features from brain images. I know that this particular class has the method SetMaskImage that can be used to constrain the region we want to extract features from. However, when I try to use it I always get blank images as a result. I’ve tried using masks with foreground values equal to 1 or equal to itk::NumericTraits< T >::max(), where T is the pixel type. All to no avail. When I don’t use a mask image, I get the expected outputs, but it’s really time-consuming.

Can someone please point me in the right direction? Using a mask to constrain the region to be processed would dramatically decrease the amount of time required to get the results I’m interested in.

Thank you all in advance!


(Dženan Zukić) #2

The mask condition seems to be checked here:

I would recommend running your program under debugging, stepping into GetMaskImage() and inspecting relevant variables. That should give you a clue about what is wrong.


(Matt McCormick) #3

@pfreire you may be interested in the ITKTextureFeatures module:

This supports a mask and can generate texture maps.


(Paulo Freire) #4

Thank you, @matt.mccormick. I’ve looked into it and I was able to run the RLM example, but I was still not able to get texture maps using masks (only using the whole image).

For instance, the images I’m using can be downloaded from here: https://drive.google.com/file/d/139zkEEMwIfaAsEolBivsas19u9dj7nvs/view?usp=sharing

This is rather frustrating, for it seems that I’m missing something very basic.

Thank you in advance!


(Dženan Zukić) #5

Can you also share source code of the minimum working example which shows the problem?


(Paulo Freire) #6

Certainly, @dzenanz! Here it is: https://drive.google.com/file/d/1dOORBsD7DuVBxWDJc6KLUib9zyqwSdcg/view?usp=sharing

Thank you very much.


(Dženan Zukić) #7

Mystery solved!

const InputImageType *mask_img = bip::utils::ReadImage< InputImageType >(argv[2]);

should be replaced by

InputImageType::ConstPointer mask_img = bip::utils::ReadImage< InputImageType >(argv[2]);

An ordinary pointer does not keep ownership of ITK’s reference counted classes such as Image, so the return value of the ReadImage function immediately goes out of scope, leaving mask_img a dangling pointer. It is pure luck that the program does not crash.


(Paulo Freire) #8

Perfect! Thank you so much, @dzenanz! Awesome help and support. Cheers!