File: otbComplexImageManipulationTest.cxx

package info (click to toggle)
otb 7.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,005,476 kB
  • sloc: cpp: 270,143; xml: 128,722; ansic: 4,367; sh: 1,768; python: 1,084; perl: 92; makefile: 72
file content (734 lines) | stat: -rw-r--r-- 22,165 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
/*
 * Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <complex>

#include "otbImageFileReader.h"
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbMacro.h"
#include "itkImageRegionIteratorWithIndex.h"

// Do all comparison in double precision
const double Epsilon = 1.E-6;

template <class TPixel>
bool IsEqual(TPixel output, TPixel expected)
{
  typedef typename itk::NumericTraits<TPixel>::RealType RealType;

  RealType outputReal   = static_cast<RealType>(output);
  RealType expectedReal = static_cast<RealType>(expected);
  // avoid division by zero
  return outputReal == expectedReal || (std::abs(expectedReal - outputReal) / std::abs(expectedReal) < Epsilon);
}

template <class TPixel>
bool IsEqual(std::complex<TPixel> output, std::complex<TPixel> expected)
{
  typedef typename itk::NumericTraits<std::complex<TPixel>>::RealType       RealType;
  typedef typename itk::NumericTraits<std::complex<TPixel>>::ScalarRealType ScalarRealType;

  RealType outputReal(static_cast<ScalarRealType>(output.real()), static_cast<ScalarRealType>(output.imag()));
  RealType expectedReal(static_cast<ScalarRealType>(expected.real()), static_cast<ScalarRealType>(expected.imag()));

  // avoid division by zero
  return outputReal == expectedReal || (std::abs(expectedReal - outputReal) / std::abs(expectedReal) < Epsilon);
}

template <class TInternalPixel>
bool IsEqual(itk::VariableLengthVector<TInternalPixel> output, itk::VariableLengthVector<TInternalPixel> expected)
{
  bool result = true;
  for (unsigned int i = 0; i < output.Size(); ++i)
  {
    result = result && IsEqual(output[i], expected[i]);
  }
  return result;
}


template <class TIndex, class TPixel>
bool TestCompare(TIndex idx, TPixel output, TPixel expected)
{
  otbLogMacro(Debug, << "PIXEL " << idx << "  -->  "
                     << "OUTPUT = " << output << "   ||   "
                     << "EXPECTED = " << expected << std::endl);

  if (!IsEqual(output, expected))
  {
    std::cerr << "ERROR at position " << idx << ". Got " << output << ", expected " << expected << std::endl;
    return false;
  }
  return true;
}

template <class TImagePointerType>
itk::ImageRegionIteratorWithIndex<typename TImagePointerType::ObjectType> ReadRegion(const char* filename, TImagePointerType& image, unsigned int w,
                                                                                     unsigned int h)
{
  typedef TImagePointerType                     ImagePointerType;
  typedef typename ImagePointerType::ObjectType ImageType;
  typedef typename ImageType::RegionType        RegionType;
  typedef typename ImageType::IndexType         IndexType;
  typedef typename ImageType::SizeType          SizeType;

  IndexType idx;
  idx.Fill(0);

  SizeType size;
  size[0] = w;
  size[1] = h;

  RegionType region;
  region.SetSize(size);
  region.SetIndex(idx);

  typedef otb::ImageFileReader<ImageType> ReaderType;
  typename ReaderType::Pointer            reader = ReaderType::New();
  reader->SetFileName(filename);
  reader->GetOutput()->SetRequestedRegion(region);
  reader->Update();

  image = reader->GetOutput();

  return itk::ImageRegionIteratorWithIndex<ImageType>(image, region);
}

/***********
 * 1.
 * Read Monoband Scalar as Image<complex>
 * out : real = in, imag = 0
 ***********/
