[vtkusers] Readers read image with some kind of reveral?

David Gobbi david.gobbi at gmail.com
Wed Apr 17 12:16:30 EDT 2013


Hmm.  I just checked, and for vtkJPEGReader, FileLowerLeft doesn't do
anything.  In order to get the image into its original orientation (i.e. so
that pixel (0,0) is at the top left of the image) you will have to apply
the vtkImageFlip filter to the image after reading it.

If you are curious, the code in vtkJPEGReader.cxx that flips the image is
this:

  // copy the data into the outPtr
  OT *outPtr2 = outPtr;
  long outSize = cinfo.output_components*(outExt[1] - outExt[0] + 1);
  for (int i = outExt[2]; i <= outExt[3]; ++i)
    {
    memcpy(outPtr2,
           row_pointers[cinfo.output_height - i - 1]
           + outExt[0]*cinfo.output_components,
           outSize);
    outPtr2 += outInc[1];
    }

There is similar image-flipping code in vtkPNGReader and pretty much every
VTK reader that reads a file format that specifies that pixel (0,0) is at
the top left corner.

 - David


On Tue, Apr 16, 2013 at 5:49 PM, ChenDawnWind <cybfly1 at hotmail.com> wrote:

> Thanks.But even if i set up FileLowerLeftOn. The contour still fliped.
> Here are the codes i used, is there any problem?
>
> vtkSmartPointer<vtkJPEGReader> jpegReader =
>  vtkSmartPointer<vtkJPEGReader>::New();
> jpegReader->FileLowerLeftOn();
> jpegReader->SetFilePrefix("C:/Users/DawnWind/Desktop/000/");
>  jpegReader->SetFilePattern("%s%d.jpg");
> jpegReader->SetDataByteOrderToLittleEndian();
> jpegReader->SetDataSpacing(2.0 / 3, 2.0 / 3, 1);
>  jpegReader->SetFileNameSliceSpacing(1);
> jpegReader->SetDataExtent(0, 209, 0, 209, 0, 0);
> jpegReader->Update();
>
>
> The full codes please see the *attachments in*
>
>
> <https://blu175.mail.live.com/mail/17.0.6156.0403/Compose/RteFrameResources.aspx?ch=8824048901591138608&mkt=zh-cn>
>
>    - [image: ????] <https://blu175.mail.live.com/mail/#>
>    - [image: ?????] <https://blu175.mail.live.com/mail/#>
>    - [image: ?????]
>    - Re: [vtkusers] vtkPointWidget set the right position
>    from Chen DawnWind (cybfly1 at hotmail.com)
>
>    Thanks.
>
>
> DawnWind.Chen
> CSU
>
>
> > From: david.gobbi at gmail.com
> > Date: Tue, 16 Apr 2013 15:30:34 -0600
> > To: vtkusers at vtk.org
> > Subject: Re: [vtkusers] Readers read image with some kind of reveral?
>
> >
> > On Tue, Apr 16, 2013 at 10:17 AM, David Doria <daviddoria at gmail.com>
> wrote:
> > > On Tue, Apr 16, 2013 at 11:45 AM, ChenDawnWind <cybfly1 at hotmail.com>
> wrote:
> > >> Hi everyone,
> > >> when i use the reader such as vtkJPEGReader to read one image file(see
> > >> attachment) and extract the contour of
> > >> the img, then read the result output and print the points with OpenCV.
> > >> Then i found the image was not the way it used to be.
> > >> In the attachment the original image is number 1, and the contour
> image is
> > >> number 2.
> > >> It is clear that the image reversal in some way.
> > >> Cause i have to set the point of the contour in the 3D model,
> > >> with this revesal the calculated center of the white target in the the
> > >> original image was not suit the reveral image 2.
> > >> So i wanna know is there any way to avoid this revesal and to read
> file as
> > >> it used to be?
> > >> Thanks!
> > >>
> > >> DawnWind.Chen
> > >> CSU
> > >
> > >
> > > It looks to me like you are just viewing the points from a different
> > > viewpoint. If you want to change the view on the VTK side of things,
> > > check out:
> > > http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/vtkCamera
> > >
> > > for how to position and aim the camera.
> > >
> > > David
> >
> > I don't think this is a camera issue. The vtkJPEGReader does in fact
> > flip the image. In JPEG the first pixel is at the upper left corner
> > of the image, while VTK's 2D coordinate system (the one used for
> > vtkActor2D) has the first pixel at the lower left corner of the
> > renderer. The reader flips the image so that it appears the right way
> > up on the screen when displayed with vtkImageViewer. This flip of
> > course means that the coordinates of any points that you get from
> > contouring the image will be flipped top-to-bottom.
> >
> > For some readers, you can call FileLowerLeftOn() to stop the reader
> > from flipping the image.
> >
> > - David
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130417/412825d9/attachment.htm>


More information about the vtkusers mailing list