V Shreyas V Shreyas - 6 days ago 5
Python Question

How to input 3D images in medpy.filter.IntensityRangeStandardization()?

I am using the MICCAI BRATS 2015 database containing 3D MRI images of the dimensions 155x240x240.

I wanted to perform intensity standardization on these images, and am trying to use the IntensityRangeStandardization class from medpy.filter.
The code is simple:

Load 20 flair images from the database into an array:

from glob import glob
import SimpleITK as sitk

pth = 'C:/BRats2015/HGG' #path to the directory
flair = glob(self.path + '*/*Flair*/*.mha') #contain paths to all images
flair = flair[:20] #choose 20 images

#load the 20 images in sitk format
im = []
for i in flair:
im.append(sitk.ReadImage(i))

#convert them into numpy array
for i in xrange(len(im)):
im[i] = sitk.GetArrayFromImage(im[i])

#initialize the filter
normalizer = IntensityRangeStandardization()

#train and transform the images
im_n = normalizer.train_transform(im)[1] # the second returned variable contains the new images, # hence [1]


I get the following error message:

File "intensity_range_standardization.py", line 268, in train
self.__stdrange = self.__compute_stdrange(images)

File "intensity_range_standardization.py", line 451, in __compute_stdrange
raise SingleIntensityAccumulationError('Image no.{} shows an unusual single-intensity accumulation that leads to a situation where two percentile values are equal. This situation is usually caused, when the background has not been removed from the image. Another possibility would be to reduce the number of landmark percentiles landmarkp or to change their distribution.'.format(idx))

SingleIntensityAccumulationError: Image no.0 shows an unusual single-intensity accumulation that leads to a situation where two percentile values are equal. This situation is usually caused, when the background has not been removed from the image. Another possibility would be to reduce the number of landmark percentiles landmarkp or to change their distribution.

Answer

Okay, I figured how to call the function train_transform if we are given images and their masks respectively. Here's the code from the medpy github repo.

Reshaping the images should be easy, but I'll still just post the link to the code in case of any confusion : Reshape the new images