This commit is contained in:
Olivier Debeir
2012-10-16 15:05:12 +02:00
parent 64c37c4e0c
commit 6e396f8598
6 changed files with 82 additions and 106 deletions
+3 -6
View File
@@ -5,11 +5,9 @@ Local Histogram Equalization
This examples enhances an image with low contrast, using a method called
*local histogram equalization*, which "spreads out the most frequent intensity
values" in an image . The equalized image [1]_ has a roughly linear cumulative
distribution function for each pixel neighborhood. The local version [2]_ of the histogram
equalization emphasized every local graylevel variations.
to be adjusted...
values" in an image .
The equalized image [1]_ has a roughly linear cumulative distribution function for each pixel neighborhood.
The local version [2]_ of the histogram equalization emphasized every local graylevel variations.
.. [1] http://en.wikipedia.org/wiki/Histogram_equalization
.. [2] http://en.wikipedia.org/wiki/Adaptive_histogram_equalization
@@ -22,7 +20,6 @@ from skimage import exposure
from skimage import rank
from skimage.morphology import disk
import matplotlib.pyplot as plt
import numpy as np
+6 -3
View File
@@ -14,9 +14,12 @@ calculates thresholds in regions of size `block_size` surrounding each pixel
(i.e. local neighborhoods). Each threshold value is the weighted mean of the
local neighborhood minus an offset value.
Added local threshold using rank filter
An other approach is to binarize locally the image using local histogram distribution.
to be adjusted ...
rank.threshold function set pixels higher than the local mean to 1, to 0 otherwize
rank.morph_contr_enh replaces each pixel by the local minimum (or local maximum) if the
pixel gray level is more close to the local minimum (resp. by the local maximum
if the pixel gray level is more close to the local maximum).
"""
import matplotlib.pyplot as plt
@@ -36,7 +39,7 @@ binary_global = image > global_thresh
block_size = 40
binary_adaptive = threshold_adaptive(image, block_size, offset=10)
selem = disk(10)
selem = disk(20)
loc_thresh = threshold(image,selem=selem)
loc_morph_contr_enh = morph_contr_enh(image,selem=selem)
+1 -1
View File
@@ -26,7 +26,7 @@ See Wikipedia_ for more details on the algorithm.
"""
import numpy as np
e
import matplotlib.pyplot as plt
from skimage.morphology import watershed, is_local_maximum
+6 -8
View File
@@ -35,10 +35,9 @@ def bilateral_mean(image, selem, out=None, mask=None, shift_x=False, shift_y=Fal
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
s0, s1 : int
define the [s0,s1] interval to be considered for computing the value.
@@ -110,10 +109,9 @@ def bilateral_pop(image, selem, out=None, mask=None, shift_x=False, shift_y=Fals
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
s0, s1 : int
define the [s0,s1] interval to be considered for computing the value.
+24 -32
View File
@@ -47,10 +47,9 @@ def percentile_autolevel(image, selem, out=None, mask=None, shift_x=False, shift
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0.,...,1.]
define the [p0,p1] percentile interval to be considered for computing the value.
@@ -120,10 +119,9 @@ def percentile_gradient(image, selem, out=None, mask=None, shift_x=False, shift_
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0.,...,1.]
define the [p0,p1] percentile interval to be considered for computing the value.
@@ -194,10 +192,9 @@ def percentile_mean(image, selem, out=None, mask=None, shift_x=False, shift_y=Fa
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0.,...,1.]
define the [p0,p1] percentile interval to be considered for computing the value.
@@ -267,10 +264,9 @@ def percentile_mean_substraction(image, selem, out=None, mask=None, shift_x=Fals
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0.,...,1.]
define the [p0,p1] percentile interval to be considered for computing the value.
@@ -341,10 +337,9 @@ def percentile_morph_contr_enh(image, selem, out=None, mask=None, shift_x=False,
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0.,...,1.]
define the [p0,p1] percentile interval to be considered for computing the value.
@@ -414,10 +409,9 @@ def percentile(image, selem, out=None, mask=None, shift_x=False, shift_y=False,
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0.,...,1.]
define the [p0,p1] percentile interval to be considered for computing the value.
@@ -488,10 +482,9 @@ def percentile_pop(image, selem, out=None, mask=None, shift_x=False, shift_y=Fal
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0.,...,1.]
define the [p0,p1] percentile interval to be considered for computing the value.
@@ -561,10 +554,9 @@ def percentile_threshold(image, selem, out=None, mask=None, shift_x=False, shift
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
p0, p1 : float in [0.,...,1.]
define the [p0,p1] percentile interval to be considered for computing the value.
+42 -56
View File
@@ -44,10 +44,9 @@ def autolevel(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -116,10 +115,9 @@ def bottomhat(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -187,10 +185,9 @@ def equalize(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -258,10 +255,9 @@ def gradient(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -331,10 +327,9 @@ def maximum(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -403,10 +398,9 @@ def mean(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -475,10 +469,9 @@ def meansubstraction(image, selem, out=None, mask=None, shift_x=False, shift_y=F
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -547,10 +540,9 @@ def median(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -619,10 +611,9 @@ def minimum(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -692,10 +683,9 @@ def modal(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -765,10 +755,9 @@ def morph_contr_enh(image, selem, out=None, mask=None, shift_x=False, shift_y=Fa
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -837,10 +826,9 @@ def pop(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -909,10 +897,9 @@ def threshold(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------
@@ -982,10 +969,9 @@ def tophat(image, selem, out=None, mask=None, shift_x=False, shift_y=False):
mask : ndarray (uint8)
Mask array that defines (>0) area of the image included in the local neighborhood.
If None, the complete image is used (default).
shift_x, shift_y : bool
shift structuring element about center point. This only affects
eccentric structuring elements (i.e. selem with even numbered sides).
Shift is bounded to the structuring element sizes.
shift_x, shift_y : (int)
Offset added to the structuring element center point.
Shift is bounded to the structuring element sizes (center must be inside the given structuring element).
Returns
-------