Filters Applied to Arbitrary 3D Arrays

leapctype.tomographicModels.LowPassFilter(self, f, FWHM=2.0)

Alias for BlurFilter

leapctype.tomographicModels.LowPassFilter2D(self, f, FWHM=2.0)

Alias for BlurFilter2D

leapctype.tomographicModels.HighPassFilter(self, f, FWHM=2.0)

Applies a high pass filter to the provided numpy array or torch tensor

The provided input does not have to be projection or volume data. It can be any 3D numpy array or torch tensor of any size The filter is given by delta[i] - cos^2(pi/(2*FWHM) * i), i = -ceil(FWHM), …, ceil(FWHM) This filter is very simular to a Gaussian filter, but is a FIR

Parameters:
  • f (C contiguous float32 numpy array or torch tensor) – numpy array to sharpen

  • FWHM (float) – the full width at half maximum (in number of pixels) of the filter

Returns:

f, the same as the input

leapctype.tomographicModels.HighPassFilter2D(self, f, FWHM=2.0)

Applies a 2D high pass filter to the provided numpy array or torch tensor

The provided input does not have to be projection or volume data. It can be any 3D numpy array or torch tensor of any size The filter is given by delta[i] - cos^2(pi/(2*FWHM) * i), i = -ceil(FWHM), …, ceil(FWHM) This filter is very simular to a Gaussian filter, but is a FIR

Parameters:
  • f (C contiguous float32 numpy array) – numpy array to smooth

  • FWHM (float) – the full width at half maximum (in number of pixels) of the filter

Returns:

f, the same as the input

leapctype.tomographicModels.BlurFilter(self, f, FWHM=2.0)

Applies a blurring filter to the provided numpy array or torch tensor

The provided input does not have to be projection or volume data. It can be any 3D numpy array of any size The filter is given by cos^2(pi/(2*FWHM) * i), i = -ceil(FWHM), …, ceil(FWHM) This filter is very simular to a Gaussian filter, but is a FIR

Parameters:
  • f (C contiguous float32 numpy array or torch tensor) – numpy array to smooth

  • FWHM (float) – the full width at half maximum (in number of pixels) of the filter

Returns:

f, the same as the input

leapctype.tomographicModels.BlurFilter2D(self, f, FWHM=2.0)

Applies a 2D blurring filter to the provided numpy array or torch tensor

The provided input does not have to be projection or volume data. It can be any 3D numpy array of any size The filter is given by cos^2(pi/(2*FWHM) * i), i = -ceil(FWHM), …, ceil(FWHM) This filter is very simular to a Gaussian filter, but is a FIR

Parameters:
  • f (C contiguous float32 numpy array) – numpy array to smooth

  • FWHM (float) – the full width at half maximum (in number of pixels) of the filter

Returns:

f, the same as the input

leapctype.tomographicModels.MedianFilter(self, f, threshold=0.0, windowSize=3)

Applies a thresholded 3D median filter (3x3x3 or 3x5x5) to the provided array

The provided input does not have to be projection or volume data. It can be any 3D array of any size This algorithm performs a 3D (3x3x3 or 3x5x5) median around each data value and then replaces this value only if |original value - median value| >= threshold*|median value| Note that if threshold is zero, then this is simply a median filter

Parameters:
  • f (C contiguous float32 numpy array or torch tensor) – 3D array to filter

  • threshold (float) – the threshold of whether to use the filtered value or not

  • windowSize (int) – the window size; can be 3 or 5

Returns:

f, the same as the input

leapctype.tomographicModels.MedianFilter2D(self, f, threshold=0.0, windowSize=3)

Applies a thresholded 2D median filter (windowSize x windowSize) to the provided array

The provided input does not have to be projection or volume data. It can be any 3D array of any size This algorithm performs a 2D (windowSize x windowSize) median around each data value and then replaces this value only if |original value - median value| >= threshold*|median value| Note that if threshold is zero, then this is simply a median filter

Parameters:
  • f (C contiguous float32 numpy array or torch tensor) – 3D array to denoise

  • threshold (float) – the threshold of whether to use the filtered value or not

  • windowSize (int) – the window size; can be 3, 5, or 7

Returns:

True is successful, False otherwise

leapctype.tomographicModels.get_numTVneighbors(self)

Gets the number of neighboring voxels to use for 3D TV

leapctype.tomographicModels.set_numTVneighbors(self, N)

Sets the number of neighboring voxels to use for 3D TV

Parameters:

N (int) – the number of neighbors to use for 3D TV calculations (can be 6 or 26)

leapctype.tomographicModels.TVcost(self, f, delta, beta=0.0, p=1.2)

Calculates the anisotropic Total Variation (TV) functional, i.e., cost of the provided numpy array

