itkToVtkImageFilter: Why is the resulting image upside down?

Hi all, I ran this code 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.

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

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

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);
}
    // Flip camera because VTK-ITK different corner for origin.
    vtkCamera *cam = renderer->GetActiveCamera();
    flip_camera(cam);

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

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.

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

4 Likes

Thanks. This is an incredibly useful answer.