[Insight-users] What is a good image format for ITK?

Stephen R. Aylward aylward at unc . edu
Mon, 26 May 2003 09:17:21 -0400


Thanks for your changes.   I implemented the MetaImageIO changes.   Good 
catch.   The changes have been committed to the cvs version.

The nice part about the IO factory in ITK is that it is relatively easy 
to add new file formats.   If there is a file IO format you like, please 
let us know.

As far as working with what is there for an extensible format - I think 
you have a number of options.   I am biased towards the MetaImage 
format.  This bias is NOT the opinion of the Insight Management - the 
Insight Management doesn't have an opinion/bias. :)  Anyway, MetaImage 
is a tagged format and commands exists to add application-specific tags 
to and read application specific tags from a MetaImage file.   Okay, 
just checked...those commands were left out of this version :(, I will 
add them back in.

In the meantime, I think you will also find it easy to derive from 
metaImage - in the derived class you need only specify two member 
functions: M_SetupReadFields and M_SetupWriteFields - add field records 
to them.   Change itkMetaImageIO.h to use your derived class or create 
your own Code/IO/*.h/cxx file for your derived class.   Your class will 
continue to work as MetaIO is upgraded...

Thanks - sorry for the errors...

Stephen

hhiraki at lab . nig . ac . jp wrote:
> Hi,
> 
> I found 3 ImageIO classes in release 1.2.0 might have bugs:
> 
> 1 itkVTKImageIO produced incorrect ascii format for (unsigned) char.
>   I fixed this by casting each value to int in itkImageIOBase.cxx.
> 
> 2 itkAnalyzeImageIO read unsigned char data as signed.
>   There may be a typo in itkAnalyzeImageIO.cxx.
> 
> 3 itkMetaImageIO disregarded non-zero start index of IORegion.
>   I fixed this by changing the origin position in itkMetaImageIO.cxx.
> 
> I'm not sure my fixes are appropriate. Would you please review the 
> patch attached? 
> 
> 
> By the way, what is a good image format to store intermediate image 
> data? Here "good" means possible to support all concrete image types 
> that the ITK filters treat and hopefully compressable, streamable, 
> and extendable to store some application specific data.
> 
> 
> Many thanks in advance.
> 
> Hideaki Hiraki
> 
> 
> ------------------------------------------------------------------------
> 
> --- Code/IO/itkImageIOBase.cxx~	Thu Feb 27 05:25:53 2003
> +++ Code/IO/itkImageIOBase.cxx	Mon May 26 17:48:38 2003
> @@ -510,6 +510,28 @@
>      }
>  }
>  
> +//specialized version for char
> +static void WriteBuffer(std::ostream& os, const char *buffer, unsigned int num)
> +{
> +  const char *ptr = buffer;
> +  for (unsigned int i=0; i < num; i++)
> +    {
> +    if ( !(i%6) && i ) os << "\n";
> +    os << static_cast<int>(*ptr++) << " ";
> +    }
> +}
> +
> +//specialized version for unsigned char
> +static void WriteBuffer(std::ostream& os, const unsigned char *buffer, unsigned int num)
> +{
> +  const unsigned char *ptr = buffer;
> +  for (unsigned int i=0; i < num; i++)
> +    {
> +    if ( !(i%6) && i ) os << "\n";
> +    os << static_cast<int>(*ptr++) << " ";
> +    }
> +}
> +
>  void ImageIOBase::WriteBufferAsASCII(std::ostream& os, const void *buffer, 
>                                       IODataType ctype, unsigned int numComp)
>  {
> @@ -608,6 +630,30 @@
>    for (unsigned int i=0; i < num; i++, ptr++)
>      {
>      is >> *ptr;
> +    }
> +}
> +
> +//specialized version for char
> +static void ReadBuffer(std::istream& is, char *buffer, unsigned int num)
> +{
> +  char *ptr = buffer;
> +  for (unsigned int i=0; i < num; i++, ptr++)
> +    {
> +    int tmp;
> +    is >> tmp;
> +    *ptr = static_cast<char>(tmp);
> +    }
> +}
> +
> +//specialized version for unsigned char
> +static void ReadBuffer(std::istream& is, unsigned char *buffer, unsigned int num)
> +{
> +  unsigned char *ptr = buffer;
> +  for (unsigned int i=0; i < num; i++, ptr++)
> +    {
> +    int tmp;
> +    is >> tmp;
> +    *ptr = static_cast<unsigned char>(tmp);
>      }
>  }
>  
> --- Code/IO/itkAnalyzeImageIO.cxx~	Fri Feb 28 00:31:07 2003
> +++ Code/IO/itkAnalyzeImageIO.cxx	Mon May 26 12:51:44 2003
> @@ -1073,8 +1073,8 @@
>          m_PixelType = CHAR;
>          break;
>        case ANALYZE_DT_UNSIGNED_CHAR:
> -        m_ComponentType = CHAR;
> -        m_PixelType = CHAR;
> +        m_ComponentType = UCHAR;
> +        m_PixelType = UCHAR;
>          break;
>        case ANALYZE_DT_SIGNED_SHORT:
>          m_ComponentType = SHORT;
> --- Code/IO/itkMetaImageIO.cxx~	Sun Jan 19 13:33:59 2003
> +++ Code/IO/itkMetaImageIO.cxx	Mon May 26 16:07:26 2003
> @@ -333,6 +333,15 @@
>      eSpacing[i] = this->GetSpacing(i);
>      eOrigin[i] = this->GetOrigin(i);
>      } 
> +  ImageIORegion::IndexType index = this->GetIORegion().GetIndex();
> +  for(i=0; i<nDims; i++)
> +    {
> +    if(index[i] != 0)
> +      {
> +      eOrigin[i] = this->GetOrigin(i) + this->GetSpacing(i) * index[i];
> +      itkWarningMacro(<<"The origin was translated for non-zero index of dimension " << i);
> +      }
> +    }
>  
>    m_MetaImage.InitializeEssential(nDims, dSize, eSpacing, eType, nChannels,
>                                    (void *)buffer);


-- 
===========================================================
Dr. Stephen R. Aylward
Associate Professor of Radiology
Adjunct Associate Professor of Computer Science and Surgery
http://caddlab . rad . unc . edu
aylward at unc . edu
(919) 966-9695