InsightSoftwareConsortium/ITKMontage

Stitched image cropped out part of input tile

bsaldana-cajal opened this issue · 4 comments

I am using the SimpleMontage.py example to stitch two 3D tiles of different sizes and the resulting stitched image does not include part of the larger tile.

Large Tile: (shape = [307, 364, 543])
Screen Shot 2022-07-20 at 11 53 46 AM

Small Tile: (shape = [307, 364, 178])
Screen Shot 2022-07-20 at 11 55 08 AM

Registration: {'Large Tile': '(0, 2.38419e-09, 0)', 'Small Tile': '(0, 28.0343, 218)'}

Resulting Stitched Image: (shape = [307, 392, 396])
Screen Shot 2022-07-20 at 11 57 40 AM

It seems that the Large Tile is not setting the upper bounds for the top part of the image. I attempted padding the Small Tile with zeros to try to match the size of the Large Tile and the resulting stitched image includes all important tile features but it has non-ideal intensity corrections. I am using the padded Small Tile for registration and for producing the montage (should I not do this?).

new_image = itk.xarray_from_image(image)
temp_image = itk.image_from_xarray(xr.DataArray(
data=np.transpose(np.pad(new_image, ((220, 150), (0, 0), (0, 0))), (2, 1, 0)),
dims=["x","y","z"]
))
temp_image.SetSpacing([25,25,25])
color_images.append(temp_image)
grayscale_images.append(temp_image)

Registered tiles: {'Large Tile': '(0, 3.8285e-07, -7.66908e-09)', 'Small Tile': '(0, 28.0352, -1.59306)'}

Resulting Stitched Image with Padding: (shape = [307, 392, 548])
Screen Shot 2022-07-20 at 2 11 49 PM

The question is, how should I approach stitching tiles of different sizes when one of the tiles is expected to set multiple bounds for the stitched image? Or if I go with the padding approach, how should I manage the intensity corrections for the padded sections?

Well, we definitely didn't envision this problem. A possible workaround is: split your big image into 2x3 tiles. Make your smaller image just one tile (center-right). Make top-right and bottom-right tiles be all black. Then you will have a somewhat normal montage setup. There will be a lot of un-needed computation, but it should produce the desired result.

Thank you, I'll try that out tomorrow and report back! In the meantime, I was looking at the code and am wondering if the problem I am experiencing is related to the Montage Size boundary setting found here? If so, is there a way for me to manually set the MaxOuter boundary?

There is no way to set it currently. If you wanted to expose it, in addition to getter/setter you would also have to add a indicator whether it was manually set, and check it before computationally updating MaxOuter.

It worked! I finally got the time to figure this out and the 2x3 tile solution worked perfectly, thank you!

Registered tiles: {'0': '(0, -2.06273e-07, 4.87442e-09)', '1': '(0, 109.001, 6.28663e-06)', '2': '(0, 2.44221e-08, 162.996)', '3': '(0, 137.059, 218.436)', '4': '(0, -6.89162e-06, 325.993)', '5': '(0, 109.046, 325.856)'}

Screen Shot 2022-07-28 at 10 20 07 AM