template <class InternalType>
int otbMonobandScalarToImageComplexGeneric(int itkNotUsed(argc), char* argv[])
{
  typedef InternalType           RealType;
  typedef std::complex<RealType> ComplexType;

  typedef ComplexType PixelType;
  typedef otb::Image<PixelType, 2> ImageType;

  const unsigned int w = 10;
  const unsigned int h = 2;

  typename ImageType::Pointer                  image;
  itk::ImageRegionIteratorWithIndex<ImageType> it = ReadRegion(argv[1], image, w, h);

  typename ImageType::SizeType largestRegion;
  largestRegion = image->GetLargestPossibleRegion().GetSize();

  unsigned int count = 0;
  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
  {
    count = it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0];

    if (!TestCompare(it.GetIndex(), it.Get(), ComplexType(count, 0)))
      return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int otbMonobandScalarToImageComplexFloat(int argc, char* argv[])
{
  return otbMonobandScalarToImageComplexGeneric<float>(argc, argv);
}

int otbMonobandScalarToImageComplexDouble(int argc, char* argv[])
{
  return otbMonobandScalarToImageComplexGeneric<double>(argc, argv);
}

int otbMonobandScalarToImageComplexInt(int argc, char* argv[])
{
  return otbMonobandScalarToImageComplexGeneric<int>(argc, argv);
}

int otbMonobandScalarToImageComplexShort(int argc, char* argv[])
{
  return otbMonobandScalarToImageComplexGeneric<short>(argc, argv);
}

/***********
 * 2.
 * Read MonobandComplex as Image<double>
 * out : norm(in)
 ***********/
template <class InternalType>
int otbMonobandComplexToImageScalarGeneric(int itkNotUsed(argc), char* argv[])
{
  typedef InternalType                                             InputType;
  typedef std::complex<InputType>                                  ComplexType;
  typedef typename itk::NumericTraits<ComplexType>::RealType       RealType;
  typedef typename itk::NumericTraits<ComplexType>::ScalarRealType ScalarRealType;

  typedef InputType PixelType;
  typedef otb::Image<PixelType, 2> ImageType;

  const unsigned int w = 10;
  const unsigned int h = 2;

  typename ImageType::Pointer                  image;
  itk::ImageRegionIteratorWithIndex<ImageType> it = ReadRegion(argv[1], image, w, h);

  typename ImageType::SizeType largestRegion;
  largestRegion = image->GetLargestPossibleRegion().GetSize();

  unsigned int count = 0;
  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
  {
    count = 2 * (it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0]);

    ComplexType expected = ComplexType(count, count + 1);
    RealType    expectedReal(static_cast<ScalarRealType>(expected.real()), static_cast<ScalarRealType>(expected.imag()));

    if (!TestCompare(it.GetIndex(), it.Get(), static_cast<InputType>(std::abs(expectedReal))))
      return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int otbMonobandComplexToImageScalarFloat(int argc, char* argv[])
{
  return otbMonobandComplexToImageScalarGeneric<float>(argc, argv);
}

int otbMonobandComplexToImageScalarDouble(int argc, char* argv[])
{
  return otbMonobandComplexToImageScalarGeneric<double>(argc, argv);
}

int otbMonobandComplexToImageScalarInt(int argc, char* argv[])
{
  return otbMonobandComplexToImageScalarGeneric<int>(argc, argv);
}

int otbMonobandComplexToImageScalarShort(int argc, char* argv[])
{
  return otbMonobandComplexToImageScalarGeneric<short>(argc, argv);
}

/***********
 * 3.
 * Read Monoband Complex as Image<complex>
 * out : in
 ***********/
template <class InternalType>
int otbMonobandComplexToImageComplexGeneric(int itkNotUsed(argc), char* argv[])
{
  typedef InternalType           RealType;
  typedef std::complex<RealType> ComplexType;

  typedef ComplexType PixelType;
  typedef otb::Image<PixelType, 2> ImageType;

  const unsigned int w = 10;
  const unsigned int h = 2;

  typename ImageType::Pointer                  image;
  itk::ImageRegionIteratorWithIndex<ImageType> it = ReadRegion(argv[1], image, w, h);

  typename ImageType::SizeType largestRegion;
  largestRegion = image->GetLargestPossibleRegion().GetSize();

  unsigned int count = 0;
  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
  {
    count = 2 * (it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0]);
    if (!TestCompare(it.GetIndex(), it.Get(), ComplexType(count, count + 1)))
      return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int otbMonobandComplexToImageComplexFloat(int argc, char* argv[])
{
  return otbMonobandComplexToImageComplexGeneric<float>(argc, argv);
}

int otbMonobandComplexToImageComplexDouble(int argc, char* argv[])
{
  return otbMonobandComplexToImageComplexGeneric<double>(argc, argv);
}

int otbMonobandComplexToImageComplexInt(int argc, char* argv[])
{
  return otbMonobandComplexToImageComplexGeneric<int>(argc, argv);
}

int otbMonobandComplexToImageComplexShort(int argc, char* argv[])
{
  return otbMonobandComplexToImageComplexGeneric<short>(argc, argv);
}

/***********
 * 4.
 * Read Monoband Complex as VectorImage<double>
 * out : [0]=in.real(), [1]=in.imag()
 ***********/
template <class InternalType>
int otbMonobandComplexToVectorImageScalarGeneric(int itkNotUsed(argc), char* argv[])
{
  typedef InternalType RealType;

  typedef otb::VectorImage<RealType, 2> ImageType;
  typedef typename ImageType::PixelType PixelType;

  const unsigned int w = 10;
  const unsigned int h = 2;

  typename ImageType::Pointer                  image;
  itk::ImageRegionIteratorWithIndex<ImageType> it = ReadRegion(argv[1], image, w, h);

  typename ImageType::SizeType largestRegion;
  largestRegion = image->GetLargestPossibleRegion().GetSize();

  unsigned int count = 0;
  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
  {
    count = 2 * (it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0]);

    PixelType expected(2);
    expected[0] = count;
    expected[1] = count + 1;

    if (!TestCompare(it.GetIndex(), it.Get(), expected))
      return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int otbMonobandComplexToVectorImageScalarFloat(int argc, char* argv[])
{
  return otbMonobandComplexToVectorImageScalarGeneric<float>(argc, argv);
}

int otbMonobandComplexToVectorImageScalarDouble(int argc, char* argv[])
{
  return otbMonobandComplexToVectorImageScalarGeneric<double>(argc, argv);
}

int otbMonobandComplexToVectorImageScalarInt(int argc, char* argv[])
{
  return otbMonobandComplexToVectorImageScalarGeneric<int>(argc, argv);
}

int otbMonobandComplexToVectorImageScalarShort(int argc, char* argv[])
{
  return otbMonobandComplexToVectorImageScalarGeneric<short>(argc, argv);
}

/***********
 * 5.
 * Read Monoband Complex as VectorImage<complex>
 * out : [0]=in
 ***********/
template <class InternalType>
int otbMonobandComplexToVectorImageComplexGeneric(int itkNotUsed(argc), char* argv[])
{
  typedef InternalType           RealType;
  typedef std::complex<RealType> ComplexType;

  typedef otb::VectorImage<ComplexType, 2> ImageType;
  typedef typename ImageType::PixelType PixelType;

  const unsigned int w = 10;
  const unsigned int h = 2;

  typename ImageType::Pointer                  image;
  itk::ImageRegionIteratorWithIndex<ImageType> it = ReadRegion(argv[1], image, w, h);

  typename ImageType::SizeType largestRegion;
  largestRegion = image->GetLargestPossibleRegion().GetSize();

  unsigned int count = 0;
  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
  {
    count = 2 * (it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0]);

    PixelType expected(1);
    expected[0] = ComplexType(count, count + 1);

    if (!TestCompare(it.GetIndex(), it.Get(), expected))
      return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int otbMonobandComplexToVectorImageComplexFloat(int argc, char* argv[])
{
  return otbMonobandComplexToVectorImageComplexGeneric<float>(argc, argv);
}

int otbMonobandComplexToVectorImageComplexDouble(int argc, char* argv[])
{
  return otbMonobandComplexToVectorImageComplexGeneric<double>(argc, argv);
}

int otbMonobandComplexToVectorImageComplexInt(int argc, char* argv[])
{
  return otbMonobandComplexToVectorImageComplexGeneric<int>(argc, argv);
}

int otbMonobandComplexToVectorImageComplexShort(int argc, char* argv[])
{
  return otbMonobandComplexToVectorImageComplexGeneric<short>(argc, argv);
}

/***********
 * 6.
 * Read Multiband Scalar as Image<complex>
 * out : out.real=in[0], out.imag=in[1]
 ***********/
template <class InternalType>
int otbMultibandScalarToImageComplexGeneric(int itkNotUsed(argc), char* argv[])
{
  typedef InternalType           RealType;
  typedef std::complex<RealType> ComplexType;

  typedef otb::Image<ComplexType, 2> ImageType;
  typedef typename ImageType::PixelType PixelType;

  const unsigned int w = 10;
  const unsigned int h = 2;

  typename ImageType::Pointer                  image;
  itk::ImageRegionIteratorWithIndex<ImageType> it = ReadRegion(argv[1], image, w, h);

  typename ImageType::SizeType largestRegion;
  largestRegion = image->GetLargestPossibleRegion().GetSize();

  unsigned int count = 0;
  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
  {
    count = it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0];

    PixelType expected(count, count + largestRegion[0] * largestRegion[1]);

    if (!TestCompare(it.GetIndex(), it.Get(), expected))
      return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int otbMultibandScalarToImageComplexFloat(int argc, char* argv[])
{
  return otbMultibandScalarToImageComplexGeneric<float>(argc, argv);
}

int otbMultibandScalarToImageComplexDouble(int argc, char* argv[])
{
  return otbMultibandScalarToImageComplexGeneric<double>(argc, argv);
}

int otbMultibandScalarToImageComplexInt(int argc, char* argv[])
{
  return otbMultibandScalarToImageComplexGeneric<int>(argc, argv);
}

int otbMultibandScalarToImageComplexShort(int argc, char* argv[])
{
  return otbMultibandScalarToImageComplexGeneric<short>(argc, argv);
}


/***********
 * 7.
 * Read Multiband Scalar as VectorImage<complex>
 * out : (out[0].real=in[0], out[0].imag=0), (out[1].real=in[1], out[1].imag=0), ...
 ***********/
template <class InternalType>
int otbMultibandScalarToVectorImageComplexGeneric(int itkNotUsed(argc), char* argv[])
{
  typedef InternalType           RealType;
  typedef std::complex<RealType> ComplexType;

  typedef otb::VectorImage<ComplexType, 2> ImageType;
  typedef typename ImageType::PixelType PixelType;

  const unsigned int w = 10;
  const unsigned int h = 2;

  typename ImageType::Pointer                  image;
  itk::ImageRegionIteratorWithIndex<ImageType> it = ReadRegion(argv[1], image, w, h);

  typename ImageType::SizeType largestRegion;
  largestRegion = image->GetLargestPossibleRegion().GetSize();

  unsigned int count = 0;
  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
  {
    count = it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0];

    PixelType expected(2);
    expected[0] = ComplexType(count, 0);
    expected[1] = ComplexType(count + largestRegion[0] * largestRegion[1], 0);

    if (!TestCompare(it.GetIndex(), it.Get(), expected))
      return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int otbMultibandScalarToVectorImageComplexFloat(int argc, char* argv[])
{
  return otbMultibandScalarToVectorImageComplexGeneric<float>(argc, argv);
}

int otbMultibandScalarToVectorImageComplexDouble(int argc, char* argv[])
{
  return otbMultibandScalarToVectorImageComplexGeneric<double>(argc, argv);
}

int otbMultibandScalarToVectorImageComplexInt(int argc, char* argv[])
{
  return otbMultibandScalarToVectorImageComplexGeneric<int>(argc, argv);
}

int otbMultibandScalarToVectorImageComplexShort(int argc, char* argv[])
{
  return otbMultibandScalarToVectorImageComplexGeneric<short>(argc, argv);
}


/***********
 * 8.
 * Read Multiband Complex as VectorImage<scalar>
 * out : out[0]=in[0].real, out[1]=in[0].imag, out[2]=in[0].real, out[3]=in[0].imag, ...
 ***********/
template <class InternalType>
int otbMultibandComplexToVectorImageScalarGeneric(int itkNotUsed(argc), char* argv[])
{
  typedef InternalType RealType;
  typedef otb::VectorImage<RealType, 2> ImageType;
  typedef typename ImageType::PixelType PixelType;

  const unsigned int w = 10;
  const unsigned int h = 2;

  typename ImageType::Pointer                  image;
  itk::ImageRegionIteratorWithIndex<ImageType> it = ReadRegion(argv[1], image, w, h);

  typename ImageType::SizeType largestRegion;
  largestRegion = image->GetLargestPossibleRegion().GetSize();

  const unsigned int nbbands = image->GetNumberOfComponentsPerPixel();

  unsigned int count = 0;
  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
  {
    count = 2 * (it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0]);

    PixelType expected(nbbands);
    for (unsigned int band = 0; band < nbbands; band += 2)
    {
      expected[band]     = count + band * largestRegion[0] * largestRegion[1];
      expected[band + 1] = count + 1 + band * largestRegion[0] * largestRegion[1];
    }

    if (!TestCompare(it.GetIndex(), it.Get(), expected))
      return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int otbMultibandComplexToVectorImageScalarFloat(int argc, char* argv[])
{
  return otbMultibandComplexToVectorImageScalarGeneric<float>(argc, argv);
}

int otbMultibandComplexToVectorImageScalarDouble(int argc, char* argv[])
{
  return otbMultibandComplexToVectorImageScalarGeneric<double>(argc, argv);
}

int otbMultibandComplexToVectorImageScalarInt(int argc, char* argv[])
{
  return otbMultibandComplexToVectorImageScalarGeneric<int>(argc, argv);
}

int otbMultibandComplexToVectorImageScalarShort(int argc, char* argv[])
{
  return otbMultibandComplexToVectorImageScalarGeneric<short>(argc, argv);
}

/***********
 * 9.
 * Read Multiband Complex as VectorImage<complex>
 * out : out[0]=in[0], out[1]=in[1], ...
 ***********/
template <class InternalType>
int otbMultibandComplexToVectorImageComplexGeneric(int itkNotUsed(argc), char* argv[])
{
  typedef InternalType           RealType;
  typedef std::complex<RealType> ComplexType;

  typedef otb::VectorImage<ComplexType, 2> ImageType;
  typedef typename ImageType::PixelType PixelType;

  const unsigned int w = 10;
  const unsigned int h = 2;

  typename ImageType::Pointer                  image;
  itk::ImageRegionIteratorWithIndex<ImageType> it = ReadRegion(argv[1], image, w, h);

  typename ImageType::SizeType largestRegion;
  largestRegion = image->GetLargestPossibleRegion().GetSize();

  const unsigned int nbbands = image->GetNumberOfComponentsPerPixel();

  unsigned int count = 0;
  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
  {
    count = 2 * (it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0]);

    PixelType expected(nbbands);
    for (unsigned int band = 0; band < nbbands; ++band)
    {
      expected[band] = ComplexType(count + band * 2 * largestRegion[0] * largestRegion[1], count + 1 + band * 2 * largestRegion[0] * largestRegion[1]);
    }

    if (!TestCompare(it.GetIndex(), it.Get(), expected))
      return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int otbMultibandComplexToVectorImageComplexFloat(int argc, char* argv[])
{
  return otbMultibandComplexToVectorImageComplexGeneric<float>(argc, argv);
}

int otbMultibandComplexToVectorImageComplexDouble(int argc, char* argv[])
{
  return otbMultibandComplexToVectorImageComplexGeneric<double>(argc, argv);
}

int otbMultibandComplexToVectorImageComplexShort(int argc, char* argv[])
{
  return otbMultibandComplexToVectorImageComplexGeneric<short>(argc, argv);
}

int otbMultibandComplexToVectorImageComplexInt(int argc, char* argv[])
{
  return otbMultibandComplexToVectorImageComplexGeneric<int>(argc, argv);
}

/***********
 * 10.
 * Read Monoband Scalar as VectorImage<complex>
 * out : out[0].real=in, out[0].imag=0
 ***********/
template <class InternalType>
int otbMonobandScalarToVectorImageComplexGeneric(int itkNotUsed(argc), char* argv[])
{
  typedef InternalType           RealType;
  typedef std::complex<RealType> ComplexType;

  typedef otb::VectorImage<ComplexType, 2> ImageType;
  typedef typename ImageType::PixelType PixelType;

  const unsigned int w = 10;
  const unsigned int h = 2;

  typename ImageType::Pointer                  image;
  itk::ImageRegionIteratorWithIndex<ImageType> it = ReadRegion(argv[1], image, w, h);

  typename ImageType::SizeType largestRegion;
  largestRegion = image->GetLargestPossibleRegion().GetSize();

  unsigned int count = 0;
  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
  {
    count = it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0];

    PixelType expected(1);
    expected[0] = ComplexType(count, 0);

    if (!TestCompare(it.GetIndex(), it.Get(), expected))
      return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int otbMonobandScalarToVectorImageComplexFloat(int argc, char* argv[])
{
  return otbMonobandScalarToVectorImageComplexGeneric<float>(argc, argv);
}

int otbMonobandScalarToVectorImageComplexDouble(int argc, char* argv[])
{
  return otbMonobandScalarToVectorImageComplexGeneric<double>(argc, argv);
}

int otbMonobandScalarToVectorImageComplexShort(int argc, char* argv[])
{
  return otbMonobandScalarToVectorImageComplexGeneric<short>(argc, argv);
}

int otbMonobandScalarToVectorImageComplexInt(int argc, char* argv[])
{
  return otbMonobandScalarToVectorImageComplexGeneric<int>(argc, argv);
}

/***********
 * 11.
 * Read MultibandComplex as Image<double>
 * out : ???
 ***********/
template <class InternalType>
int otbMultibandComplexToImageScalarGeneric(int itkNotUsed(argc), char* itkNotUsed(argv)[])
{
  // This case is not handled yet.
  // We need more time to decide what we want to do with this case. ( perhaps return exception ???)
  std::cout << "This case is not handled yet."
            << "Need specification : throw exception ?" << std::endl;
  return EXIT_FAILURE;
}

int otbMultibandComplexToImageScalarFloat(int argc, char* argv[])
{
  return otbMultibandComplexToImageScalarGeneric<float>(argc, argv);
}

int otbMultibandComplexToImageScalarDouble(int argc, char* argv[])
{
  return otbMultibandComplexToImageScalarGeneric<double>(argc, argv);
}

int otbMultibandComplexToImageScalarShort(int argc, char* argv[])
{
  return otbMultibandComplexToImageScalarGeneric<short>(argc, argv);
}

int otbMultibandComplexToImageScalarInt(int argc, char* argv[])
{
  return otbMultibandComplexToImageScalarGeneric<int>(argc, argv);
}