pyushkevich / itksnap

ITK-SNAP medical image segmentation tool
http://www.itksnap.org
GNU General Public License v3.0
299 stars 88 forks source link

How ITK Snap gets the intensity at a particular co-ordinate from the MRI Scan, and which library does the ITK Snap to get intensity at a particular co-ordinate #117

Open NiharJani2002 opened 8 months ago

NiharJani2002 commented 8 months ago

I am doing Brain Tumour Segmentation. I am analysing BRATS 2020 dataset. If I hover over a particular co-ordinate (let the co-ordinate be [x,y,z]) in MRI scan using ITK snap, I get a particular intensity value.

My Question is How to get that particular intensity in the Python code or c++ code ? Such that I can it.

If possible share the code also, or what algorithm does ITK Snap uses to show that particular intensity from MRI Scan

NiharJani2002 commented 8 months ago

I am using PyTorch, but I can move on to Tensorflow if its works well with Tensorflow

liamtimms commented 3 months ago

In case this wasn't clear, you can use ITK itself (python and c++) or simpleITK to get that behavior. ITK snap is a GUI built on ITK.

NiharJani2002 commented 3 months ago

Thanks @liamtimms , but I am using the ITK library in my code but still I am not getting the same intensity values when matched to ITK snap software. Can you pls guide me how to Get it?

liamtimms commented 2 months ago

@NiharJani2002 I am not associated with ITK or ITKsnap, but you can find information about accessing pixel values and interpolation in the ITK book: https://itk.org/ItkSoftwareGuide.pdf or use the simpler nibabel -> numpy in python by just indexing to the voxel of interest if you are less interested in spatial coordinate.

pyushkevich commented 2 months ago

Pixel values are very easy to access with SimpleITK. You just have to watch out for coordinate swaps, so for example x,y,z in Numpy maps to z,y,x in SimpleITK/ITK-SNAP.

In ITK-SNAP the image coordinates (row,column,slice) displayed to the user have 1-based indexing, i.e., if you have 5 slices, they are numbered 1,2,3,4,5, rather than 0,1,2,3,4 as in Python/NumPy arrays. So that might be the source of the mismatch. In the early 2000s, when SNAP was first developed, most people outside of C/C++ were not used to 0-based indexing, so we thought 1-based would be more intuitive for our target audience. Changing it now would make things confusing for users.

Finally, prior to version 4.2, ITK-SNAP internally represented all images as int16. So when an image with floating point intensity values was loaded, those values were mapped to the range between 0 and 2^16-1, resulting in some loss of precision. Since 4.2, floating point intensity values are stored as such.

Best, Paul

On Thu, Jul 18, 2024 at 11:41 PM Liam Timms, PhD @.***> wrote:

@NiharJani2002 https://github.com/NiharJani2002 I am not associated with ITK or ITKsnap, but you can find information about accessing pixel values and interpolation in the ITK book: https://itk.org/ItkSoftwareGuide.pdf or use the simpler nibabel -> numpy in python by just indexing to the voxel of interest if you are less interested in spatial coordinate.

— Reply to this email directly, view it on GitHub https://github.com/pyushkevich/itksnap/issues/117#issuecomment-2237670779, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJPEW7P5J5P5URHNBFHWMLZNAZBZAVCNFSM6AAAAABKKMZW6OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZXGY3TANZXHE . You are receiving this because you are subscribed to this thread.Message ID: @.***>