# Vertical flip with the vtkImageData

**URL:** https://discourse.vtk.org/t/vertical-flip-with-the-vtkimagedata/4818
**Category:** Support
**Created:** [December 14, 2020, 10:22am UTC](https://discourse.vtk.org/t/vertical-flip-with-the-vtkimagedata/4818 "2020-12-14T10:22:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Kim\_William](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kim_william/32/373_2.png) [@Kim\_William](https://discourse.vtk.org/u/Kim_William)
#### Post date: [December 14, 2020, 10:22am UTC](https://discourse.vtk.org/t/vertical-flip-with-the-vtkimagedata/4818/1 "2020-12-14T10:22:30Z")

</div>

Hi all.

I have a question about vertical flip with the vtkImageData.

I would like to display the image buffer received from the camera on the vtkImageViewer2.

By referring to some example code, I made a sample code and it works well when it loads an image from the file.  
[https://lorensen.github.io/VTKExamples/site/Cxx/Images/StaticImage/](https://lorensen.github.io/VTKExamples/site/Cxx/Images/StaticImage/)  
[https://lorensen.github.io/VTKExamples/site/Cxx/IO/PNGReader/](https://lorensen.github.io/VTKExamples/site/Cxx/IO/PNGReader/)

But when I load the image from the camera buffer it flips the image vertically.  
My code:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/c/c83271d484365838e89381d3c09078a9a7d101b3.jpeg)  
Original file:  
[Bubbles.bmp](https://discourse.vtk.org/uploads/short-url/gYQJbsgIzYq68PjOfe20I9DV3Wq.bmp) (257.1 KB)

And I referred to the sample code and I got an error.  
[https://lorensen.github.io/VTKExamples/site/Cxx/Images/Flip/](https://lorensen.github.io/VTKExamples/site/Cxx/Images/Flip/)

Is there any way to flip an image vertically with the vtkImageData?

Thank you.

Best regards,  
William

---

<div class="post-metadata">

### Author: ![Kim\_William](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kim_william/32/373_2.png) [@Kim\_William](https://discourse.vtk.org/u/Kim_William)
#### Post date: [December 15, 2020, 3:40am UTC](https://discourse.vtk.org/t/vertical-flip-with-the-vtkimagedata/4818/2 "2020-12-15T03:40:23Z")

</div>

I solved this issue by modifying the code as below:

> vtkNew flipYFilter;  
> flipYFilter-\>SetFilteredAxis(1);  
> flipYFilter-\>SetInputData(imageData);
> 
> vtkNew castYFilter;  
> castYFilter-\>SetOutputScalarTypeToUnsignedChar();  
> castYFilter-\>SetInputConnection(flipYFilter-\>GetOutputPort());
> 
> m\_imageViewer-\>SetInputConnection(castYFilter-\>GetOutputPort());  
> m\_imageViewer-\>GetRenderer()-\>ResetCamera();  
> m\_imageViewer-\>GetRenderWindow()-\>Render();
