From f3b827d21b6686839f2a117a3ed4dd57e2419969 Mon Sep 17 00:00:00 2001 From: Ankit Agrawal Date: Sun, 30 Jun 2013 21:12:54 +0800 Subject: [PATCH] Fixing indentation --- skimage/feature/_brief.py | 108 +++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/skimage/feature/_brief.py b/skimage/feature/_brief.py index a5ce37b7..b12d827b 100644 --- a/skimage/feature/_brief.py +++ b/skimage/feature/_brief.py @@ -6,16 +6,16 @@ from scipy.spatial.distance import hamming def _remove_border_keypoints(image, keypoints, dist): - width = image.shape[0] - height = image.shape[1] + width = image.shape[0] + height = image.shape[1] - keypoints = keypoints[(dist < keypoints[:, 0]) & (keypoints[:, 0] < width - dist) & - (dist < keypoints[:, 1]) & (keypoints[:, 1] < height - dist)] - return keypoints + keypoints = keypoints[(dist < keypoints[:, 0]) & (keypoints[:, 0] < width - dist) & + (dist < keypoints[:, 1]) & (keypoints[:, 1] < height - dist)] + return keypoints def brief(image, keypoints, descriptor_size=256, mode='normal', patch_size=49, sample_seed=1): - """Extract BRIEF Descriptor about given keypoints for a given image. + """Extract BRIEF Descriptor about given keypoints for a given image. Parameters ---------- @@ -49,73 +49,73 @@ def brief(image, keypoints, descriptor_size=256, mode='normal', patch_size=49, s http://cvlabwww.epfl.ch/~lepetit/papers/calonder_eccv10.pdf """ - if np.squeeze(image).ndim == 3: - image = rgb2gray(image) + if np.squeeze(image).ndim == 3: + image = rgb2gray(image) - keypoints = np.array(keypoints + 0.5, dtype=np.intp) + keypoints = np.array(keypoints + 0.5, dtype=np.intp) - # Removing keypoints that are (patch_size / 2) distance from the image border - keypoints = _remove_border_keypoints(image, keypoints, patch_size / 2) + # Removing keypoints that are (patch_size / 2) distance from the image border + keypoints = _remove_border_keypoints(image, keypoints, patch_size / 2) - descriptor = np.zeros((len(keypoints), descriptor_size), dtype=bool) + descriptor = np.zeros((len(keypoints), descriptor_size), dtype=bool) - # Gaussian Low pass filtering with variance 2 to alleviate noise sensitivity - image = gaussian_filter(image, 2) + # Gaussian Low pass filtering with variance 2 to alleviate noise sensitivity + image = gaussian_filter(image, 2) - # Sampling pairs of decision pixels in patch_size x patch_size window - if mode == 'normal': - np.random.seed(sample_seed) - samples = np.round((patch_size / 5) * np.random.randn(descriptor_size * 8)) - samples = samples[(samples < (patch_size / 2)) & (samples > - (patch_size - 1) / 2)] - first = (samples[: descriptor_size * 2]).reshape(descriptor_size, 2) - second = (samples[descriptor_size * 2: descriptor_size * 4]).reshape(descriptor_size, 2) - else: - np.random.seed(sample_seed) - samples = np.random.randint(-patch_size / 2, (patch_size / 2) + 1, (descriptor_size * 2, 2)) - first, second = np.split(samples, 2) + # Sampling pairs of decision pixels in patch_size x patch_size window + if mode == 'normal': + np.random.seed(sample_seed) + samples = np.round((patch_size / 5) * np.random.randn(descriptor_size * 8)) + samples = samples[(samples < (patch_size / 2)) & (samples > - (patch_size - 1) / 2)] + first = (samples[: descriptor_size * 2]).reshape(descriptor_size, 2) + second = (samples[descriptor_size * 2: descriptor_size * 4]).reshape(descriptor_size, 2) + else: + np.random.seed(sample_seed) + samples = np.random.randint(-patch_size / 2, (patch_size / 2) + 1, (descriptor_size * 2, 2)) + first, second = np.split(samples, 2) - # Intensity comparison tests for building the descriptor - for i in range(len(keypoints)): - set_1 = first + keypoints[i] - set_2 = second + keypoints[i] + # Intensity comparison tests for building the descriptor + for i in range(len(keypoints)): + set_1 = first + keypoints[i] + set_2 = second + keypoints[i] - for j in range(descriptor_size): - if image[set_1[j, 0]][set_1[j, 1]] < image[set_2[j, 0]][set_2[j, 0]]: - descriptor[i][j] = True + for j in range(descriptor_size): + if image[set_1[j, 0]][set_1[j, 1]] < image[set_2[j, 0]][set_2[j, 0]]: + descriptor[i][j] = True - return descriptor + return descriptor def hamming_distance(descriptor_1, descriptor_2): - """A dissimilarity measure used for matching keypoints in different images - using binary feature descriptors like BRIEF etc. + """A dissimilarity measure used for matching keypoints in different images + using binary feature descriptors like BRIEF etc. Parameters ---------- descriptor_1 : ndarray with dtype bool - Binary feature descriptor for keypoints in the first image. - 2D ndarray of dimensions (no_of_keypoints_in_image_1, descriptor_size) - with value at an index (i, j) either being True or False representing - the outcome of Intensity comparison about ith keypoint on jth decision - pixel-pair. + Binary feature descriptor for keypoints in the first image. + 2D ndarray of dimensions (no_of_keypoints_in_image_1, descriptor_size) + with value at an index (i, j) either being True or False representing + the outcome of Intensity comparison about ith keypoint on jth decision + pixel-pair. descriptor_2 : ndarray with dtype bool - Binary feature descriptor for keypoints in the second image. - 2D ndarray of dimensions (no_of_keypoints_in_image_2, descriptor_size) - with value at an index (i, j) either being True or False representing - the outcome of Intensity comparison about ith keypoint on jth decision - pixel-pair. + Binary feature descriptor for keypoints in the second image. + 2D ndarray of dimensions (no_of_keypoints_in_image_2, descriptor_size) + with value at an index (i, j) either being True or False representing + the outcome of Intensity comparison about ith keypoint on jth decision + pixel-pair. Returns ------- distance : ndarray - 2D ndarray of dimensions (no_of_rows_in_descripto_1, no_of_rows_in_descripto_2) - with value at an index (i, j) between the range [0, 1] representing the - extent of dissimilarity between ith keypoint of in first image and jth - keypoint in second image. + 2D ndarray of dimensions (no_of_rows_in_descripto_1, no_of_rows_in_descripto_2) + with value at an index (i, j) between the range [0, 1] representing the + extent of dissimilarity between ith keypoint of in first image and jth + keypoint in second image. """ - distance = np.zeros((len(descriptor_1), len(descriptor_2)), dtype=float) - for i in range(len(descriptor_1)): - for j in range(len(descriptor_2)): - distance[i, j] = hamming(descriptor_1[i][:], descriptor_2[j][:]) - return distance + distance = np.zeros((len(descriptor_1), len(descriptor_2)), dtype=float) + for i in range(len(descriptor_1)): + for j in range(len(descriptor_2)): + distance[i, j] = hamming(descriptor_1[i][:], descriptor_2[j][:]) + return distance