New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reword the definition of Origin in SoftwareGuide #400

Open
phcerdan opened this Issue Jan 11, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@phcerdan
Copy link
Contributor

phcerdan commented Jan 11, 2019

itk.FFTPadImageFilter introduces negative indexes to its output image as a result of the padding internals.

Check the results of the piece of code in Steps to Reproduce. The results of padded image after written and read are correct. But the output of padRegular is intriguing for me, following the Software Guide, sectionDefining origin and spacing:

Dirac delta function located at the pixel center. Pixel spacing is measured between the pixel centers
and can be different along each dimension. The image origin is associated with the coordinates of
the first pixel in the image.

From that, I would expect that the origin of padRegular is modified, taking into account the new first index (negative), the correct origin would be the same that is read in readPadded.

What do you think, am I misunderstanding something?

Steps to Reproduce

import sys
import itk
try:
    from urllib.request import urlretrieve
except ImportError:
    from urllib import urlretrieve


def printImageInformation(image, title = ''):
    if title:
        print("** ", title, " **")
    print("Origin: ", image.GetOrigin())
    print("Spacing: ", image.GetSpacing())
    print("Index: ", image.GetLargestPossibleRegion().GetIndex())
    print("Size: ", image.GetLargestPossibleRegion().GetSize())
    print()

# Download data (3D)
filename = '005_32months_T2_RegT1_Reg2Atlas_ManualBrainMask_Stripped.nrrd'
if not os.path.exists(filename):
    url = 'https://data.kitware.com/api/v1/file/564a5b078d777f7522dbfaa6/download'
    urlretrieve(url, filename)

image = itk.imread(filename)
padFilter = itk.FFTPadImageFilter.New(Input=image)
padFilter.SetSizeGreatestPrimeFactor(2)
padFilter.Update()
padded = padFilter.GetOutput()
padded_filename = '/tmp/VOL_10_cropped_fftPadConstantWHAT.nrrd'
itk.imwrite(padded, padded_filename )
printImageInformation(image, 'cropped')
printImageInformation(padded, 'padRegular')

readPadded = itk.imread(padded_filename)
printImageInformation(readPadded, 'padded after written and read')
**  cropped  **
Origin:  itkPointD3 ([-6.835, -6.835, -6.835])
Spacing:  itkVectorD3 ([0.2734, 0.2734, 0.2734])
Index:  itkIndex3 ([0, 0, 0])
Size:  itkSize3 ([300, 350, 250])

**  padRegular  **
Origin:  itkPointD3 ([-6.835, -6.835, -6.835])
Spacing:  itkVectorD3 ([0.2734, 0.2734, 0.2734])
Index:  itkIndex3 ([-106, -81, -3])
Size:  itkSize3 ([512, 512, 256])

**  padded after written and read  **
Origin:  itkPointD3 ([-35.8154, -28.9804, -7.6552])
Spacing:  itkVectorD3 ([0.2734, 0.2734, 0.2734])
Index:  itkIndex3 ([0, 0, 0])
Size:  itkSize3 ([512, 512, 256])

@dzenanz

This comment has been minimized.

Copy link
Member

dzenanz commented Jan 11, 2019

The origin represents coordinates of the pixel with index [0,0,...]. This is usually, but not always, the first pixel in the image. That's why the padding filters extend the index into negative values, to avoid altering either pixel indices and their physical coordinates. Explanation in the software guide might need some rewording.

@phcerdan

This comment has been minimized.

Copy link
Contributor Author

phcerdan commented Jan 11, 2019

The origin represents coordinates of the pixel with index [0,0,...]

Yeah, that's way different than first index. Thanks @dzenanz

@phcerdan phcerdan changed the title Is Origin correct in FFTPadImageFilter? Reword `Origin` definition in SoftwareGuide Jan 11, 2019

@phcerdan phcerdan changed the title Reword `Origin` definition in SoftwareGuide Reword the definition of Origin in SoftwareGuide Jan 11, 2019

phcerdan added a commit to phcerdan/ITKIsotropicWavelets that referenced this issue Jan 14, 2019

BUG: Fix origin of itkFFTPadPositiveIndexImageFilter
See InsightSoftwareConsortium/ITK#400
for more context on the origin in ITK.
It corresponds to the index{0}, not to the first index.

Some tests related with boundary condition are removed, as they are not
needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment