When I load the tiff file, the image is displayed upside down.

I have tested to draw an image by using vtkImageReader2 and vtkImageViewer2.
Strangely, a bitmap file works well but tiff has a problem
When I load the tiff file, the image is displayed upside down.

Original Image:
original.tif (358.8 KB)
VTK:

Could I need any setting for the tiff file?

Could you please advise for me?

Thank you :slight_smile:

My code is:
int main(int argc, char* argv[])
{
std::string path = “original.tif”;
// Read the image
vtkSmartPointer readerFactory =
vtkSmartPointer::New();
vtkSmartPointer reader;
reader.TakeReference(readerFactory->CreateImageReader2(path.c_str()));
reader->SetFileName(path.c_str());
reader->Update();

// Visualize
vtkSmartPointer<vtkImageViewer2> imageViewer =
	vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(reader->GetOutputPort());
imageViewer->GetRenderWindow()->SetSize(500, 500);
imageViewer->GetRenderer()->ResetCamera();

// Set up an interactor that does not respond to mouse events
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
	vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer->GetRenderWindow()->SetInteractor(renderWindowInteractor);
//renderWindowInteractor->SetInteractorStyle(0);
imageViewer->Render();

// Start the event loop
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();

return EXIT_SUCCESS;

}

Hi,

You might want to add a vtkImageFlip filter to your pipeline (between the reader and the viewer of course) - with a call to SetFilteredAxis(1);.

Take a look to https://vtk.org/Wiki/VTK/Examples/Cxx/Images/Flip for an example.

Hope this helps,
Joachim

Hi Joachim.

Thank you for your advise.

I modified the code that if the loaded image file’s extension is TIF, it should be applied to Flip Y.

And It works well.

Thank you :slight_smile:

Best regards,
William Kim