mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-04 14:48:37 +08:00
public MBLBP function created for users to safely use it.
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
----------
|
||||
|
||||
Reference in New Issue
Block a user