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

hhiraki@lab.nig.ac.jp hhiraki at lab . nig . ac . jp
Mon, 26 May 2003 19:25:47 +0900


----Next_Part(Mon_May_26_18:59:48_2003_559)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

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

----Next_Part(Mon_May_26_18:59:48_2003_559)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="InsightToolkit-1.2.0.patch"

--- 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);

----Next_Part(Mon_May_26_18:59:48_2003_559)----