[Insight-users] How to transform ITK image reader to Qt image type?

Julien Jomier jjomier at cs . unc . edu
Fri, 15 Aug 2003 10:35:54 -0400


Hi Chunyan,

QImage as a setPixel() function and you can use ITK iterators (chapter =
11 of
the SoftwareGuide)

This is an (untested) example to display an unsigned char image.=20

--------

// h and w are the sizes of the image
QImage* myQtImage =3D new QImage(h,w,8,256);

for (unsigned int i=3D0;i<256;i++)
{
  QColor* rgb =3D new QColor(i,i,i);
  myQtImage ->setColor(i,rgb->rgb());
}

typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;
ImageType::Pointer myITKImage =3D reader->GetOutput();
IteratorType
it(myITKImage,myITKImage->GetLargestPossibleRegion().GetSize());

it.GoToBegin();

for (unsigned int i=3D0;i<h;i++)
{
  for (unsigned int j=3D0;j<w;j++)
  {
    myQtImage ->setPixel(i,j,it.Get());
    it++;
  }
}

------

I don't know if this is the most efficient way but it should work.
You may have to modify the code to accept other pixel types than =
unsigned
char.

regards,

Julien

> -----Original Message-----
> From: insight-users-admin at itk . org=20
> [mailto:insight-users-admin at itk . org] On Behalf Of jiang
> Sent: Friday, August 15, 2003 9:24 AM
> To: ITK
> Subject: [Insight-users] How to transform ITK image reader to=20
> Qt image type?
>=20
>=20
> Hi,
> I want to use Qt to produce UI. If I use Qt to load one=20
> image, I will do: image.load(filename, 0); //QImage image
> pm.convertFromImage(image, PreferDither); //QPixmap	pm;
> painter.drawPixmap(0,0,  pm,0,0,-1,-1); //QPainter painter(this);
>=20
> Now I use Qt to load image:
> typedef unsigned short                    PixelType;
> typedef itk::Image<PixelType, 2>          ImageType;
> typedef itk::ImageFileReader<ImageType>   ReaderType;
> reader=3DReaderType::New();
> reader->SetFileName( filename );
> reader->Update();
>=20
> My question is how can I transform from ITK ImageType to Qt=20
> QImage or QPixmap. Thanks a lot.
>=20
>=20
> Chunyan
>=20
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org=20
> http://www . itk . org/mailman/listinfo/insight-> users
>=20