[Insight-users] JPEG files IO problem

Fucang Jia jiafucang at hotmail . com
Tue, 25 Nov 2003 00:27:35 +0800


Hi, everyone,

When I use multiple file to read or write, and the image format is JPEG, the 
program throw an exception when it handles about 509 files. I think this is 
because the itkJPEGImageIO.cxx does not
close the FILE pointer fp. When I use "fcloseall();" in the program , the 
problem does not occur.

ExceptionObject caught !

itk::ExceptionObject (00E8F7AC)
Location: "Unknown"
File: H:\cvs_11_20\Insight\Code\IO\itkJPEGImageIO.cxx
Line: 522
Description: itk::ERROR: JPEGImageIO(0027D290): Error JPEGImageIO could not 
open file: roi_0508.jpg


Thank you!

Fucang

==========================

The demo program is as follows:

#include "itkRGBPixel.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkJPEGImageIO.h"
#include "itkExtractImageFilter.h"
#include "itkImage.h"

int main( int argc, char ** argv )
{

	typedef itk::RGBPixel<unsigned char>           PixelType;

	const   unsigned int        Dimension = 2;

	typedef itk::Image< PixelType, Dimension >     ImageType;
	typedef itk::Image< PixelType, Dimension >     ImageType;
	typedef itk::ImageFileReader< ImageType  >     ReaderType;
	typedef itk::ImageFileWriter< ImageType >      WriterType;

	ReaderType::Pointer reader = ReaderType::New();
	WriterType::Pointer writer = WriterType::New();

	typedef itk::ExtractImageFilter< ImageType, ImageType > FilterType;

	FilterType::Pointer filter = FilterType::New();

	ImageType::IndexType  start;
	ImageType::SizeType   size;
	ImageType::RegionType wantedRegion;

	start[0] = 10;
	start[1] = 10;
	size[0]  = 50;
	size[1]  = 50;

	wantedRegion.SetSize(  size  );
	wantedRegion.SetIndex( start );
	filter->SetExtractionRegion( wantedRegion );

	char intputFileName[256];
	char outputFileName[256];

	for(int i=0;i<1024;i++)
	{

		sprintf(intputFileName,"org_%04d.jpg",i);
		sprintf(outputFileName,"roi_%04d.jpg",i);

		reader->SetFileName( intputFileName );
		writer->SetFileName( outputFileName );
		filter->SetInput( reader->GetOutput() );
		writer->SetInput( filter->GetOutput() );

		try
		{
			writer->Update();
		}
		catch( itk::ExceptionObject & err )
		{
			std::cout << "ExceptionObject caught !" << std::endl;
			std::cout << err << std::endl;
			return -1;
		}


		//fcloseall();

	}


	return 0;
}

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join . msn . com/?page=features/virus