# Extract preprocessed image and mask from Pyradiomics

**URL:** https://discourse.slicer.org/t/extract-preprocessed-image-and-mask-from-pyradiomics/22654
**Category:** Radiomics
**Tags:** python, pyradiomics
**Created:** [March 23, 2022, 2:32pm UTC](https://discourse.slicer.org/t/extract-preprocessed-image-and-mask-from-pyradiomics/22654 "2022-03-23T14:32:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![JonasB](https://avatars.discourse-cdn.com/v4/letter/j/8e7dd6/32.png) [@JonasB](https://discourse.slicer.org/u/JonasB)
#### Post date: [March 23, 2022, 2:32pm UTC](https://discourse.slicer.org/t/extract-preprocessed-image-and-mask-from-pyradiomics/22654/1 "2022-03-23T14:32:12Z")

</div>

Dear community,

I was wondering if it is possible to extract the images and masks on which the feature calculation is based with Pyradiomics in command-line batch mode. I would like to make some comparisons on different mask validation, image discretization, and normalization procedures.

Best,  
Jonas

---

<div class="post-metadata">

### Author: ![JoostJM](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joostjm/32/1091_2.png) [@JoostJM](https://discourse.slicer.org/u/JoostJM)
#### Post date: [March 25, 2022, 7:12am UTC](https://discourse.slicer.org/t/extract-preprocessed-image-and-mask-from-pyradiomics/22654/2 "2022-03-25T07:12:42Z")

</div>

Hello Jonas,

Currently, it is not possible to do so directly from the commandline. Still, PyRadiomcis is built fairly modular, so it shouldn’t be to much of a hassle to use the pre-processing functions directly.

Image pre-processing (e.g. normalization, resampling and application of filters) is all defined in `imageoperations.py`. Every functions accepts a `**kwargs` argument dict, which contains all configuration from the `setting` section in the parameter file (it doesn’t matter if there are settings in the dict that are intended for other functions, it just takes out those that are needed).

Image discretization is just as easy, but works on the numpy array extracted from the image. The function you’re looking for is `imageoperations.binImage`, which accepts the `image_array`, an optional `mask_array` and the `**kwargs` settings. In case the mask array (boolean array) is provided, the discretization is based only on the pixels inside the ROI (PyRadiomics default). If omitted, the entire image is discretized. Be aware that the selection of the label is done elsewhere, the mask array should have boolean datatype indicating only the active ROI.

Hope this helps.

Regards,

Joost

---

<div class="post-metadata">

### Author: ![JonasB](https://avatars.discourse-cdn.com/v4/letter/j/8e7dd6/32.png) [@JonasB](https://discourse.slicer.org/u/JonasB)
#### Post date: [March 25, 2022, 3:49pm UTC](https://discourse.slicer.org/t/extract-preprocessed-image-and-mask-from-pyradiomics/22654/3 "2022-03-25T15:49:33Z")

</div>

Thank you very much @JoostJM.  
Does that mean I need to integrate this into my code or apply imageoperations.py from command line?

Best,  
Jonas

---

<div class="post-metadata">

### Author: ![JoostJM](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joostjm/32/1091_2.png) [@JoostJM](https://discourse.slicer.org/u/JoostJM)
#### Post date: [March 26, 2022, 11:50am UTC](https://discourse.slicer.org/t/extract-preprocessed-image-and-mask-from-pyradiomics/22654/4 "2022-03-26T11:50:21Z")

</div>

Hello @JonasB,

To test this, you’d need to integrate it into your own python script. The PyRadiomics commandline does not expose that functionality.

Regards,

Joost

---

<div class="post-metadata">

### Author: ![JonasB](https://avatars.discourse-cdn.com/v4/letter/j/8e7dd6/32.png) [@JonasB](https://discourse.slicer.org/u/JonasB)
#### Post date: [October 6, 2022, 9:50am UTC](https://discourse.slicer.org/t/extract-preprocessed-image-and-mask-from-pyradiomics/22654/5 "2022-10-06T09:50:08Z")

</div>

Hi @JoostJM ,

thanks for your answers.  
I managed to transform the images.  
I was wondering, since the functions (such as imageoperations.getLoGImage) take the image and the segmentations but only output the transformed img could the segmentation (the region of interest) be effected by the transformation?  
Or in other words do we need to refine the mask for transformed images (might be that the borders of the segmentation from the original image do not fit 100% on the transformed image)?

Best regards,  
Jonas
