mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-20 12:40:31 +08:00
Do not acquire GIL for BRIEF
This commit is contained in:
@@ -140,7 +140,8 @@ class BRIEF(DescriptorExtractor):
|
||||
"""
|
||||
assert_nD(image, 2)
|
||||
|
||||
np.random.seed(self.sample_seed)
|
||||
random = np.random.RandomState()
|
||||
random.seed(self.sample_seed)
|
||||
|
||||
image = _prepare_grayscale_input_2D(image)
|
||||
|
||||
@@ -151,7 +152,7 @@ class BRIEF(DescriptorExtractor):
|
||||
desc_size = self.descriptor_size
|
||||
patch_size = self.patch_size
|
||||
if self.mode == 'normal':
|
||||
samples = (patch_size / 5.0) * np.random.randn(desc_size * 8)
|
||||
samples = (patch_size / 5.0) * random.randn(desc_size * 8)
|
||||
samples = np.array(samples, dtype=np.int32)
|
||||
samples = samples[(samples < (patch_size // 2))
|
||||
& (samples > - (patch_size - 2) // 2)]
|
||||
@@ -159,9 +160,9 @@ class BRIEF(DescriptorExtractor):
|
||||
pos1 = samples[:desc_size * 2].reshape(desc_size, 2)
|
||||
pos2 = samples[desc_size * 2:desc_size * 4].reshape(desc_size, 2)
|
||||
elif self.mode == 'uniform':
|
||||
samples = np.random.randint(-(patch_size - 2) // 2,
|
||||
(patch_size // 2) + 1,
|
||||
(desc_size * 2, 2))
|
||||
samples = random.randint(-(patch_size - 2) // 2,
|
||||
(patch_size // 2) + 1,
|
||||
(desc_size * 2, 2))
|
||||
samples = np.array(samples, dtype=np.int32)
|
||||
pos1, pos2 = np.split(samples, 2)
|
||||
|
||||
|
||||
@@ -12,13 +12,14 @@ def _brief_loop(double[:, ::1] image, unsigned char[:, ::1] descriptors,
|
||||
|
||||
cdef Py_ssize_t k, d, kr, kc, pr0, pr1, pc0, pc1
|
||||
|
||||
for p in range(pos0.shape[0]):
|
||||
pr0 = pos0[p, 0]
|
||||
pc0 = pos0[p, 1]
|
||||
pr1 = pos1[p, 0]
|
||||
pc1 = pos1[p, 1]
|
||||
for k in range(keypoints.shape[0]):
|
||||
kr = keypoints[k, 0]
|
||||
kc = keypoints[k, 1]
|
||||
if image[kr + pr0, kc + pc0] < image[kr + pr1, kc + pc1]:
|
||||
descriptors[k, p] = True
|
||||
with nogil:
|
||||
for p in range(pos0.shape[0]):
|
||||
pr0 = pos0[p, 0]
|
||||
pc0 = pos0[p, 1]
|
||||
pr1 = pos1[p, 0]
|
||||
pc1 = pos1[p, 1]
|
||||
for k in range(keypoints.shape[0]):
|
||||
kr = keypoints[k, 0]
|
||||
kc = keypoints[k, 1]
|
||||
if image[kr + pr0, kc + pc0] < image[kr + pr1, kc + pc1]:
|
||||
descriptors[k, p] = True
|
||||
|
||||
@@ -4,6 +4,7 @@ from skimage import data
|
||||
from skimage import transform as tf
|
||||
from skimage.color import rgb2gray
|
||||
from skimage.feature import BRIEF, corner_peaks, corner_harris
|
||||
from skimage._shared.testing import test_parallel
|
||||
|
||||
|
||||
def test_color_image_unsupported_error():
|
||||
|
||||
Reference in New Issue
Block a user