# How to transfer an image buffer to matlab image matrix

**URL:** <https://discourse.itk.org/t/how-to-transfer-an-image-buffer-to-matlab-image-matrix/5568>\
**Category:** Beginner Questions\
**Created:** [December 13, 2022, 11:50am UTC](https://discourse.itk.org/t/how-to-transfer-an-image-buffer-to-matlab-image-matrix/5568 "2022-12-13T11:50:25Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![allen](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@allen](https://discourse.itk.org/u/allen)\
**Post date:** [December 17, 2022, 9:30am UTC](https://discourse.itk.org/t/how-to-transfer-an-image-buffer-to-matlab-image-matrix/5568/4 "2022-12-17T09:30:28Z")

</div>

channel sequence from rgbrgbrgb…rgb to rrr…rggg…gbbb…b is called convert from HWC to CHW ryt,  
what if i want to do this in pure itk,  
i use VectorIndexSelectionCastImageFilter first, then compose them by ComposeImageFilter like this [post](https://discourse.itk.org/t/how-to-get-the-0-th-component-for-vector-image/2759/2) said, will i get a CHW image, or get the same HWC image just like split the channels before

```auto
// PixelType comes from completeMontage template 
// template <unsigned Dimension,
// typename PixelType,
// typename AccumulatePixelType>
using ScalarPixelType = typename itk::NumericTraits<PixelType>::ValueType;
using ScalarImageType = itk::Image<ScalarPixelType, Dimension>;
using OriginalImageType = itk::Image<PixelType, Dimension>;
using ImageAdaptorType = itk::VectorIndexSelectionCastImageFilter<OriginalImageType, ScalarImageType>;
using ComposeType = itk::ComposeImageFilter<ScalarImageType, OriginalImageType>;
typename ImageAdaptorType::Pointer cAdaptor = ImageAdaptorType::New();
cAdaptor->SetInput(resampleF->GetOutput());

std::vector<typename ScalarImageType::Pointer> zImages(PixelType::Length);
for (unsigned c = 0; c < PixelType::Length; c++)
{
  cAdaptor->SetIndex(c);
  zImages[c] = cAdaptor->GetOutput();
  zImages[c]->DisconnectPipeline();
}

// compose an RGB(A) image from the filtered component images
typename ComposeType::Pointer compose = ComposeType::New();
for (unsigned c = 0; c < PixelType::Length; c++)
{
  compose->SetInput(c, zImages[c]);
}
compose->Update();

```

---

_[View the full topic](https://discourse.itk.org/t/how-to-transfer-an-image-buffer-to-matlab-image-matrix/5568)._
