[Insight-users] exception when writing row or column images

Zachary Pincus zpincus at stanford.edu
Sun, 18 Apr 2004 04:40:36 -0700


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