[Insight-users] exception when writing row or column images
Zachary Pincus
zpincus at stanford.edu
Mon, 19 Apr 2004 11:33:42 -0700
Luis,
In general, I have no specific need for one-column images sine in my
case (as, I assume, in most others) they represent erroneous algorithm
output.
I was just wondering if this was a feature or a bug. Given that it is a
feature, a programmatic flag to control it (and the associated
documentation about both the feature and flag) would be nice, but
certainly a very-low-priority item, since I certainly have no specific
need for row- or column-images.
Thanks for your reply, and really for all the time you spend on the
email list,
Zach Pincus
On Apr 19, 2004, at 11:27 AM, Luis Ibanez wrote:
>
> Hi Zach,
>
> This is a safeguard that was introduced on purpose
> in order to prevent the missuse of the writers.
>
> If you are sure that you want to save 1-row images,
> you can simply override this control.
>
>
> For this, just go to:
>
> Insight/Code/IO/
> itkJPEGImageIO.cxx
>
>
> move to line 457 and comment out the three lines:
>
>
> // Make sure the region to be written is 2D
> if ( ioRegion.GetRegionDimension() != 2 )
> {
> itkExceptionMacro(<<"JPEG Writer can only
> write 2-dimensional images");
> }
>
>
>
> What happens is that the method: GetRegionDimension()
> considers that an image should have more than one pixel
> along every dimension. Therefore, dimensions that are
> just one pixel wide, are assumed to be flattened.
>
>
> We could probably set a flag on the file
>
> itkImageIORegion.h
>
> in order to change the limit from "1" to "0".
>
> In this way, images of one pixel along a dimension
> will not considered to be of inferior dimension.
>
>
> Please let us know if this works for you,
> and whether you will find useful to have such
> a flag available or not.
>
>
> Thanks,
>
>
> Luis
>
>
> ----------------------
> Zachary Pincus wrote:
>
>> Hello,
>> A tool that I'm building sometimes segments out an object that is it
>> the far edge of an image, leading me to try to save to disk an image
>> that, while 2D by type, consists of a single row or column. (i.e.
>> that has a degenerate second dimension.)
>> Unfortunately, this does not appear to be possible, and instead
>> generates the exception:
>>> itk::ERROR: JPEGImageIO(0x2101070): JPEG Writer can only write
>>> 2-dimensional images
>> (the same general error appears regardless of which ImageIO you
>> choose.)
>> I'm sure that 1 x n or n x 1 images are valid in most if not all
>> image format specifications.
>> Is this a bug? And if it's been brought up before, I apologize -- I
>> didn't find anything on the mailing list archive.
>> Thanks,
>> Zach Pincus
>> Department of Biochemistry and Program in Biomedical Informatics
>> Stanford University School of Medicine
>> Here is code to reproduce this error:
>> #include "itkImageFileWriter.h"
>> #include "itkImage.h"
>> #include <iostream>
>> const unsigned int Dimension = 2;
>> typedef unsigned short PixelType;
>> typedef itk::Image<PixelType, Dimension> ImageType;
>> typedef itk::ImageFileWriter<ImageType> WriterType;
>> int main(int argc, char *argv[]) {
>> ImageType::Pointer image = ImageType::New();
>> ImageType::IndexType start;
>> start[0] = 0;
>> start[1] = 0;
>> ImageType::SizeType size;
>> size[0] = 2;
>> size[1] = 1;
>> ImageType::RegionType region;
>> region.SetSize( size );
>> region.SetIndex( start );
>> image->SetRegions( region );
>> image->Allocate();
>> std::cout << image << std::endl;
>> WriterType::Pointer writer = WriterType::New();
>> writer->SetFileName("foo.jpg");
>> writer->SetInput(image);
>> try {
>> writer->Update();
>> } catch( itk::ExceptionObject & err ) {
>> std::cout << "ExceptionObject caught !" << std::endl;
>> std::cout << err << std::endl;
>> return -1;
>> }
>> return 0;
>> }
>> Running this code results in this:
>> Image (0x2100420)
>> RTTI typeinfo: N3itk5ImageItLj2EEE
>> Reference Count: 2
>> Modified Time: 4
>> Debug: Off
>> Observers:
>> none
>> Source: (none)
>> Source output index: 0
>> Release Data: Off
>> Data Released: False
>> Global Release Data: Off
>> PipelineMTime: 0
>> UpdateMTime: 0
>> LargestPossibleRegion:
>> Dimension: 2
>> Index: [0, 0]
>> Size: [2, 1]
>> BufferedRegion:
>> Dimension: 2
>> Index: [0, 0]
>> Size: [2, 1]
>> RequestedRegion:
>> Dimension: 2
>> Index: [0, 0]
>> Size: [2, 1]
>> Spacing: [1, 1]
>> Origin: [0, 0]
>> PixelContainer: ImportImageContainer (0x21004f0)
>> RTTI typeinfo: N3itk20ImportImageContainerImtEE
>> Reference Count: 2
>> Modified Time: 5
>> Debug: Off
>> Observers:
>> none
>> Pointer: 0x2100534
>> Container manages memory: true
>> Size: 2
>> Capacity: 2
>> ExceptionObject caught !
>> itk::ExceptionObject (0x2101020)
>> Location: "Unknown"
>> File: /Volumes/Atlotl/Developer/ITK/ITK-CVS-src/Insight/Code/IO/
>> itkJPEGImageIO.cxx
>> Line: 459
>> Description: itk::ERROR: JPEGImageIO(0x2101070): JPEG Writer can only
>> write 2-dimensional images
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at itk.org
>> http://www.itk.org/mailman/listinfo/insight-users
>
>
>