mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-20 12:40:31 +08:00
pep8. Documenatation correction.
This commit is contained in:
@@ -10,11 +10,11 @@ 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 (See `LBP <plot_local_binary_pattern.html>`_).
|
||||
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
|
||||
(See `LBP <plot_local_binary_pattern.html>`_).
|
||||
|
||||
First, we generate an image to illustrate the functioning of MB-LBP:
|
||||
we take a (9, 9) rectangle and divide it into (3, 3) block,
|
||||
@@ -25,6 +25,7 @@ upon which we then apply MB-LBP.
|
||||
from __future__ import print_function
|
||||
from skimage.feature import multiblock_local_binary_pattern
|
||||
import numpy as np
|
||||
from numpy.testing import assert_equal
|
||||
from skimage.transform import integral_image
|
||||
|
||||
# Create test matrix where first and fifth
|
||||
@@ -35,17 +36,16 @@ test_img[3:6, 3:6] = 1
|
||||
test_img[:3, :3] = 50
|
||||
test_img[6:, 6:] = 50
|
||||
|
||||
# MB-LBP is filled in reverse order.
|
||||
# So the first and fifth bits from the end should
|
||||
# be filled.
|
||||
# First and fifth bits should be filled.
|
||||
# This correct value will be compared to
|
||||
# the computed one.
|
||||
correct_answer = 0b10001000
|
||||
|
||||
int_img = integral_image(test_img)
|
||||
|
||||
lbp_code = multiblock_local_binary_pattern(int_img, 0, 0, 3, 3)
|
||||
|
||||
print(correct_answer)
|
||||
print(lbp_code)
|
||||
assert_equal(correct_answer, lbp_code)
|
||||
|
||||
"""
|
||||
Now let's apply the operator to a real image and see how the visualization works.
|
||||
@@ -71,6 +71,6 @@ plt.imshow(img, interpolation='nearest')
|
||||
|
||||
On the above plot we see the result of computing a MB-LBP and visualization
|
||||
of the computed feature. The rectangles that have less intensity than the central
|
||||
rectangle are marked in cyan. The ones that have bigger intensity values
|
||||
rectangle are marked in cyan. The ones that have higher intensity values
|
||||
are marked in white. The central rectangle is left untouched.
|
||||
"""
|
||||
|
||||
@@ -315,9 +315,7 @@ def _multiblock_local_binary_pattern(float[:, ::1] int_image,
|
||||
Py_ssize_t central_rect_y = y + height
|
||||
|
||||
# Sum of intensity values of central rectangle
|
||||
cdef float central_rect_val = integrate(int_image,
|
||||
central_rect_y,
|
||||
central_rect_x,
|
||||
cdef float central_rect_val = integrate(int_image, central_rect_y, central_rect_x,
|
||||
central_rect_y + height - 1,
|
||||
central_rect_x + width - 1)
|
||||
|
||||
@@ -338,9 +336,7 @@ def _multiblock_local_binary_pattern(float[:, ::1] int_image,
|
||||
current_rect_y = central_rect_y + offset_y * height
|
||||
|
||||
|
||||
current_rect_val = integrate(int_image,
|
||||
current_rect_y,
|
||||
current_rect_x,
|
||||
current_rect_val = integrate(int_image, current_rect_y, current_rect_x,
|
||||
current_rect_y + height - 1,
|
||||
current_rect_x + width - 1)
|
||||
|
||||
|
||||
@@ -343,11 +343,7 @@ def multiblock_local_binary_pattern(int_image, x, y, width, height):
|
||||
return lbp_code
|
||||
|
||||
|
||||
def draw_multiblock_lbp(img,
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
def draw_multiblock_lbp(img, x, y, width, height,
|
||||
lbp_code=0,
|
||||
color_greater_block=[1, 1, 1],
|
||||
color_less_block=[0, 0.69, 0.96],
|
||||
@@ -441,12 +437,12 @@ def draw_multiblock_lbp(img,
|
||||
|
||||
# Mix-in the visualization colors.
|
||||
if has_greater_value:
|
||||
output[curr_y:curr_y+height, curr_x:curr_x+width] = \
|
||||
(1-alpha) * output[curr_y:curr_y+height, curr_x:curr_x+width] \
|
||||
+ alpha * color_greater_block
|
||||
new_value = ((1-alpha) * output[curr_y:curr_y+height, curr_x:curr_x+width]
|
||||
+ alpha * color_greater_block)
|
||||
output[curr_y:curr_y+height, curr_x:curr_x+width] = new_value
|
||||
else:
|
||||
output[curr_y:curr_y+height, curr_x:curr_x+width] = \
|
||||
(1-alpha) * output[curr_y:curr_y+height, curr_x:curr_x+width] \
|
||||
+ alpha * color_less_block
|
||||
new_value = ((1-alpha) * output[curr_y:curr_y+height, curr_x:curr_x+width]
|
||||
+ alpha * color_less_block)
|
||||
output[curr_y:curr_y+height, curr_x:curr_x+width] = new_value
|
||||
|
||||
return output
|
||||
|
||||
Reference in New Issue
Block a user