Skip to content

Commit

Permalink
Clip denoise_tv_bregman output to [-1, 1] or [0, 1]
Browse files Browse the repository at this point in the history
  • Loading branch information
jni committed Feb 14, 2016
1 parent 65fb923 commit 99cb592
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 5 additions & 1 deletion skimage/restoration/_denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ def denoise_tv_bregman(image, weight, max_iter=100, eps=1e-3, isotropic=True):
.. [4] http://www.math.ucsb.edu/~cgarcia/UGProjects/BregmanAlgorithms_JacquelineBush.pdf
"""
return _denoise_tv_bregman(image, weight, max_iter, eps, isotropic)
image = np.ascontiguousarray(np.atleast_3d(img_as_float(image)))
u = _denoise_tv_bregman(image, weight, max_iter, eps, isotropic)
minvalue = -1 if np.any(image < 0) else 0
maxvalue = 1
return np.clip(u, minvalue, maxvalue, out=u)


def _denoise_tv_chambolle_nd(im, weight=0.1, eps=2.e-4, n_iter_max=200):
Expand Down
10 changes: 3 additions & 7 deletions skimage/restoration/_denoise_cy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#cython: nonecheck=False
#cython: wraparound=False

cimport numpy as cnp
import numpy as np
from libc.math cimport exp, fabs, sqrt
from libc.float cimport DBL_MAX
Expand Down Expand Up @@ -148,10 +147,8 @@ def _denoise_bilateral(image, Py_ssize_t win_size, sigma_range,
return np.squeeze(np.asarray(out))


def _denoise_tv_bregman(image, double weight, int max_iter, double eps,
char isotropic):
image = np.atleast_3d(img_as_float(image))

def _denoise_tv_bregman(double[:, :, ::1] image, double weight, int max_iter,
double eps, char isotropic):
cdef:
Py_ssize_t rows = image.shape[0]
Py_ssize_t cols = image.shape[1]
Expand All @@ -166,7 +163,6 @@ def _denoise_tv_bregman(image, double weight, int max_iter, double eps,
u = np.zeros(shape_ext, dtype=np.double)

cdef:
double[:, :, ::1] cimage = np.ascontiguousarray(image)
double[:, :, ::1] cu = u

double[:, :, ::1] dx = np.zeros(shape_ext, dtype=np.double)
Expand Down Expand Up @@ -219,7 +215,7 @@ def _denoise_tv_bregman(image, double weight, int max_iter, double eps,
+ bx[r, c, k]
- by[r - 1, c, k]
+ by[r, c, k]
) + weight * cimage[r - 1, c - 1, k]
) + weight * image[r - 1, c - 1, k]
) / norm
cu[r, c, k] = unew

Expand Down

0 comments on commit 99cb592

Please sign in to comment.