Discussion:
[ITK-users] why jpg image that is converted from a mhd image is so weird ?
XieYi
2017-06-07 11:45:00 UTC
Permalink
the mhd image in ParaView software is like this:
<Loading Image...>
after being converted to jpg image, it is like this
<Loading Image...>

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
Timothee Evain
2017-06-07 12:01:38 UTC
Permalink
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" <***@126.com>
À: insight-***@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
***@itk.org
http://public.kitware.com/mailman/listinfo/community
_____________________________________
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/mai
XieYi
2017-06-07 12:57:18 UTC
Permalink
Thank you very much Tim
There is one point not clear in my topic. The point is that the dimension of
image is 3, but infact it is a slice, i.e. it is a 2D image but store in a
3D image type. its size is 512x512x1

there are two strange things:
1, some ImageType can be cast into a 2D jpg image, and have no accident.
2, when I define the density ImageType as
typedef itk::RGBPixel<unsigned short> PixelType_2D;
typedef itk::CudaImage< PixelType_2D, 2 > ImageType2;
typedef itk::PNGImageIO ImageIOType;
the xxxxx.png look like normal.



--
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-tp38307p38309.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
Timothee Evain
2017-06-07 13:18:06 UTC
Permalink
Ok, I don't see the advantage of storing a slice as a 3D image since it confuses the code quite a bit, but I guess you have some good reasons.
Same thing for the cast, even if it works, that is really not a standard way of doing it, and could be tricky in the long term.

About the png being normal: Jpeg is a compressed format with loss, that could impact the aspect. But if the image appears normal it is probably because you switched to unsigned short instead of unsigned char, and your original image intensity range overflowed the char one, giving false values.

HTH,

Tim

----- Mail original -----
De: "XieYi" <***@126.com>
À: insight-***@itk.org
Envoyé: Mercredi 7 Juin 2017 14:57:18
Objet: Re: [ITK] [ITK-users] why jpg image that is converted from a mhd image is so weird ?

Thank you very much Tim
There is one point not clear in my topic. The point is that the dimension of
image is 3, but infact it is a slice, i.e. it is a 2D image but store in a
3D image type. its size is 512x512x1

there are two strange things:
1, some ImageType can be cast into a 2D jpg image, and have no accident.
2, when I define the density ImageType as
typedef itk::RGBPixel<unsigned short> PixelType_2D;
typedef itk::CudaImage< PixelType_2D, 2 > ImageType2;
typedef itk::PNGImageIO ImageIOType;
the xxxxx.png look like normal.



--
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-tp38307p38309.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
***@itk.org
http://public.kitware.com/mailman/listinfo/community
_____________________________________
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://p

Loading...