# Mean of Complex Vector Image

**URL:** https://discourse.itk.org/t/mean-of-complex-vector-image/632
**Category:** Algorithms
**Created:** [January 30, 2018, 1:12pm UTC](https://discourse.itk.org/t/mean-of-complex-vector-image/632 "2018-01-30T13:12:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![spinicist](https://discourse.itk.org/user_avatar/discourse.itk.org/spinicist/32/183_2.png) [@spinicist](https://discourse.itk.org/u/spinicist)
#### Post date: [January 30, 2018, 1:12pm UTC](https://discourse.itk.org/t/mean-of-complex-vector-image/632/1 "2018-01-30T13:12:14Z")

</div>

Hi,

I need to take the average (mean) of a complex-valued vector image (i.e. the output should also be a complex vector). I am trying to do this with `itk::StatisticsImageFilter`, however, I am getting the following compile error:

```auto
  typedef typename vnl_numeric_traits<T>::abs_t abs_t;
                   ^
/usr/local/include/ITK-4.13/vnl/vnl_vector.h:300:20: note: in instantiation of template class 'vnl_c_vector<itk::VariableLengthVector<std::__1::complex<double> > >' requested here
  typedef typename vnl_c_vector<T>::abs_t abs_t;
                   ^
/usr/local/include/ITK-4.13/itkArray.h:50:42: note: in instantiation of template class 'vnl_vector<itk::VariableLengthVector<std::__1::complex<double> > >' requested here
class ITK_TEMPLATE_EXPORT Array : public vnl_vector< TValue >
                                         ^
/usr/local/include/ITK-4.13/itkStatisticsImageFilter.h:173:27: note: in instantiation of template class 'itk::Array<itk::VariableLengthVector<std::__1::complex<double> > >' requested here
  Array< RealType > m_ThreadSum;
                          ^
../Source/Utils/qi_coil_combine.cpp:111:27: note: in instantiation of template class 'itk::StatisticsImageFilter<itk::VectorImage<std::__1::complex<float>, 3> >' requested here
        auto stats = itk::StatisticsImageFilter<QI::VectorVolumeXF>::New();
                          ^
/usr/local/include/ITK-4.13/vnl/vnl_numeric_traits.h:38:27: note: template is declared here
class VNL_TEMPLATE_EXPORT vnl_numeric_traits;

```

I assume this is because someone assumed no-one would be crazy enough to want a complex-vector mean, and so the required traits aren’t defined. Is it possible for me to define them myself and if so where?

Thanks.

---

<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: [January 30, 2018, 1:39pm UTC](https://discourse.itk.org/t/mean-of-complex-vector-image/632/2 "2018-01-30T13:39:28Z")

</div>

Hello Tobias,

The StatisticsImageFilter does not work with ImageVectors, Images of Vectors or complex pixel types, much less ImageVectors of complex. This is because the filter computes the Minimum and Maximum, and those listed image type’s pixels types do not form an ordered set, that is the less than operator has not meaning for vectors or complex types.

One could argue that there should be two Statistics filters, one for pixels of ordered set and one for un-ordered, because Mean, Sum, and Variance could still have meaning.

Brad

---

<div class="post-metadata">

### Author: ![spinicist](https://discourse.itk.org/user_avatar/discourse.itk.org/spinicist/32/183_2.png) [@spinicist](https://discourse.itk.org/u/spinicist)
#### Post date: [January 30, 2018, 3:12pm UTC](https://discourse.itk.org/t/mean-of-complex-vector-image/632/3 "2018-01-30T15:12:00Z")

</div>

Thanks Brad. Yes, some kind of “Reduce Region” filter that applies a single function (e.g. sum) might be useful. Variance might be a bit tricky.

Can you think of any other filters that might help me in the mean-time? Getting just the sum would do. As always I’m in a rush.

---

<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: [January 30, 2018, 7:07pm UTC](https://discourse.itk.org/t/mean-of-complex-vector-image/632/4 "2018-01-30T19:07:12Z")

</div>

Would just manually using an ImageRegionIterator with accumulation work for you?

---

<div class="post-metadata">

### Author: ![spinicist](https://discourse.itk.org/user_avatar/discourse.itk.org/spinicist/32/183_2.png) [@spinicist](https://discourse.itk.org/u/spinicist)
#### Post date: [February 2, 2018, 7:50pm UTC](https://discourse.itk.org/t/mean-of-complex-vector-image/632/5 "2018-02-02T19:50:03Z")

</div>

Yes - that’s essentially what I ended up doing. Thanks!
