From ccd902fcb492ef1a0635346d49318f48b70d377b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 30 Jun 2013 11:14:55 +0200 Subject: [PATCH] Extend bitdepth from 12bit to full 16bit --- skimage/filter/rank/bilateral.py | 15 ++---- skimage/filter/rank/core16_cy.pyx | 6 +-- skimage/filter/rank/generic.py | 76 ++++++++----------------------- skimage/filter/rank/percentile.py | 39 ++++------------ 4 files changed, 38 insertions(+), 98 deletions(-) diff --git a/skimage/filter/rank/bilateral.py b/skimage/filter/rank/bilateral.py index 13bfe37a..26784df8 100644 --- a/skimage/filter/rank/bilateral.py +++ b/skimage/filter/rank/bilateral.py @@ -3,8 +3,7 @@ The local histogram is computed using a sliding window similar to the method described in [1]_. -Input image must be 16-bit with a value < 4096 (i.e. 12 bit), -the number of histogram bins is determined from the +Input image must be 16-bit, the number of histogram bins is determined from the maximum value present in the image. The pixel neighborhood is defined by: @@ -61,8 +60,6 @@ def _apply(func8, func16, image, selem, out, mask, shift_x, shift_y, s0, s1): if out is None: out = np.zeros(image.shape, dtype=np.uint16) bitdepth = find_bitdepth(image) - if bitdepth > 11: - raise ValueError("Only uint16 <4096 image (12bit) supported.") func16(image, selem, shift_x=shift_x, shift_y=shift_y, mask=mask, bitdepth=bitdepth + 1, out=out, s0=s0, s1=s1) else: @@ -88,9 +85,8 @@ def bilateral_mean(image, selem, out=None, mask=None, shift_x=False, Parameters ---------- - image : ndarray - Image array (uint16). As the algorithm uses max. 12bit histogram, - an exception will be raised if image has a value > 4095 + image : ndarray (uint16) + Input image. selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -142,9 +138,8 @@ def bilateral_pop(image, selem, out=None, mask=None, shift_x=False, Parameters ---------- - image : ndarray - Image array (uint16). As the algorithm uses max. 12bit histogram, - an exception will be raised if image has a value > 4095 + image : ndarray (uint16) + Input image. selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray diff --git a/skimage/filter/rank/core16_cy.pyx b/skimage/filter/rank/core16_cy.pyx index 04d829e2..2b01f246 100644 --- a/skimage/filter/rank/core16_cy.pyx +++ b/skimage/filter/rank/core16_cy.pyx @@ -56,10 +56,10 @@ cdef void _core16(dtype_t kernel(Py_ssize_t*, float, dtype_t, assert centre_c >= 0 assert centre_r < srows assert centre_c < scols - assert bitdepth in range(2, 13) - maxbin_list = [0, 0, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096] - midbin_list = [0, 0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048] + maxbin_list = [0, 0, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, + 8192, 16384, 32768, 65536] + midbin_list = [m / 2 for m in maxbin_list] # set maxbin and midbin cdef Py_ssize_t maxbin = maxbin_list[bitdepth] diff --git a/skimage/filter/rank/generic.py b/skimage/filter/rank/generic.py index 124d4f25..bcfda1bc 100644 --- a/skimage/filter/rank/generic.py +++ b/skimage/filter/rank/generic.py @@ -1,11 +1,10 @@ """The local histogram is computed using a sliding window similar to the method described in [1]_. -Input image can be 8-bit or 16-bit with a value < 4096 (i.e. 12 bit), for 16-bit -input images, the number of histogram bins is determined from the maximum value -present in the image. +Input image can be 8-bit or 16-bit, for 16-bit input images, the number of +histogram bins is determined from the maximum value present in the image. -Result image is 8 or 16-bit with respect to the input image. +Result image is 8- or 16-bit with respect to the input image. References ---------- @@ -61,9 +60,6 @@ def _apply(func8, func16, image, selem, out, mask, shift_x, shift_y): if out is None: out = np.zeros(image.shape, dtype=np.uint16) bitdepth = find_bitdepth(image) - if bitdepth > 11: - image = image >> 4 - bitdepth = find_bitdepth(image) func16(image, selem, shift_x=shift_x, shift_y=shift_y, mask=mask, bitdepth=bitdepth + 1, out=out) @@ -85,9 +81,7 @@ def autolevel(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -127,9 +121,7 @@ def bottomhat(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -159,9 +151,7 @@ def equalize(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -203,9 +193,7 @@ def gradient(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -236,9 +224,7 @@ def maximum(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -278,9 +264,7 @@ def mean(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -321,9 +305,7 @@ def meansubtraction(image, selem, out=None, mask=None, shift_x=False, Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -354,9 +336,7 @@ def median(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -396,9 +376,7 @@ def minimum(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -438,9 +416,7 @@ def modal(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -473,9 +449,7 @@ def morph_contr_enh(image, selem, out=None, mask=None, shift_x=False, Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -517,9 +491,7 @@ def pop(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -566,9 +538,7 @@ def threshold(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -615,9 +585,7 @@ def tophat(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -648,9 +616,7 @@ def noise_filter(image, selem, out=None, mask=None, shift_x=False, Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -694,9 +660,7 @@ def entropy(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, the algorithm - uses max. 12bit histogram, an exception will be raised if image has a - value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -712,7 +676,7 @@ def entropy(image, selem, out=None, mask=None, shift_x=False, shift_y=False): Returns ------- out : uint8 array or uint16 array (same as input image) - entropy x10 (uint8 images) and entropy x1000 (uint16 images) + Entropy x10 (uint8 images) and entropy x1000 (uint16 images) References ---------- diff --git a/skimage/filter/rank/percentile.py b/skimage/filter/rank/percentile.py index 25758115..56c67983 100644 --- a/skimage/filter/rank/percentile.py +++ b/skimage/filter/rank/percentile.py @@ -7,9 +7,8 @@ not produce halos. The local histogram is computed using a sliding window similar to the method described in [1]_. -Input image can be 8-bit or 16-bit with a value < 4096 (i.e. 12 bit), for 16-bit -input images, the number of histogram bins is determined from the maximum value -present in the image. +Input image can be 8-bit or 16-bit, for 16-bit input images, the number of +histogram bins is determined from the maximum value present in the image. Result image is 8 or 16-bit with respect to the input image. @@ -60,8 +59,6 @@ def _apply(func8, func16, image, selem, out, mask, shift_x, shift_y, p0, p1): if out is None: out = np.zeros(image.shape, dtype=np.uint16) bitdepth = find_bitdepth(image) - if bitdepth > 11: - raise ValueError("Only uint16 <4096 image (12bit) supported.") func16(image, selem, shift_x=shift_x, shift_y=shift_y, mask=mask, bitdepth=bitdepth + 1, out=out, p0=p0, p1=p1) else: @@ -80,9 +77,7 @@ def percentile_autolevel(image, selem, out=None, mask=None, shift_x=False, Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, as the - algorithm uses max. 12bit histogram, an exception will be raised if - image has a value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -121,9 +116,7 @@ def percentile_gradient(image, selem, out=None, mask=None, shift_x=False, Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, as the - algorithm uses max. 12bit histogram, an exception will be raised if - image has a value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -161,9 +154,7 @@ def percentile_mean(image, selem, out=None, mask=None, shift_x=False, Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, as the - algorithm uses max. 12bit histogram, an exception will be raised if - image has a value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -201,9 +192,7 @@ def percentile_mean_subtraction(image, selem, out=None, mask=None, Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, as the - algorithm uses max. 12bit histogram, an exception will be raised if - image has a value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -243,9 +232,7 @@ def percentile_morph_contr_enh( Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, as the - algorithm uses max. 12bit histogram, an exception will be raised if - image has a value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -284,9 +271,7 @@ def percentile(image, selem, out=None, mask=None, shift_x=False, shift_y=False, Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, as the - algorithm uses max. 12bit histogram, an exception will be raised if - image has a value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -324,9 +309,7 @@ def percentile_pop(image, selem, out=None, mask=None, shift_x=False, Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, as the - algorithm uses max. 12bit histogram, an exception will be raised if - image has a value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray @@ -366,9 +349,7 @@ def percentile_threshold(image, selem, out=None, mask=None, shift_x=False, Parameters ---------- image : ndarray - Image array (uint8 array or uint16). If image is uint16, as the - algorithm uses max. 12bit histogram, an exception will be raised if - image has a value > 4095. + Image array (uint8 array or uint16). selem : ndarray The neighborhood expressed as a 2-D array of 1's and 0's. out : ndarray