diff --git a/skimage/feature/__init__.py b/skimage/feature/__init__.py index 37954c92..4c646235 100644 --- a/skimage/feature/__init__.py +++ b/skimage/feature/__init__.py @@ -3,9 +3,9 @@ from ._daisy import daisy from ._hog import hog from .texture import (greycomatrix, greycoprops, local_binary_pattern, + multiblock_local_binary_pattern, draw_multiblock_lbp) -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 70d92c5c..98503534 100644 --- a/skimage/feature/_texture.pyx +++ b/skimage/feature/_texture.pyx @@ -274,11 +274,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]) -cdef int _multiblock_local_binary_pattern(float[:, ::1] int_image, - Py_ssize_t x, - Py_ssize_t y, - Py_ssize_t width, - Py_ssize_t height): +def _multiblock_local_binary_pattern(float[:, ::1] int_image, + Py_ssize_t x, + Py_ssize_t y, + Py_ssize_t width, + Py_ssize_t height): """Multi-block local binary pattern. Parameters @@ -354,49 +354,4 @@ cdef int _multiblock_local_binary_pattern(float[:, ::1] int_image, return lbp_code -def multiblock_local_binary_pattern(int_image, x, y, width, height): - """Multi-block local binary pattern. - - The features are calculated similarly to local binary patterns (LBPs), - except that summed blocks are used instead of individual pixel values. - - MB-LBP is an extension of LBP that can be computed on multiple scales - in constant time using the integral image. - 9 equally-sized rectangles are used to compute a feature. - For each rectangle, the sum of the pixel intensities is computed. - Comparisons of these sums to that of the central rectangle determine - the feature, similarly to LBP. - - 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 - 8-bit 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.float32) - lbp_code = _multiblock_local_binary_pattern(int_image, x, y, width, height) - return lbp_code - diff --git a/skimage/feature/texture.py b/skimage/feature/texture.py index efa119eb..5a3308a2 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,52 @@ 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 similarly to local binary patterns (LBPs), + except that summed blocks are used instead of individual pixel values. + + MB-LBP is an extension of LBP that can be computed on multiple scales + in constant time using the integral image. + 9 equally-sized rectangles are used to compute a feature. + For each rectangle, the sum of the pixel intensities is computed. + Comparisons of these sums to that of the central rectangle determine + the feature, similarly to LBP. + + 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 + 8-bit 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.float32) + lbp_code = _multiblock_local_binary_pattern(int_image, x, y, width, height) + return lbp_code + + def draw_multiblock_lbp(img, x, y,