ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
629 stars 161 forks source link

Plotting RGB(Multi channel) image using ants.plot() #220

Closed J-Yash closed 3 years ago

J-Yash commented 3 years ago

I am trying to read an rgb image(.jpg) and plot it using ants.plot() but it does not plot the image properly and instead plots noise. Here is my image : bird (This is just a sample image I am using to test plotting of rgb images)

Code to read/plot image : im = ants.image_read(PATH_TO_IMAGE) im.plot()

The image that is being plotted looks like this: image

The ANTsImage object header using print(im) gives: image

Is there a specific way to use rgb images in ANTs? Please advise.

Thank you.

ntustison commented 3 years ago

I stumbled across this the other day and had to use imageio as a workaround. Note that if you save starry_night_ants as a nii.gz file, you can then read it back in using ants.image_read. I have this on my list of things to fix but just haven't gotten to it yet.

J-Yash commented 3 years ago
  1. So I tried using your suggested method to get the ANTs image but plotting that using ants.plot() still plots noise. Is there another way I could plot this ANTs image?

  2. Even though the plotting is buggy, does the ants.registration() method work fine on such RGB images?

ntustison commented 3 years ago

It works for me.

>>> starry_night = ants.image_read("starry_night.nii.gz")
>>> ants.plot(starry_night.vector_to_rgb())

Even though the plotting is buggy, does the ants.registration() method work fine on such RGB images?

Multi-component images, including RGB, have to be split up and any components beyond the first would need to be plugged into the multivariate_extras argument of ants.registration.

J-Yash commented 3 years ago

That solves my issue. Thank you. Although I was curious: Does using an RGB image lead to better registration? Or simply converting my image to grayscale(Or simply using one channel) and then doing the registration would give similar results?

ntustison commented 3 years ago

Medical imaging doesn't typically utilize RGB images so we don't have direct experience. However, since the RGB channels are highly correlated and since our go to metric is cross- correlation, you probably won't gain much using all three channels separately.

J-Yash commented 3 years ago

That's very helpful. Thank you.