# Multiply a vector image with scalar (SimpleITK)

**URL:** <https://discourse.itk.org/t/multiply-a-vector-image-with-scalar-simpleitk/4612>\
**Category:** Beginner Questions\
**Tags:** simpleitk, python\
**Created:** [November 25, 2021, 6:41am UTC](https://discourse.itk.org/t/multiply-a-vector-image-with-scalar-simpleitk/4612 "2021-11-25T06:41:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alsurayhi](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Alsurayhi](https://discourse.itk.org/u/Alsurayhi)\
**Post date:** [November 25, 2021, 6:41am UTC](https://discourse.itk.org/t/multiply-a-vector-image-with-scalar-simpleitk/4612/1 "2021-11-25T06:41:55Z")

</div>

To multiply a vector image with a scalar, I used

> import SimpleITK as sitk  
> multiply = sitk.MultiplyImageFilter()  
> multplied\_img = multiply.Execute(img , 0.5)

my input image is of size 512 \*512 \*200 \*3.  
But it gives me this error message

> RuntimeError: Exception thrown in SimpleITK MultiplyImageFilter\_Execute: d:\a\1\sitk\code\common\include\sitkMemberFunctionFactory.hxx:158:  
> sitk::ERROR: Pixel type: vector of 32-bit float is not supported in 3D by class itk::simple::MultiplyImageFilter.

What should I do? Is there away to apply the vector image multiplication from SimpleITK?

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [November 25, 2021, 2:52pm UTC](https://discourse.itk.org/t/multiply-a-vector-image-with-scalar-simpleitk/4612/2 "2021-11-25T14:52:42Z")

</div>

Hello @Alsurayhi,

See code below:

```auto
val = 0.5
multplied_img = sitk.Compose([sitk.VectorIndexSelectionCast(img,i)*val for i in range(img.GetNumberOfComponentsPerPixel())])

```

---

<div class="post-metadata">

**Author:** ![Alsurayhi](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@Alsurayhi](https://discourse.itk.org/u/Alsurayhi)\
**Post date:** [November 25, 2021, 6:19pm UTC](https://discourse.itk.org/t/multiply-a-vector-image-with-scalar-simpleitk/4612/3 "2021-11-25T18:19:57Z")

</div>

It works.  
Thank You!
