CBICA / HistoReg

Framework for registration of sequential digitized histology slices
Other
28 stars 7 forks source link

Limitation of dimension to output the original image #5

Closed akihikoueda closed 4 years ago

akihikoueda commented 4 years ago

Hi,

Your software is beautifully worked, however there is a limitation of dimension when adapting transformation to the original image file. When I input the original image which has more than 32767 pixels in width, I got the following error on Linux, after Affine had been done.

Exception caught of type 16ConvertException When processing command: -omc Exception detail: Error writing image to [filelocation]/metrics/full_resolution/big_warp.nii.gz ITK Exception: itk::ERROR: NiftiImageIO(0x4317140): Dimension(0) = 39360 is greater than maximum possible dimension 32767

Is there any ways to output transformed original-size images that have more than 32767 pixels in width or height in your software? Or is there any option to output images with other formats?

Best wishes Ueda

ludovenet commented 4 years ago

Hi Ueda,

Thank you for your interest in our method ! I am happy to see that you didn't have any issue with the installation. About your issue, it looks like ITK uses int16 to encode the width and height of an image, and the maximum size of a number encoded as an int16 is 32767. This explain why you can't resample an image to a resolution higher than 32767x32767. Currently we don't have any option in our method to resample images to such a high resolution, we might add this in the future. For now, I would recommend you to save the low resolution metric by using the "-S" parameter, and then resample the images yourself to the higher resolution using a different library than ITK. For example, you can try this by using Python (I know that OpenSlide can be useful to work with whole-slide images, or PIL might work as well). Keep in mind that you will need to adapt the vectors stored in the small warp image to the new resolution by scaling the vectors by the ratio between the two resolution (a 1 pixel translation in a 10x10 image correspond to a 2 pixels translation in a 20x20 image, so you need to scale the translation by 20/10 = 2).

Please let me know if this was of any help, I am curious about the result and might try this myself in the future. Best, Ludovic.

sarthakpati commented 4 years ago

On a related note, this might be a limitation of the NIfTI format [ref] and we could possibly explore the possibility of using another format (Meta or NRRD) to overcome this.

akihikoueda commented 4 years ago

Thank you for your detailed and helpful explanation. I could fully understand the limitation of ITK library and NIfTI format. I'll try another format and report the results when succeeded.

Best regards, Ueda

Borda commented 4 years ago

We have tackled loading large images in python too, and the solution was using matplotlib while ImageMagic nor other lib (opencv, skimage, Pillow) is able to load larger images then 64k or 32k. https://github.com/Borda/BIRL/blob/ec2ca0d815215680a1d5650a8a5ab83fb45ad4bc/birl/utilities/dataset.py#L168-L186