[Insight-users] Possible bug in Gipl file not being recognized

Julien Jomier jjomier@cs.unc.edu
Mon, 31 Mar 2003 10:45:27 -0500


Raghavendra,

It appears that the magic number in your gipl is different from what =
it's
expected:
Magic Number: 719555000 (your file)
Magic Number: 4026526128 (other files)

And the CanReadFile() function in the GiplIO class is checking the magic
number.
However, it seems that some programs, like rview, are writing 719555000 =
for
the magic number.
What software did you use to produce this image?

I don't know wich one of these two numbers is the right one; if someone =
has
an answer?

I just checked in a fix in the repository. Now GiplImageIO accepts these =
two
magic numbers.
Thanks for pointing this out.

Julien

> -----Original Message-----
> From: insight-users-admin@public.kitware.com=20
> [mailto:insight-users-admin@public.kitware.com] On Behalf Of=20
> Raghavendra Chandrashekara
> Sent: Monday, March 31, 2003 6:04 AM
> To: Luis Ibanez
> Cc: Insight-users@public.kitware.com; Julien Jomier
> Subject: Re: [Insight-users] Possible bug in Gipl file not=20
> being recognized
>=20
>=20
> Hi Luis,
>=20
> Sorry the for the delay in replying. I've attached the entire=20
> image as=20
> it's quite a small one.
>=20
> Thanks,
>=20
> Raghavendra.
>=20
> Luis Ibanez wrote:
> > Hi Raghavendra,
> >=20
> > The ramp.gipl file was added to Testing after the 1.2=20
> release. You can=20
> > get it through CVS at:=20
> >=20
> http://www.itk.org/cgi-bin/cvsweb.cgi/Insight/Testing/Data/Baseline/IO
> > /?cvsroot=3DInsight
> >=20
> >=20
> > ---
> >=20
> > Your test shows that your Gipl file is ok.
> >=20
> > What seems to be failing is the testing criteria of the GIPL reader=20
> > for recognizing your file as a gipl-file.
> >=20
> > Could you please post the header (just the header, not the data) of=20
> > your GIPL file. It should have an extra field, or a missing=20
> field that=20
> > is making the GiplImageIO reject the file.
> >=20
> > You can also check the GiplImageIO.cxx file in Insight/Code/IO and=20
> > verify the revision criteria in the method "CanReadFile()".
> >=20
> >=20
> >=20
> > Thanks
> >=20
> >=20
> > Luis
> >=20
> >=20
> >=20
> > ----------------------------------------
> >=20
> > Raghavendra Chandrashekara wrote:
> >=20
> >> Just to be on the safe side I cleaned our copy of the ITK=20
> repository,=20
> >> updated it again, and built everything from scratch. Unfortunately=20
> >> the ramp.gipl image doesn't seem to be there anymore so I couldn't=20
> >> check the program with the test image. Has the image been removed=20
> >> from the Release-1-2-0 branch?
> >>
> >> Here's the code that I am using:
> >>
> >> #include <iostream>
> >> #include <iomanip>
> >>
> >> #include "itkImage.h"
> >> #include "itkImageFileReader.h"
> >> #include "itkGiplImageIO.h"
> >> #include "itkImageFileWriter.h"
> >>
> >> /* Program reads a GIPL image and writes it out again. */ int=20
> >> main(int argc, char** argv) {
> >>   if (argc !=3D 3) {
> >>     std::cout << std::setiosflags(std::ios::left) <<=20
> "GIPLIOTest reads an
> >> input image file and writes it out again." << std::endl
> >>        << std::endl
> >>        << "Usage: GIPLIOTest input.gipl output.gipl" << std::endl
> >>        << std::endl
> >>        << "Where:" << std::endl
> >>        << std::endl
> >>        << std::setw(30) << "input.gipl" << std::setw(50)=20
> << "is the input
> >> image" << std::endl
> >>        << std::setw(30) << "output.gipl" << std::setw(50)=20
> << "is the=20
> >> output
> >> filename" << std::endl;
> >>     exit(1);
> >>   }
> >>
> >>   typedef short PixelType;
> >>   typedef itk::Image<PixelType, 3> ImageType;
> >>   typedef itk::ImageFileReader<ImageType> ReaderType;
> >>   typedef itk::ImageFileWriter<ImageType> WriterType;
> >>   itk::GiplImageIO::Pointer pGiplImageIO =3D =
itk::GiplImageIO::New();
> >>
> >>   try {
> >>     ReaderType::Pointer pReader =3D ReaderType::New();
> >>     WriterType::Pointer pWriter =3D WriterType::New();
> >>
> >>     //    pReader->SetImageIO(pGiplImageIO);
> >>
> >>     pReader->SetFileName(argv[1]);
> >>     pWriter->SetFileName(argv[2]);
> >>
> >>     pWriter->SetInput(pReader->GetOutput());
> >>
> >>     pWriter->Update();
> >>   }
> >>   catch (itk::ExceptionObject& ex) {
> >>     std::cout << "Exception object caught!" << std::endl;
> >>     std::cout << ex << std::endl;
> >>     exit(1);
> >>   }
> >>
> >>   return 0;
> >> }
> >>
> >> When I uncomment out the line that sets the GIPL IO object then
> >> everything
> >> works fine! So it looks like the image that I am using is alright.
> >>
> >> Thanks,
> >>
> >> Raghavendra
> >>
> >> ----- Original Message -----
> >> From: "Luis Ibanez" <luis.ibanez@kitware.com>
> >> To: "Raghavendra Chandrashekara" <rc3@doc.ic.ac.uk>
> >> Cc: <Insight-users@public.kitware.com>
> >> Sent: Friday, March 28, 2003 1:28 PM
> >> Subject: Re: [Insight-users] Possible bug in itkAnalyzeImageIO? :=20
> >> Gipl
> >> not
> >> being found
> >>
> >>
> >>
> >>> Hi Raghavendra,
> >>>
> >>> Yeap, the code looks right.
> >>>
> >>> 1) Could you post the piece of code you are using for
> >>>    reading the gipl file ?
> >>>
> >>> 2)  Could you try reading the gipl test file
> >>>     that is available in
> >>>
> >>>        Insight/Testing/Data/Baseline/IO
> >>>
> >>>     the file name is
> >>>
> >>>               ramp.gipl
> >>>
> >>> If this test file works, this may mean that there
> >>> is something particular in your gipl file that
> >>> prevents the reader from recognizing the format.
> >>>
> >>> Note that checking the extension .gipl is only the
> >>> initial part of the test. Readers verify the content
> >>> of the file in order to make sure they are capable
> >>> of processing the file.
> >>>
> >>>
> >>> Thanks
> >>>
> >>>   Luis
> >>>
> >>>
> >>> --------------------------
> >>>
> >>> Raghavendra Chandrashekara wrote:
> >>>
> >>>> Hi Luis,
> >>>>
> >>>> There is a line registering the GiplImageIOFactory but it is on=20
> >>>> line
> >>>> 98,
> >>>> this is the code:
> >>>>
> >>>> void
> >>>> ImageIOFactory::RegisterBuiltInFactories()
> >>>> {
> >>>>  static bool firstTime =3D true;
> >>>>
> >>>>  static SimpleMutexLock mutex;
> >>>>  {
> >>>>    // This helper class makes sure the Mutex is unlocked
> >>>>    // in the event an exception is thrown.
> >>>>    MutexLockHolder<SimpleMutexLock> mutexHolder( mutex );
> >>>>    if( firstTime )
> >>>>      {
> >>>>      ObjectFactoryBase::RegisterFactory(=20
> DicomImageIOFactory::New() );
> >>>>      ObjectFactoryBase::RegisterFactory(=20
> MetaImageIOFactory::New() );
> >>>>      ObjectFactoryBase::RegisterFactory(=20
> PNGImageIOFactory::New() );
> >>>>      ObjectFactoryBase::RegisterFactory(=20
> VTKImageIOFactory::New() );
> >>>>      ObjectFactoryBase::RegisterFactory(=20
> GiplImageIOFactory::New() );
> >>>>      ObjectFactoryBase::RegisterFactory(=20
> AnalyzeImageIOFactory::New());
> >>>>      firstTime =3D false;
> >>>>      }
> >>>>  }
> >>>>
> >>>> }
> >>>>
> >>>> Does it look correct to you? I'm using Release-1-2-0 also.
> >>>>
> >>>> Thanks,
> >>>>
> >>>> Raghavendra.
> >>>>
> >>>> ----- Original Message -----
> >>>> From: "Luis Ibanez" <luis.ibanez@kitware.com>
> >>>> To: "Raghavendra Chandrashekara" <rc3@doc.ic.ac.uk>
> >>>> Cc: <insight-users@public.kitware.com>
> >>>> Sent: Friday, March 28, 2003 12:31 PM
> >>>> Subject: Re: [Insight-users] Possible bug in=20
> itkAnalyzeImageIO? :=20
> >>>> Gipl
> >>>
> >>>
> >> not
> >>
> >>>> being found
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>> Hi Raghavendra,
> >>>>>
> >>>>> It looks like the GiplImageIO factory
> >>>>> is not being found.
> >>>>>
> >>>>> Could you please double check the file
> >>>>>
> >>>>> Insight/Code/IO
> >>>>>
> >>>>>  itkImageIOFactory.cxx
> >>>>>
> >>>>> and see if in line 99, the following
> >>>>> line is not commented out :
> >>>>>
> >>>>>
> >>>>> ObjectFactoryBase::RegisterFactory( GiplImageIOFactory::New() );
> >>>>>
> >>>>>
> >>>>> This lines registers the Gipl reader/writer
> >>>>> in the factory mechanism.
> >>>>>
> >>>>> (I'm assuming you are using ITK version 1.2)
> >>>>>
> >>>>>
> >>>>>
> >>>>> Regards,
> >>>>>
> >>>>>
> >>>>>
> >>>>> Luis
> >>>>>
> >>>>>
> >>>>> ---------------------------------------------
> >>>>> Raghavendra Chandrashekara wrote:
> >>>>>
> >>>>>
> >>>>>> Hi Kent,
> >>>>>>
> >>>>>> Okay I tried the patch that you sent. Now another exception is
> >>>>>> thrown,
> >>>>>
> >>>>>
> >>>> this
> >>>>
> >>>>
> >>>>>> time by the itkImageFileReader class:
> >>>>>>
> >>>>>> Exception object caught!
> >>>>>>
> >>>>>> itk::ImageFileReaderException (0x815ace8)
> >>>>>> Location: "Unknown"
> >>>>>> File:=20
> >>>>>> /vol/vipdata/packages/InsightCVS/Code/IO/itkImageFileReader.txx
> >>>>>> Line: 94
> >>>>>> Description:  Could not create IO object for file
> >>>>>> ../../Data/Synthetic/cube.gipl
> >>>>>>
> >>>>>> Does this mean that the gipl image is not being=20
> recognised by any=20
> >>>>>> of
> >>>>>
> >>>>>
> >> the
> >>
> >>>> IO
> >>>>
> >>>>
> >>>>>> classes?
> >>>>>>
> >>>>>> Raghavendra.
> >>>>>>
> >>>>>> ----- Original Message -----
> >>>>>> From: "Kent Williams" <kent@mail.psychiatry.uiowa.edu>
> >>>>>> To: "Raghavendra Chandrashekara" <rc3@doc.ic.ac.uk>
> >>>>>> Sent: Wednesday, March 19, 2003 6:46 PM
> >>>>>> Subject: Re: [Insight-users] Possible bug in itkAnalyzeImageIO?
> >>>>>>
> >>>>>>
> >>>>>> I don't know why you're getting that far into CanRead,=20
> since the=20
> >>>>>> 1.2
> >>>>>
> >>>>>
> >>>> version
> >>>>
> >>>>
> >>>>>> of itkAnalyzeImageIO.cxx checks for valid extensions=20
> first before
> >>>>>
> >>>>>
> >> trying
> >>
> >>>> to
> >>>>
> >>>>
> >>>>>> open the file.
> >>>>>>
> >>>>>> I think that it's incorrect to throw an exception in CanRead
> >>>>>> anyway; my
> >>>>>> suggestion to  you is to patch around line 1000 in=20
> that file thusly:
> >>>>>>
> >>>>>> CHANGE:
> >>>>>>   if( local_InputStream.fail() )
> >>>>>>     {
> >>>>>>       ExceptionObject exception(__FILE__, __LINE__);
> >>>>>>       exception.SetDescription("File cannot be read");
> >>>>>>       throw exception;
> >>>>>>     }
> >>>>>>   local_InputStream.read( (char *)&(this->m_hdr), sizeof(struct
> >>>>>
> >>>>>
> >>>> dsr) );
> >>>>
> >>>>
> >>>>>>   if( local_InputStream.eof() )
> >>>>>>     {
> >>>>>>       ExceptionObject exception(__FILE__, __LINE__);
> >>>>>>       exception.SetDescription("Unexpected end of file");
> >>>>>>       throw exception;
> >>>>>>     }
> >>>>>> TO:
> >>>>>>   if( local_InputStream.fail() )
> >>>>>>     {
> >>>>>> return false;
> >>>>>>     }
> >>>>>>   local_InputStream.read( (char *)&(this->m_hdr), sizeof(struct
> >>>>>
> >>>>>
> >>>> dsr) );
> >>>>
> >>>>
> >>>>>>   if( local_InputStream.eof() )
> >>>>>>     {
> >>>>>> return false;
> >>>>>>     }
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> _______________________________________________
> >>>>>> Insight-users mailing list Insight-users@public.kitware.com
> >>>>>> http://public.kitware.com/mailman/listinfo/insight-users
> >>>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> _______________________________________________
> >>>>> Insight-users mailing list Insight-users@public.kitware.com
> >>>>> http://public.kitware.com/mailman/listinfo/insight-users
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >>> _______________________________________________
> >>> Insight-users mailing list
> >>> Insight-users@public.kitware.com=20
> >>> http://public.kitware.com/mailman/listinfo/insight-users
> >>>
> >>
> >>
> >> _______________________________________________
> >> Insight-users mailing list
> >> Insight-users@public.kitware.com=20
> >> http://public.kitware.com/mailman/listinfo/insight-users
> >>
> >=20
> >=20
> >=20
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users@public.kitware.com=20
> > http://public.kitware.com/mailman/listinfo/insight-users
>=20
>=20