# Creating a coefficient image from mask

**URL:** https://discourse.itk.org/t/creating-a-coefficient-image-from-mask/3236
**Category:** Beginner Questions
**Tags:** simpleitk
**Created:** [June 28, 2020, 6:32pm UTC](https://discourse.itk.org/t/creating-a-coefficient-image-from-mask/3236 "2020-06-28T18:32:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Michael\_Ef](https://discourse.itk.org/user_avatar/discourse.itk.org/michael_ef/32/1441_2.png) [@Michael\_Ef](https://discourse.itk.org/u/Michael_Ef)
#### Post date: [June 28, 2020, 6:32pm UTC](https://discourse.itk.org/t/creating-a-coefficient-image-from-mask/3236/1 "2020-06-28T18:32:59Z")

</div>

Hi all,

what is the best way to create a coefficient image (in mhd format) with values between 0 and 1 from a segmented image (grayscale)? E.g. every pixel on the reference image with value 100 will hold the value 0.4 in the output image. Thanks in advance.

Regards  
Michael

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 29, 2020, 1:16pm UTC](https://discourse.itk.org/t/creating-a-coefficient-image-from-mask/3236/2 "2020-06-29T13:16:38Z")

</div>

You should use [RescaleIntensityImageFilter](https://itk.org/Doxygen/html/classitk_1_1RescaleIntensityImageFilter.html) with `uchar` as input type and `float` as output type. Working out the offset and rescale coefficient should be easy.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 29, 2020, 1:22pm UTC](https://discourse.itk.org/t/creating-a-coefficient-image-from-mask/3236/3 "2020-06-29T13:22:32Z")

</div>

For the case with using SimpleITK you will have to first use the `CastImageFilter` with the output pixel type as `sitkFloat32`, then rescaling can be done by either using the above filter or simple multiplying by a scalar e.g. `img * (0.4/100)`.
