[ITK-users] [ITK] why jpg image that is converted from a mhd image is so weird ?

Timothee Evain tevain at telecom-paristech.fr
Wed Jun 7 08:01:38 EDT 2017


Hello,

You can't just "cast" a 3D image into a RGB 2D one. Casting is for type only and cannot be used for dimension, see https://itk.org/Doxygen/html/classitk_1_1CastImageFilter.html
One basic solution would be to initialize an ImageType2D image, then parse the "3D" image along spatial dimensions, filling the rgb pixel of the second image with the values along the color dimension.

HTH,

Tim

----- Mail original -----
De: "XieYi" <xieyi4650 at 126.com>
À: insight-users at itk.org
Envoyé: Mercredi 7 Juin 2017 13:45:00
Objet: [ITK] [ITK-users] why jpg image that is converted from a mhd image	is so	weird ?

the mhd image in ParaView software is like this:
<http://itk-users.7.n7.nabble.com/file/n38307/gt1.png> 
after being converted to jpg image, it is like this 
<http://itk-users.7.n7.nabble.com/file/n38307/drr.jpg> 

here is my converting code:

typedef float PixelType;
const unsigned int Dimension = 3;
typedef itk::Matrix<double, 3, 3> MatrixType;
#ifdef RTK_USE_CUDA
	typedef itk::CudaImage< PixelType, Dimension > ImageType;
#else
	typedef itk::Image< PixelType, Dimension > ImageType;
#endif

typedef  itk::RGBPixel<unsigned char>	PixelType_2D;
#ifdef RTK_USE_CUDA
	typedef itk::CudaImage< PixelType_2D, 2 > ImageType;
#else
	typedef itk::Image<PixelType_2D, 2> ImageType2;
#endif
typedef itk::JPEGImageIO   ImageIOType;
ImageIOType::Pointer jpegIO = ImageIOType::New();

ImageType::Pointer drr1 = [a function get a image]

typedef itk::CastImageFilter <ImageType, ImageType2> ImageCastType;
ImageCastType::Pointer Imagecast = ImageCastType::New();
Imagecast->SetInput(drr1);
Imagecast->Update();
		
jpegIO->SetFileTypeToASCII();
typedef itk::ImageFileWriter<ImageType2> WriterType2;
WriterType2::Pointer writer_jpg = WriterType2::New();
writer_jpg->SetImageIO(jpegIO);
writer_jpg->SetFileName("drr.jpg");
writer_jpg->SetInput(Imagecast->GetOutput());
writer_jpg->Update();



--
View this message in context: http://itk-users.7.n7.nabble.com/why-jpg-image-that-is-converted-from-a-mhd-image-is-so-weird-tp38307.html
Sent from the ITK - Users mailing list archive at Nabble.com.
_____________________________________
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.php

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://public.kitware.com/mailman/listinfo/insight-users
_______________________________________________
Community mailing list
Community at itk.org
http://public.kitware.com/mailman/listinfo/community


More information about the Insight-users mailing list