[Insight-users] Computing image spacing?

Luis Ibanez luis.ibanez at kitware.com
Thu Nov 26 14:19:26 EST 2009


Hi Motes,

The image spacing is independent of the image size,
and it is independent of the image pixel intensities.

If the spacing values look suspicious, you may want
to check the size of the equivalent anatomical structures
inside of the image.   For example, if this is a brain scan,
you can verify that the brain shouldn't be larger than
25cm ~ 30cm from front to back.


  Regards,


      Luis

----------------------------------------------------------------------------
On Thu, Nov 26, 2009 at 1:38 PM, motes motes <mort.motes at gmail.com> wrote:
> Ok I was just wondering about this since I got the following values
> after reading a 3D volume:
>
> InitGrid: imageSize = [127, 92, 86]
> InitGrid: imageF->GetOrigin() = [0, 0, 0]
> InitGrid: imageF->GetSpacing() = [3.125, 3.125, 4]
>
> I understand the first two but the spacing seems to be rather
> arbitrary, I have done nothing else than reading the volume from disk
> using the itk image readers.
>
> My first thought was that the spacing was somehow dependent on the
> dimension of the volume, but I could not find anything to back this
> theory up. I also thought it might have something to do with the
> distribution of intensities in the volume, but again no info on this
> either.
>
>
>
>
>
>
> On Thu, Nov 26, 2009 at 7:13 PM, Luis Ibanez <luis.ibanez at kitware.com> wrote:
>> Hi Motes,
>>
>> The Magic is in
>>
>>     Insight/Code/IO/itkImageIOBase.cxx
>>
>> in the method:
>>
>> void ImageIOBase::SetSpacing(unsigned int i, double spacing)
>>
>> although... the magic is not that special.
>>
>> The values are simply stored in the output image.
>>
>> There is really not much to compute for the image spacing
>> when you are reading data from a file. You simply get this
>> from the file format and pass it to the image using the
>> SetSpacing() method above.
>>
>> See the use of the SetSpacing() methods in any of the files:
>>
>> Insight/Code/IO/
>>
>> itkAnalyzeImageIO.cxx:924:
>> this->SetSpacing(dim,this->m_Hdr.dime.pixdim[dim+1]);
>> itkDICOMImageIO2.cxx:168:    this->SetSpacing(i, imageSpacing[i]);
>> itkGDCMImageIO.cxx:1981:  image.SetSpacing(0, m_Spacing[0] );
>> itkGDCMImageIO.cxx:1982:  image.SetSpacing(1, m_Spacing[1] );
>> itkGDCMImageIO.cxx:1983:  image.SetSpacing(2, m_Spacing[2] );
>> itkGE5ImageIO.cxx:532:    this->SetSpacing(2, distanceBetweenTwoSlices);
>> itkImageFileReader.txx:228:  output->SetSpacing( spacing );     // Set
>> the image spacing
>> itkImageFileWriter.txx:197:    m_ImageIO->SetSpacing(i,spacing[i]);
>> itkImageIOBase.cxx:132:void ImageIOBase::SetSpacing(unsigned int i,
>> double spacing)
>> itkImageIOBase.cxx:573:      this->SetSpacing(i, 1.0);
>> itkImageIOBase.h:115:   * SetSpacing() method is required when writing
>> the image. */
>> itkImageIOBase.h:116:  virtual void SetSpacing(unsigned int i, double spacing);
>> itkImageSeriesReader.txx:257:  output->SetSpacing( spacing );   // Set
>> the image spacing
>> itkImageSeriesWriter.txx:251:  outputImage->SetSpacing( spacing );
>> itkIPLCommonImageIO.cxx:367:  this->SetSpacing(0, m_ImageHeader->imageXres);
>> itkIPLCommonImageIO.cxx:368:  this->SetSpacing(1, m_ImageHeader->imageYres);
>> itkIPLCommonImageIO.cxx:369:  this->SetSpacing(2,
>> m_ImageHeader->sliceThickness + m_ImageHeader->sliceGap);
>> itkMetaImageIO.cxx:379:    this->SetSpacing(i,
>> m_MetaImage.ElementSpacing(i)*m_SubSamplingFactor);
>> itkNiftiImageIO.cxx:1187:      this->SetSpacing(6,this->m_NiftiImage->dw);
>> itkNiftiImageIO.cxx:1191:      this->SetSpacing(5,this->m_NiftiImage->dv);
>> itkNiftiImageIO.cxx:1195:      this->SetSpacing(4,this->m_NiftiImage->du);
>> itkNiftiImageIO.cxx:1198:
>> this->SetSpacing(3,this->m_NiftiImage->dt*timingscale);
>> itkNiftiImageIO.cxx:1201:
>> this->SetSpacing(2,this->m_NiftiImage->dz*spacingscale);
>> itkNiftiImageIO.cxx:1204:
>> this->SetSpacing(1,this->m_NiftiImage->dy*spacingscale);
>> itkNiftiImageIO.cxx:1207:
>> this->SetSpacing(0,this->m_NiftiImage->dx*spacingscale);
>> itkNrrdImageIO.cxx:437:        // this->SetSpacing(axii, 1.0);
>> itkNrrdImageIO.cxx:440:        this->SetSpacing(axii, spacing);
>> itkNrrdImageIO.cxx:467:          this->SetSpacing(axii, spacing);
>>
>>
>>
>>
>>    Regards,
>>
>>
>>            Luis
>>
>>
>> ----------------------------------------------------------------------------
>> On Wed, Nov 25, 2009 at 11:42 AM, motes motes <mort.motes at gmail.com> wrote:
>>> How is the image spacing for a loaded image computed?
>>>
>>> I have tried debugging my way through:
>>>
>>> itkImageFileReader.txx
>>>
>>> but when I get to:
>>>
>>> template <class TOutputImage, class ConvertPixelTraits>
>>> void ImageFileReader<TOutputImage, ConvertPixelTraits>
>>> ::GenerateData()
>>> {
>>>
>>>  typename TOutputImage::Pointer output = this->GetOutput();
>>>
>>>
>>> output contains the spacing after returning from the "GetOutput()"
>>> call. But if I enter the GetOutput() call I never get to where the
>>> spacing are set. Does this happen in some other magic place?
>>> _____________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Kitware offers ITK Training Courses, for more information visit:
>>> http://www.kitware.com/products/protraining.html
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>>
>


More information about the Insight-users mailing list