 # Is it possible to compute 2D Hessian value for each slice in a 3D medical array?

Hi, I am trying to compute 2-dimention hessian value for each slice in a 3D array. I succeed computing 3D hessian value for a 3D image or 2D hessian value for a single slice by using itk.MultiScaleHessianBasedMeasureImageFilter. But is it possible to perform Hessian Augmentation simultaneously for all the slices in a 3D array? I know I could achieve it by writing a for-loop, which is, however, very time-consuming. Thank you for your replies.

Here is how I compute 2D hessian value

``````def hessian2D(array2d):
print("*****Hessian-vessel starts！*****")
start_time = time()
dimention = len(array2d.shape)
img_itk = itk.GetImageFromArray(array2d)

# 1
sigma_minimum = 0.2
sigma_maximum = 1  # 3.
number_of_sigma_steps = 8
ImageType = type(img_itk)
Dimension = img_itk.GetImageDimension()
HessianPixelType = itk.SymmetricSecondRankTensor[itk.D, Dimension]
HessianImageType = itk.Image[HessianPixelType, Dimension]
objectness_filter = itk.HessianToObjectnessMeasureImageFilter[HessianImageType, ImageType].New()
objectness_filter.SetBrightObject(True)
objectness_filter.SetScaleObjectnessMeasure(True)
objectness_filter.SetAlpha(0.5)
objectness_filter.SetBeta(1.0)
objectness_filter.SetGamma(5.0)
multi_scale_filter = itk.MultiScaleHessianBasedMeasureImageFilter[ImageType, HessianImageType, ImageType].New()
multi_scale_filter.SetInput(img_itk)
multi_scale_filter.SetHessianToMeasureFilter(objectness_filter)
multi_scale_filter.SetSigmaStepMethodToLogarithmic()
multi_scale_filter.SetSigmaMinimum(sigma_minimum)
multi_scale_filter.SetSigmaMaximum(sigma_maximum)
multi_scale_filter.SetNumberOfSigmaSteps(number_of_sigma_steps)
output = multi_scale_filter.GetOutput()
output_array = itk.GetArrayFromImage(output)
end_time = time()
print("Hessian-vessel finished, duration:{}s".format(end_time - start_time))
return output_array

``````

Hello @Fivethousand,

Possibly look at the SliceBySliceFilter. I’m not sure it is available in ITK’s Python wrapping but likely. The `MultiScaleHessianBasedMeasureImageFilter` is not available in SimpleITK.

Finally you can always use Python multiprocessing to work on multiple slices in parallel.

1 Like

Thank you for your reply, I just notice that most of time is used in C compilation when initializing the

MultiScaleHessianBasedMeasureImageFilter . And the time of iterating each slice could be totally ignored.