pythonsimpleitkimage-thresholding

SimpleITK thresholding based on ratio


I am trying to do some basic thresholding on brain images. I'm trying to find the tumor to brain ratio and then use do some basic filtering based on the following ratio:

the intensity of every pixel/contralateral brain tissue intensity

Is there a way to get the intensity of this background brain pixel manually and then calculate the ratio for every pixel, to then be able to see which pixels are "in" and "out" of this threshold?

Thanks in advance


Solution

  • When you say manually, you're going just program in a number for the background intensity?

    If so, the rest of it could be like this:

    import SimpleITK as sitk
    
    # reading input as float so we can do floating point math
    input_image = sitk.ReadImage("your_file_here.nii", sitk.sitkFloat32)
    
    background_intensity =  42.0    # whatever value you've selected
    
    ratio_image = input_image / background_intensity
    
    # make a binary threshold image for ratios greater than 2.0, or whatever ratio you select
    thresholded_binary_image = ratio_image > 2.0
    

    As you can see, with SimpleITK you can do mathematical and binary operations between images and constant numbers.

    If you want to try and determine the background value automatically, you could examine a histogram of the image.