This function uses a Huber-like loss function applied to the differences of neighboring samples (in 3D). One can switch between using 6 or 26 neighbors using the "set_numTVneighbors" function. The aTV functional with Huber-like loss function is given by

\[\begin{split}\begin{eqnarray} R(x) &:=& \sum_{\boldsymbol{i}} \sum_{\boldsymbol{j} \in N_{\boldsymbol{i}}} \|\boldsymbol{i} - \boldsymbol{j}\|^{-1} h(x_\boldsymbol{i} - x_\boldsymbol{j}) \\ h(t) &:=& \begin{cases} \frac{1}{2}t^2, & \text{if } |t| \leq delta \\ \frac{delta^{2 - p}}{p}|t|^p + delta^2\left(\frac{1}{2} - \frac{1}{p}\right), & \text{if } |t| > delta \end{cases} \end{eqnarray}\end{split}\]

where \(N_{\boldsymbol{i}}\) is a neighborhood around the 3D pixel index \(\boldsymbol{i} = (i_1, i_2, i_3)\). The provided input does not have to be projection or volume data. It can be any 3D numpy array of any size.

Parameters:
  • f (C contiguous float32 numpy array) – 3D numpy array

  • delta (float) – parameter for the Huber-like loss function used in TV

  • beta (float) – TV multiplier (sometimes called the regularizaion strength)

  • p (float) – the exponent for the Huber-like loss function used in TV

Returns:

TV functional value

leapctype.tomographicModels.TVgradient(self, f, delta, beta=0.0, p=1.2)

Calculates the gradient of the anisotropic Total Variation (TV) functional of the provided numpy array

This function uses a Huber-like loss function applied to the differences of neighboring samples (in 3D). One can switch between using 6 or 26 neighbors using the "set_numTVneighbors" function. The aTV functional with Huber-like loss function is given by

