[Insight-users] Fast Image Conversion-

Karthik Krishnan karthik.krishnan at kitware.com
Wed Feb 9 00:30:00 EST 2011


Also try importing each of the pieces separately, ie the
importFilter->Update(), connector->Update(). Its hard to tell where in the
pipeline you hang now..

Also, I presume you are doing some processing in ITK. If not, you could use
a vtkImageImport to get this straight into VTK, instead of first converting
to an ITK image, then to a VTK image.

On Tue, Feb 8, 2011 at 7:54 PM, Ryan L. Smith <ryans09 at gmail.com> wrote:

> Hi David-
>
> Thanks for the quick response.  I explored that option, and my software
> compiles although it hangs on execution.  The example has an input as an
> array of unsigned chars, as opposed to my vector. Is this the
> problem?  Additionally, this still uses an itk to vtk connector before
> display.  I am assuming based on your suggestion, the bulk of my time in the
> previous solution was spent looping and setting individual pixels as
> opposed to the itk to vtk filter.  Is this correct? If not, is there a vtk import
> filter that will take my buffer as an input directly? My non-functioning
> code hangs when I try to connect my pipeline to an actor, and it is included
> below:
>
>
> ==================================================================================
>  setupCamera();
> getCamInfo(w,h,d) //get width,height,depth from camera
>  typedef unsigned char PixelType;
> const unsigned int Dimension = 2;
> typedef itk::Image<PixelType,Dimension> ImageType;
> typedef itk::ImageToVTKImageFilter< ImageType > ConnectorType;
> ConnectorType::Pointer connector = ConnectorType::New();
> typedef itk::Image< PixelType, Dimension > ImageType;
> typedef itk::ImportImageFilter< PixelType, Dimension > ImportFilterType;
> ImportFilterType::Pointer importFilter = ImportFilterType::New();
>
> vtkSmartPointer<vtkImageActor> actor =
> vtkSmartPointer<vtkImageActor>::New();
>
> ImportFilterType::SizeType size;
> size[0] = w;
> size[1] = h; // size along Y
>
> ImportFilterType::IndexType start;
> start.Fill( 0 );
>
> ImportFilterType::RegionType region;
> region.SetIndex( start );
> region.SetSize( size );
> importFilter->SetRegion( region );
>
> double origin[ Dimension ];
> origin[0] = 0.0; // X coordinate
> origin[1] = 0.0; // Y coordinate
> importFilter->SetOrigin( origin );
>
> double spacing[ Dimension ];
> spacing[0] = 1.0; // along X direction
> spacing[1] = 1.0; // along Y direction
>
> importFilter->SetSpacing( spacing );
> const int numberOfPixels = size[0] * size[1];
>
> ConnectorType::Pointer connector = ConnectorType::New();
>
>
>
> UINT32_TYPE SizeInBytes = h*w*3*((depth+7)/8);
>
> std::vector<
> unsigned char> ImageData(SizeInBytes);
>
> UINT32_OUT_TYPE pnFrameCount ;
>
> Result = UCC_GetBitmap8ImageEx( CamId, &*ImageData.begin(), pnFrameCount ,
> 6000, NULL ) ;
>
> const bool importImageFilterWillOwnTheBuffer = true;
>
> importFilter->SetImportPointer( &*ImageData.begin(), numberOfPixels,
>
> importImageFilterWillOwnTheBuffer );
>
> connector->SetInput(importFilter->GetOutput());
>
>  actor->SetInput(connector->GetOutput());  // THIS LINE MAKES MY CODE HANG
>
>
> ====================================================================================
>
>
>
> Thanks in advance for your help!
> -Ryan
>
>
>
> On Tue, Feb 8, 2011 at 1:55 PM, David Doria <daviddoria at gmail.com> wrote:
>
>>  On Tue, Feb 8, 2011 at 4:52 PM, Ryan L. Smith <ryans09 at gmail.com> wrote:
>> >
>> > Hi-
>> > I am reading in an image stream in unsigned char vector format from a
>> camera in real-time.  I have some code setup to display the image using
>> VTK/ITK, but the latencies are high.  Is there a method to directly convert
>> this vector to a VTK image?  I am currently looping through and setting the
>> image pixels in an ITK image using the following example:
>> > http://www.vtk.org/Wiki/ITK/Examples/SimpleOperations/SetPixels
>> > I then connect the pipeline using itk::ImageToVTKImageFilter and display
>> the image.  I recognize this is an inefficient way of doing things, but came
>> up blank in looking for an optimized function to do it for me.  Thanks in
>> advance-
>> > -Ryan
>>
>> Have you seen the ImportImageFilter ?
>> http://www.itk.org/Wiki/ITK/Examples/IO/ImportImageFilter
>>
>> David
>>
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110209/a39ebdca/attachment-0001.htm>


More information about the Insight-users mailing list