[vtkusers] Extract a slice and save it as jpg/png

Jothy jothybasu at gmail.com
Wed Jul 14 11:01:42 EDT 2010


Have you checked that your setVOi is with the bounds of the Image. What are
your bounds?

Jothy

On Wed, Jul 14, 2010 at 3:58 PM, Chris Turner <cturnercomplex at googlemail.com
> wrote:

> No didn't do the trick either.
>
> No file, no error/warning message.
>
> Thanks though!
>
> On Wed, Jul 14, 2010 at 10:54 AM, Jothy <jothybasu at gmail.com> wrote:
> > Try SetVOI(0,0,0,79,1,146)
> >
> > Jothy
> >
> > On Wed, Jul 14, 2010 at 3:44 PM, Chris Turner
> > <cturnercomplex at googlemail.com> wrote:
> >>
> >> Hi David & Bill,
> >>
> >> thanks for your patience and your help I appreciate it a lot!  So this
> >> is the code with David's suggestion:
> >>
> >> import os
> >> import vtk
> >> import sys
> >>
> >>
> >> reader=vtk.vtkImageReader()
> >> reader.SetFileName("/tmp/lungROI.vtk")
> >> reader.Update()
> >>
> >> lut=vtk.vtkLookupTable()
> >> lut.SetRange(-1024, +4095)
> >>
> >> map=vtk.vtkImageMapToColors()
> >> map.SetInput(reader.GetOutput())
> >> map.SetLookupTable(lut)
> >>
> >>
> >> voi=vtk.vtkExtractVOI()
> >> voi.SetInput(map.GetOutput())
> >> voi.SetVOI(0,0,0,79,146,1)
> >> voi.Update()
> >>
> >> writerp=vtk.vtkPNGWriter()
> >> writerp.SetInput(voi.GetOutput())
> >> writerp.SetFileName("/tmp/out.png")
> >> writerp.Write()
> >>
> >> print "done"
> >>
> >>
> >> .... but still no output nor an error message. You can take a look at
> >> the Image here:
> >>
> >> http://www.load.to/t8MWurwasf/lungROI.vtk (~10mb)
> >>
> >> Thanks Again,
> >> Chris
> >>
> >>
> >> On Tue, Jul 13, 2010 at 4:38 PM, David Gobbi <david.gobbi at gmail.com>
> >> wrote:
> >> > Hi Chris,
> >> >
> >> > This could be an instance of trying to write 16-bit data to a JPEG
> >> > file.  Try adding vtkImageMapToColors with a suitable vtkLookupTable.
> >> >  The Range of the lookup table will have to be set to something
> >> > reasonable for the image, a range of (-1024, +4095) is a good place to
> >> > start and then you can increase or decrease the range in order to get
> >> > the contrast right.
> >> >
> >> >   David
> >> >
> >> >
> >> > On Tue, Jul 13, 2010 at 2:15 PM, Bill Lorensen <
> bill.lorensen at gmail.com>
> >> > wrote:
> >> >> Post you entire example. And, if you can post a link to your data...
> >> >>
> >> >> On Tue, Jul 13, 2010 at 3:57 PM, Chris Turner
> >> >> <cturnercomplex at googlemail.com> wrote:
> >> >>> Hi Bill,
> >> >>>
> >> >>> thanks for your answer! But didn't do the trick.
> >> >>> So strange I thought this was a standard question and procedure. And
> >> >>> that there has to be a easy way to do that.
> >> >>>
> >> >>> And why don't I even get a error message or something. Even when I
> >> >>> turn on the debug mode there is nothing suspicious.
> >> >>>
> >> >>> Anybody has another approach?
> >> >>>
> >> >>> Thanks
> >> >>> Chris
> >> >>>
> >> >>> On Mon, Jul 12, 2010 at 10:16 AM, Bill Lorensen
> >> >>> <bill.lorensen at gmail.com> wrote:
> >> >>>> Try,
> >> >>>> voi.SetVOI(0,0,0,511,511,0)
> >> >>>>
> >> >>>> On Mon, Jul 12, 2010 at 10:07 AM, Chris Turner
> >> >>>> <cturnercomplex at googlemail.com> wrote:
> >> >>>>> Really? Am I the only one with that problem?
> >> >>>>>
> >> >>>>> On Fri, Jul 9, 2010 at 5:02 PM, Chris Turner
> >> >>>>> <cturnercomplex at googlemail.com> wrote:
> >> >>>>>> Hi Everyone!
> >> >>>>>>
> >> >>>>>> I'm trying to extract a slice from a vtkImageData object and save
> >> >>>>>> it as picture.
> >> >>>>>>
> >> >>>>>> That's how I do it:
> >> >>>>>>
> >> >>>>>> voi=vtkExtractVOI()
> >> >>>>>> voi.SetInput(imageData)
> >> >>>>>> voi.SetVOI(0,0,0,512,512,1)
> >> >>>>>> voi.Update()
> >> >>>>>>
> >> >>>>>> writer=vtkJPEGWriter()
> >> >>>>>> writer.SetInput(voi.GetOutput())
> >> >>>>>> writer.SetFileName("slice.jpg")
> >> >>>>>> writer.Write()
> >> >>>>>>
> >> >>>>>> ImageData is 512x512x40 spacing 1,1,1
> >> >>>>>>
> >> >>>>>> The strange thing is I don't get an output nor an error message.
> So
> >> >>>>>> I
> >> >>>>>> think I'm missing something here.... but it can't figure out
> what.
> >> >>>>>>
> >> >>>>>> So does anybody have an idea or a better solution?
> >> >>>>>>
> >> >>>>>> Thanks
> >> >>>>>> Chris
> >> >>>>>>
> >> >>>>> _______________________________________________
> >> >>>>> Powered by www.kitware.com
> >> >>>>>
> >> >>>>> Visit other Kitware open-source projects at
> >> >>>>> http://www.kitware.com/opensource/opensource.html
> >> >>>>>
> >> >>>>> Please keep messages on-topic and check the VTK FAQ at:
> >> >>>>> http://www.vtk.org/Wiki/VTK_FAQ
> >> >>>>>
> >> >>>>> Follow this link to subscribe/unsubscribe:
> >> >>>>> http://www.vtk.org/mailman/listinfo/vtkusers
> >> >>>>>
> >> >>>>
> >> >>>
> >> >> _______________________________________________
> >> >> Powered by www.kitware.com
> >> >>
> >> >> Visit other Kitware open-source projects at
> >> >> http://www.kitware.com/opensource/opensource.html
> >> >>
> >> >> Please keep messages on-topic and check the VTK FAQ at:
> >> >> http://www.vtk.org/Wiki/VTK_FAQ
> >> >>
> >> >> Follow this link to subscribe/unsubscribe:
> >> >> http://www.vtk.org/mailman/listinfo/vtkusers
> >> >>
> >> >
> >> _______________________________________________
> >> Powered by www.kitware.com
> >>
> >> Visit other Kitware open-source projects at
> >> http://www.kitware.com/opensource/opensource.html
> >>
> >> Please keep messages on-topic and check the VTK FAQ at:
> >> http://www.vtk.org/Wiki/VTK_FAQ
> >>
> >> Follow this link to subscribe/unsubscribe:
> >> http://www.vtk.org/mailman/listinfo/vtkusers
> >
> >
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100714/38e0f85c/attachment.htm>


More information about the vtkusers mailing list