\[\begin{split}\begin{eqnarray} R(x) &:=& \sum_{\boldsymbol{i}} \sum_{\boldsymbol{j} \in N_{\boldsymbol{i}}} \|\boldsymbol{i} - \boldsymbol{j}\|^{-1} h(x_\boldsymbol{i} - x_\boldsymbol{j}) \\ h(t) &:=& \begin{cases} \frac{1}{2}t^2, & \text{if } |t| \leq delta \\ \frac{delta^{2 - p}}{p}|t|^p + delta^2\left(\frac{1}{2} - \frac{1}{p}\right), & \text{if } |t| > delta \end{cases} \\ h'(t) &=& \begin{cases} t, & \text{if } |t| \leq delta \\ delta^{2 - p}sgn(t)|t|^{p-1}, & \text{if } |t| > delta \end{cases} \end{eqnarray}\end{split}\]

where \(N_{\boldsymbol{i}}\) is a neighborhood around the 3D pixel index \(\boldsymbol{i} = (i_1, i_2, i_3)\). The provided input does not have to be projection or volume data. It can be any 3D numpy array of any size

Parameters:
  • f (C contiguous float32 numpy array) – 3D numpy array

  • delta (float) – parameter for the Huber-like loss function used in TV

  • beta (float) – TV multiplier (sometimes called the regularizaion strength)

  • p (float) – the exponent for the Huber-like loss function used in TV

Returns:

the gradient of the TV functional applied to the input

Return type:

Df (C contiguous float32 numpy array)

leapctype.tomographicModels.TVquadForm(self, f, d, delta, beta=0.0, p=1.2)

Calculates the quadratic form of the anisotropic Total Variation (TV) functional of the provided numpy arrays

The provided inputs does not have to be projection or volume data. It can be any 3D numpy array of any size This function calculates the following inner product <d, R’’(f)d>, where R’’ is the Hessian of the TV functional The quadraitc surrogate is used here, so this function can be used to calculate the step size of a cost function that includes a TV regularization term. See the same cost in the diffuse function below for an example of its usage.

This function uses a Huber-like loss function applied to the differences of neighboring samples (in 3D). One can switch between using 6 or 26 neighbors using the "set_numTVneighbors" function. The aTV functional with Huber-like loss function is given by

\[\begin{split}\begin{eqnarray} R(x) &:=& \sum_{\boldsymbol{i}} \sum_{\boldsymbol{j} \in N_{\boldsymbol{i}}} \|\boldsymbol{i} - \boldsymbol{j}\|^{-1} h(x_\boldsymbol{i} - x_\boldsymbol{j}) \\ h(t) &:=& \begin{cases} \frac{1}{2}t^2, & \text{if } |t| \leq delta \\ \frac{delta^{2 - p}}{p}|t|^p + delta^2\left(\frac{1}{2} - \frac{1}{p}\right), & \text{if } |t| > delta \end{cases} \end{eqnarray}\end{split}\]

where \(N_{\boldsymbol{i}}\) is a neighborhood around the 3D pixel index \(\boldsymbol{i} = (i_1, i_2, i_3)\). To make this calculate a quadraitc surrogate (upper bound), LEAP uses h’(t)/t instead of h’’(t).

Parameters:
  • f (C contiguous float32 numpy array) – 3D numpy array

  • d (C contiguous float32 numpy array) – 3D numpy array

  • delta (float) – parameter for the Huber-like loss function used in TV

  • beta (float) – TV multiplier (sometimes called the regularizaion strength)

  • p (float) – the exponent for the Huber-like loss function used in TV

Returns:

the gradient of the TV functional applied to the input

Return type:

Df (C contiguous float32 numpy array)

leapctype.tomographicModels.diffuse(self, f, delta, numIter, p=1.2)

Performs anisotropic Total Variation (TV) smoothing to the provided 3D numpy array

The provided inputs does not have to be projection or volume data. It can be any 3D numpy array of any size. This function performs a specifies number of iterations of minimizing the aTV functional using gradient descent. The step size calculation uses the method of Separable Quadratic Surrogate (see also TVquadForm).

Parameters:
  • f (C contiguous float32 numpy array) – 3D numpy array

  • delta (float) – parameter for the Huber-like loss function used in TV

  • numIter (int) – number of iterations

  • p (float) – the exponent for the Huber-like loss function used in TV

Returns:

f, the same array as the input denoised

leapctype.tomographicModels.TV_denoise(self, f, delta, beta, numIter, p=1.2, meanOverFirstDim=False)

Performs anisotropic Total Variation (TV) denoising to the provided 3D numpy array

The provided inputs does not have to be projection or volume data. It can be any 3D numpy array of any size. This function performs a specifies number of iterations of minimizing the sum of an L2 loss and aTV functional using gradient descent. The step size calculation uses the method of Separable Quadratic Surrogate (see also TVquadForm).

Parameters:
  • f (C contiguous float32 numpy array) – 3D numpy array

  • delta (float) – parameter for the Huber-like loss function used in TV

  • beta (float) – regularization strength

  • numIter (int) – number of iterations

  • p (float) – the exponent for the Huber-like loss function used in TV

Returns:

f, the same array as the input denoised

leapctype.tomographicModels.BilateralFilter(self, f, spatialFWHM, intensityFWHM, scale=1.0)

Performs 3D (Scaled) Bilateral Filter (BLF) denoising method

The provided input does not have to be projection or volume data. It can be any 3D numpy array of any size

Parameters:
  • f (C contiguous float32 numpy array or torch tensor) – 3D array to denoise

  • spatialFWHM (float) – the FWHM (in number of pixels) of the spatial closeness term of the BLF

  • intensityFWHM (float) – the FWHM of the intensity closeness terms of the BLF

  • scale (float) – an optional argument to used a blurred volume (and this parameter specifies the FWHM of the blurring) to calculate the intensity closeness term

Returns:

f, the same as the input

leapctype.tomographicModels.PriorBilateralFilter(self, f, spatialFWHM, intensityFWHM, prior=None)

Performs 3D Bilateral Filter (BLF) denoising method where the intensity distance is measured against a prior image

The provided input does not have to be projection or volume data. It can be any 3D numpy array of any size

Parameters:
  • f (C contiguous float32 numpy array or torch tensor) – 3D array to denoise

  • spatialFWHM (float) – the FWHM (in number of pixels) of the spatial closeness term of the BLF

  • intensityFWHM (float) – the FWHM of the intensity closeness terms of the BLF

  • prior (C contiguous float32 numpy array or torch tensor) – 3D data prior used for the intensity distance

Returns:

f, the same as the input

leapctype.tomographicModels.GuidedFilter(self, f, r, epsilon)

Performs 3D Guided Filter denoising method

The provided input does not have to be projection or volume data. It can be any 3D numpy array of any size

Parameters:
  • f (C contiguous float32 numpy array or torch tensor) – 3D array to denoise

  • r (int) – the window radius (in number of pixels)

  • epsilon (float) – the degree of smoothing

Returns:

f, the same as the input

leapctype.tomographicModels.DictionaryDenoising(self, f, dictionary, sparsityThreshold=8, epsilon=0.0)

Represents 3D data by a sparse representation of an overcomplete dictionary, effectively denoising the data

The provided input does not have to be projection or volume data. It can be any 3D numpy array of any size

Parameters:
  • f (C contiguous float32 numpy array or torch tensor) – 3D array to denoise

  • dictionary (C contiguous float32 numpy array) – 4D array of dictionary patches

  • sparsityThreshold (int) – the maximum number of dictionary elements to use to represent a patch in the volume

  • epsilon (float) – the L^2 residual threshold to decide of the sparse dictionary representation is close enough (larger numbers perform stronger denoising)

Returns:

f, the same as the input