InsightSoftwareConsortium/ITKMontage

Fixed Image and Moving Image must have the same spacing

bweasels opened this issue · 4 comments

First off - thank you so much for continuing to respond to issues thus far. I'm trying to use your tool to stitch together a 3x2 microscopy image using the Nuclear stain channel, and following your "SimpleMontage.py" but I am running into a very strange error detailed below:

Error:

RuntimeError Traceback (most recent call last)
Cell In [4], line 9
6 montage.SetInputTile(t, greyscale_images[t])
8 print("Computing tile registration transforms")
----> 9 montage.Update()

RuntimeError: D:\a\im\include\itkPhaseCorrelationImageRegistrationMethod.hxx:545:
ITK ERROR: PhaseCorrelationImageRegistrationMethod(000001C3C38771D0): Fixed image and moving image must have the same spacing!
Fixed spacing: [0.100488, 0.100488, 0.967742]
Moving spacing: [0.100488, 0.100488, 0.967742]

Code Block

I follow your SimpleMontage.py tutorial script exactly, but the exact error happens here:

montage = itk.TileMontage[type(greyscale_images[0]), itk.F].New()
montage.SetMontageSize(stage_tiles.GetAxisSizes())
for t in range(stage_tiles.LinearSize()):
montage.SetInputTile(t, greyscale_images[t])
print("Computing tile registration transforms")
montage.Update()

Files
I can make the exact files available, but they are large, so not sure if it is appropriate to send over github. These files first split by channel and converted from .ims images (a bioformats compatable format generated by Andor Dragonfly Confocal Microscopes) to .nrrd via ImageJ/Fiji to try to better match the tutorial.

Please let me know if there's any other information I can send over. And thanks in advance for your help.

spacing: [0.100488, 0.100488, 0.967742] is the spacing to 6 decimal digits. Could you check your files and see whether the spacing differs in some less significant decimal place (tenth, 15th)?

So the images have spacing to 8 digits, but it is identical across all images. Does ITK have a 10^-6 limit in precision?

for file in files:
if '405.nrrd' in file:
readData, header = nrrd.read('/Datasets/Montage NRRDs/'+file)
print(np.sum(header['space directions'], axis = 0))

[0.10048828 0.10048828 0.96774194]
[0.10048828 0.10048828 0.96774194]
[0.10048828 0.10048828 0.96774194]
[0.10048828 0.10048828 0.96774194]
[0.10048828 0.10048828 0.96774194]
[0.10048828 0.10048828 0.96774194]

(for note, spacing is strictly orthogonal in my files, so the column sum is just a simplification of the following:

array([[0.10048828, 0. , 0. ],
[0. , 0.10048828, 0. ],
[0. , 0. , 0.96774194]])

Internally, ITK uses double for spacing, origin and direction information. It is just that by default, libraries print out less decimal digits. double is usually fully represented by 16-17 decimal places.

The code makes a comparison using all recorded decimals:

if (m_FixedImage->GetSpacing() != m_MovingImage->GetSpacing())

That might be strict, but when dealing with homogeneous tiles, any deviation in metadata usually indicates an error.

This module is currently not actively developed, so if you want a less strict comparison, please submit a PR.

FWIW I went through and rounded the spacing to 6 decimal places using pynrrd, saved the files, and the montage command seems to work, so this seems like a good workaround given that all my tiles had identical spacing, but was still throwing the identical spacing error check.