# itkToVtkImageFilter: Why is the resulting image upside down?

**URL:** https://discourse.itk.org/t/itktovtkimagefilter-why-is-the-resulting-image-upside-down/3373
**Category:** Beginner Questions
**Tags:** itkvtkglue
**Created:** [August 9, 2020, 2:14am UTC](https://discourse.itk.org/t/itktovtkimagefilter-why-is-the-resulting-image-upside-down/3373 "2020-08-09T02:14:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![msrepo](https://discourse.itk.org/user_avatar/discourse.itk.org/msrepo/32/2307_2.png) [@msrepo](https://discourse.itk.org/u/msrepo)
#### Post date: [August 9, 2020, 2:14am UTC](https://discourse.itk.org/t/itktovtkimagefilter-why-is-the-resulting-image-upside-down/3373/1 "2020-08-09T02:14:33Z")

</div>

Hi all, I ran [this code](https://itk.org/Doxygen/html/SphinxExamples_2src_2Remote_2WikiExamples_2DisplayITKImage_2Code_8cxx-example.html) which uses itktovtkglue to render an image. I do not understand why the resulting image in the window is upside down(flipped)? Using a QuickView viewer gives the option to revert back but what could be the reason behind image getting flipped? Is it a representation issue?

Thank you.

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.itk.org/u/flaviu2)
#### Post date: [August 10, 2020, 6:13am UTC](https://discourse.itk.org/t/itktovtkimagefilter-why-is-the-resulting-image-upside-down/3373/2 "2020-08-10T06:13:44Z")

</div>

That code should work correctly, did you tried the result with another viewer than QuickView ?

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [August 10, 2020, 8:28am UTC](https://discourse.itk.org/t/itktovtkimagefilter-why-is-the-resulting-image-upside-down/3373/3 "2020-08-10T08:28:44Z")

</div>

The origin in VTK is different than ITK, you have to flip the camera:

```cpp
void flip_camera(vtkCamera *cam) {
    double pos[3];
    double vup[3];
    cam->GetPosition(pos);
    cam->GetViewUp(vup);
    for (unsigned int i = 0; i < 3; ++i) {
        pos[i] = -pos[i];
        vup[i] = -vup[i];
    }
    cam->SetPosition(pos);
    cam->SetViewUp(vup);
}

```

```cpp
    // Flip camera because VTK-ITK different corner for origin.
    vtkCamera *cam = renderer->GetActiveCamera();
    flip_camera(cam);

    renderer->ResetCamera();
    renderWindowInteractor->Initialize();
    renderWindowInteractor->Start();

```

---

<div class="post-metadata">

### Author: ![msrepo](https://discourse.itk.org/user_avatar/discourse.itk.org/msrepo/32/2307_2.png) [@msrepo](https://discourse.itk.org/u/msrepo)
#### Post date: [August 14, 2020, 4:19am UTC](https://discourse.itk.org/t/itktovtkimagefilter-why-is-the-resulting-image-upside-down/3373/4 "2020-08-14T04:19:44Z")

</div>

Thank you for your reply. Would you like to elaborate more? What do you mean the origins are different? Is it that the image plane in behind the camera origin and not in front? Is the camera looking down the positive or negative z-axis? Is the image buffer array have different index orientation?

Thanks.

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [August 14, 2020, 10:02am UTC](https://discourse.itk.org/t/itktovtkimagefilter-why-is-the-resulting-image-upside-down/3373/5 "2020-08-14T10:02:12Z")

</div>

The camera default in VTK treats the Y axis as going down. Hope this Luis Ibañez answer helps:  
[https://itk.org/pipermail/insight-users/2007-September/023504.html](https://itk.org/pipermail/insight-users/2007-September/023504.html)

---

<div class="post-metadata">

### Author: ![msrepo](https://discourse.itk.org/user_avatar/discourse.itk.org/msrepo/32/2307_2.png) [@msrepo](https://discourse.itk.org/u/msrepo)
#### Post date: [August 14, 2020, 11:22am UTC](https://discourse.itk.org/t/itktovtkimagefilter-why-is-the-resulting-image-upside-down/3373/6 "2020-08-14T11:22:31Z")

</div>

Thanks. This is an incredibly useful answer.
