From fb6ef72a3195cfdba219ef7b1acb551df2a8181d Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 9 Jun 2015 14:56:29 +0200 Subject: [PATCH] public MBLBP function created for users to safely use it. --- .../plot_multiblock_local_binary_pattern.py | 4 +- skimage/feature/__init__.py | 2 +- skimage/feature/_texture.pyx | 10 +-- skimage/feature/texture.py | 65 ++++++++++++++++--- 4 files changed, 64 insertions(+), 17 deletions(-) diff --git a/doc/examples/plot_multiblock_local_binary_pattern.py b/doc/examples/plot_multiblock_local_binary_pattern.py index 8c64554b..e1ec7abb 100644 --- a/doc/examples/plot_multiblock_local_binary_pattern.py +++ b/doc/examples/plot_multiblock_local_binary_pattern.py @@ -55,12 +55,12 @@ print(lbp_code == correct_answer) """ Now let's apply the operator to a real image and see how the visualization works. """ -from skimage.feature import (multiblock_local_binary_pattern, - draw_multiblock_lbp) from skimage.util import img_as_float from skimage.transform import integral_image from skimage import data from matplotlib import pyplot as plt +from skimage.feature import (multiblock_local_binary_pattern, + draw_multiblock_lbp) test_img = data.coins() diff --git a/skimage/feature/__init__.py b/skimage/feature/__init__.py index 37954c92..11f5cd8c 100644 --- a/skimage/feature/__init__.py +++ b/skimage/feature/__init__.py @@ -5,7 +5,7 @@ from .texture import (greycomatrix, greycoprops, local_binary_pattern, draw_multiblock_lbp) -from ._texture import multiblock_local_binary_pattern +from .texture import multiblock_local_binary_pattern from .peak import peak_local_max from .corner import (corner_kitchen_rosenfeld, corner_harris, corner_shi_tomasi, corner_foerstner, corner_subpix, diff --git a/skimage/feature/_texture.pyx b/skimage/feature/_texture.pyx index 8597cdee..f71d08c1 100644 --- a/skimage/feature/_texture.pyx +++ b/skimage/feature/_texture.pyx @@ -315,11 +315,11 @@ cdef: Py_ssize_t[::1] mlbp_x_offsets = np.asarray([-1, 0, 1, 1, 1, 0, -1, -1]) Py_ssize_t[::1] mlbp_y_offsets = np.asarray([-1, -1, -1, 0, 1, 1, 1, 0]) -def multiblock_local_binary_pattern(cnp.double_t[:, ::1] int_image, - Py_ssize_t x, - Py_ssize_t y, - Py_ssize_t width, - Py_ssize_t height): +def _multiblock_local_binary_pattern(cnp.double_t[:, ::1] int_image, + Py_ssize_t x, + Py_ssize_t y, + Py_ssize_t width, + Py_ssize_t height): """Multi-block local binary pattern. The features are calculated in a way similar to local binary diff --git a/skimage/feature/texture.py b/skimage/feature/texture.py index 670c7ccb..1a9f6901 100644 --- a/skimage/feature/texture.py +++ b/skimage/feature/texture.py @@ -5,7 +5,9 @@ Methods to characterize image textures. import numpy as np from .._shared.utils import assert_nD from ..util import img_as_float -from ._texture import _glcm_loop, _local_binary_pattern +from ._texture import (_glcm_loop, + _local_binary_pattern, + _multiblock_local_binary_pattern) def greycomatrix(image, distances, angles, levels=256, symmetric=False, @@ -294,6 +296,57 @@ def local_binary_pattern(image, P, R, method='default'): return output +def multiblock_local_binary_pattern(int_image, + x, + y, + width, + height): + """Multi-block local binary pattern. + + The features are calculated in a way similar to local binary + patterns, except that summed up pixel values + rather than pixel values are used. + + MB-LBP is an extension of LBP that can be computed on any + scale in a constant time using integral image. It consists of + 9 equal-sized rectangles. They are used to compute a feature. + Sum of pixels' intensity values in each of them are compared + to the central rectangle and depending on comparison result, + the feature descriptor is computed. + + Parameters + ---------- + int_image : (N, M) array + Integral image. + x : int + X-coordinate of top left corner of a rectangle containing feature. + y : int + Y-coordinate of top left corner of a rectangle containing feature. + width : int + Width of one of 9 equal rectangles that will be used to compute + a feature. + height : int + Height of one of 9 equal rectangles that will be used to compute + a feature. + + Returns + ------- + output : int + 8bit MB-LBP feature descriptor. + + References + ---------- + .. [1] Face Detection Based on Multi-Block LBP + Representation. Lun Zhang, Rufeng Chu, Shiming Xiang, Shengcai Liao, + Stan Z. Li + http://www.cbsr.ia.ac.cn/users/scliao/papers/Zhang-ICB07-MBLBP.pdf + """ + + int_image = np.ascontiguousarray(int_image, dtype=np.double) + lbp_code = _multiblock_local_binary_pattern(int_image, x, y, width, height) + return lbp_code + + def draw_multiblock_lbp(img, x, y, @@ -306,17 +359,11 @@ def draw_multiblock_lbp(img, ): """Multi-block local binary pattern visualization. - MB-LBP is an extension of LBP that can be computed on many - scales in a constant time using integral image. It consists of - 9 equal-sized rectangles. Sum of pixels' intensity values - in each of them are compared to the central rectangle and - depending on comparison result, the feature descriptor is - computed. - The blocks visualized in the following manner: the center block is left untouched. The blocks that have higher are covered with transparent white rectangles. The blocks that have less intensity - are covered with cyan rectangles. + are covered with cyan rectangles. The colors can also be specified. + Opacity of visualization is controlled with `alpha` argument. Parameters ----------