Filters

petl_server.PETLserver.TVcost(self, f, delta, beta=0.0, p=1.0)

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

petl_server.PETLserver.TVgradient(self, f, delta, beta=0.0, p=1.0)

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)

petl_server.PETLserver.TVquadForm(self, f, d, delta, beta=0.0, p=1.0)

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)

petl_server.PETLserver.diffuse(self, f, delta, numIter, p=1.0)

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

petl_server.PETLserver.TV_denoise(self, f, delta, beta, numIter, p=1.0, 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

petl_server.PETLserver.relative_differences_grad(self, f, delta, beta)
petl_server.PETLserver.gaussian_filter(self, f, FWHM=2.0, numDims=3)