[Insight-users] Help on getting and reading image buffer
Luis Ibanez
luis.ibanez at kitware.com
Mon Aug 28 18:04:14 EDT 2006
Hi Xuejun,
Please look at the code of the fltkSlicer* classes in:
InsightApplications/
Auxiliary/
FltkImageViewer/
fltkSlice2DDrawer.txx line 344
fltkSlice3DDrawer.txx lines 522,611,671
They will show you how to use the gluScaleImage() method
with buffers from ITK images.
Regards,
Luis
----------------------------------
Xuejun wrote:
> Dear all ITK users and developers;
>
>
>
> I am trying to getting the image buffer and input it into a OpenGL
> function gluScaleImage to resize the image. Unfortunately my code does
> not work despite my many times try. The major part of the code is listed
> as follows:
>
>
>
> ……
>
> try
>
> {
>
> reader->Update();
>
> }
>
> catch (itk::ExceptionObject & err)
>
> {
>
> std::cerr << "exception in file reader " <<
> std::endl;
>
> std::cerr << err << std::endl;
>
> return ;
>
> }
>
>
>
> InputImageType::Pointer image = reader->GetOutput() ;
>
> const InputImageType::RegionType ®ion = image->GetBufferedRegion() ;
>
>
>
> // image size
>
> unsigned long lwidth = image->GetBufferedRegion().GetSize()[0] ;
>
> unsigned long lheight = image->GetBufferedRegion().GetSize()[1] ;
>
>
>
> // set up new size
>
> double factor = 0.5 ;
>
> int nNewWidth = (int)lwidth * factor;
>
> int nNewHeight = (int)lheight * factor;
>
> unsigned char rasterNew = new unsigned char [nNewHeight * nNewWidth] ;
>
>
>
> // resize the image buffer
>
> int iscale = gluScaleImage(GL_RGBA, (GLint)lwidth, (GLint)lheight,
> GL_UNSIGNED_BYTE, ®ion, (GLint)nNewWidth, (GLint)nNewHeight,
> GL_UNSIGNED_BYTE, rasterNew ) ;
>
>
>
> But the output of the function iscale=gluScaleImage is 1285. I also
> tried to use InputPixelType *pointer = image->GetBufferPointer();. It
> does not work either.
>
>
>
> My questions are:
>
>
>
> 1. How to get and reading the buffer of the image after reading an
> image file? Is the method in the above code correct?
> 2. What does it mean by the return value 1285 of the OpenGL function
> (I used a DICOM image with unsigned char type and it is
> successfully read by the code)? Is the first item (pixel format) I
> set GL_RGBA correct? and how to fix the problem?
>
>
>
> Your kind help is greatly appreciated.
>
>
>
> Best regards,
>
> Sam
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list