I am trying to segment an image but not able to apply to rescale intensity to the image
I have tried to reshape the image and apply the rescaleintensity but was not able to get it
def load_sitk_image(path,vol_size=np.array([128,128,64]),dst_res=[1,1,1],method = sitk.sitkLinear ) :
img = sitk.ReadImage(path)
ret = np.zeros([vol_size[0], vol_size[1], vol_size[2]], dtype=np.float32)
#we rotate the image according to its transformation using the direction and according to the final spacing we want
factor = np.asarray(img.GetSpacing()) / [dst_res[0], dst_res[1],dst_res[2]]
factorSize = np.asarray(img.GetSize() * factor, dtype=float)
newSize = np.max([factorSize, vol_size], axis=0)
newSize = newSize.astype(dtype='int')
T=sitk.AffineTransform(3)
T.SetMatrix(img.GetDirection())
resampler = sitk.ResampleImageFilter()
resampler.SetReferenceImage(img)
resampler.SetOutputSpacing([dst_res[0], dst_res[1], dst_res[2]])
resampler.SetSize(newSize.tolist())
resampler.SetInterpolator(method)
imgResampled = resampler.Execute(img)
imgCentroid = np.asarray(newSize, dtype=float) / 2.0
imgStartPx = (imgCentroid - vol_size / 2.0).astype(dtype='int')
regionExtractor = sitk.RegionOfInterestImageFilter()
size_2_set = vol_size.astype(dtype='int')
regionExtractor.SetSize(size_2_set.tolist())
regionExtractor.SetIndex(imgStartPx.tolist())
imgResampledCropped = regionExtractor.Execute(imgResampled)
ret = np.transpose(sitk.GetArrayFromImage(imgResampledCropped).astype(dtype=float),[0,1,2])
ret = (ret - ret.min())/(ret.max()-ret.min())
#ret = (ret - ret.mean())/ret.std()
return ret
img_T1 = load_sitk_image(path = r"C:\Users\chinnu\Desktop\post processing project\training part 1\case01.mhd")
img_T2 = load_sitk_image(path =r"C:\Users\chinnu\Desktop\post processing project\training\Case01_segmentation.mhd")
img_T1_255 = sitk.Cast(sitk.RescaleIntensity(img_T1), sitk.sitkUInt8)
> error:
TypeError Traceback (most recent call last) in () 3 4 ----> 5 img_T1_255 = sitk.Cast(sitk.RescaleIntensity(img_T1), sitk.sitkUInt8)
~\Anaconda3\lib\site-packages\SimpleITK\SimpleITK.py in RescaleIntensity(image1, outputMinimum, outputMaximum) 59087 59088 """
59089 return _SimpleITK.RescaleIntensity(image1, outputMinimum, outputMaximum) 59090 class RichardsonLucyDeconvolutionImageFilter(ImageFilter_2): 59091 """
TypeError: in method 'RescaleIntensity', argument 1 of type 'itk::simple::Image const &'
i expect that result like i can apply the rescale intensity