# Convert scalar image into image of vectors

**URL:** https://discourse.itk.org/t/convert-scalar-image-into-image-of-vectors/753
**Category:** Beginner Questions
**Created:** [March 9, 2018, 4:03pm UTC](https://discourse.itk.org/t/convert-scalar-image-into-image-of-vectors/753 "2018-03-09T16:03:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Fijoy\_Vadakkumpadan](https://discourse.itk.org/user_avatar/discourse.itk.org/fijoy_vadakkumpadan/32/1287_2.png) [@Fijoy\_Vadakkumpadan](https://discourse.itk.org/u/Fijoy_Vadakkumpadan)
#### Post date: [March 9, 2018, 4:03pm UTC](https://discourse.itk.org/t/convert-scalar-image-into-image-of-vectors/753/1 "2018-03-09T16:03:27Z")

</div>

Hello,

Is there a filter or pipeline of filters that I can use to convert a scalar image into an image of vectors, each vector having just one component?

For example, I want to convert itk::Image\<unsigned char, 3\> to itk::Image\<itk::Vector\<unsigned char, 1\>, 3\>. Asking because I want to run the itk::ImageKmeansModelEstimator filter on a scalar image, but this filter only accepts an image of vectors if I’m not mistaken. I do see the itk::ComposeImageFilter filter, but it produces itk::VectorImage and not image of vectors. I can always use iterators and indexing to do the conversion, but want to check if a filter is available first.

Thanks,  
–Fijoy

---

<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: [March 9, 2018, 4:59pm UTC](https://discourse.itk.org/t/convert-scalar-image-into-image-of-vectors/753/2 "2018-03-09T16:59:30Z")

</div>

> [@Fijoy\_Vadakkumpadan](#):
>
> I can always use iterators and indexing to do the conversion, but want to check if a filter is available first.

Hello!

The ComposeImageFilter can be used to create any image of a vector like type. Here is an example for an Image of CovariantVector pixel type, which should be very similar to what you are looking for:

[https://itk.org/Doxygen/html/WikiExamples\_2ImageProcessing\_2Compose3DCovariantVectorImageFilter\_8cxx-example.html#\_a1](https://itk.org/Doxygen/html/WikiExamples_2ImageProcessing_2Compose3DCovariantVectorImageFilter_8cxx-example.html#_a1)
