mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-02 13:03:48 +08:00
Trying to Debug the SegFault
This commit is contained in:
+16
-11
@@ -6,7 +6,7 @@ from ..feature.corner import _compute_auto_correlation
|
||||
from ..util import img_as_float
|
||||
|
||||
from .censure_cy import _censure_dob_loop, _slanted_integral_image, _censure_octagon_loop
|
||||
from time import time
|
||||
|
||||
|
||||
def _get_filtered_image(image, no_of_scales, mode):
|
||||
# TODO : Implement the STAR mode
|
||||
@@ -52,14 +52,17 @@ def _get_filtered_image(image, no_of_scales, mode):
|
||||
def _slanted_integral_image_modes(img, mode=1):
|
||||
if mode == 1:
|
||||
image = np.copy(img)
|
||||
mode1 = _slanted_integral_image(image)
|
||||
return mode1
|
||||
mode1 = np.zeros((image.shape[0] + 1, image.shape[1]))
|
||||
_slanted_integral_image(image, mode1)
|
||||
return mode1[1:, :mode1.shape[1]]
|
||||
|
||||
elif mode == 2:
|
||||
image = np.copy(img)
|
||||
image = np.fliplr(image)
|
||||
image = np.flipud(image)
|
||||
mode2 = _slanted_integral_image(image)
|
||||
mode2 = np.zeros((image.shape[0] + 1, image.shape[1]))
|
||||
_slanted_integral_image(image, mode2)
|
||||
mode2 = mode2[1:, :mode2.shape[1]]
|
||||
mode2 = np.fliplr(mode2)
|
||||
mode2 = np.flipud(mode2)
|
||||
return mode2
|
||||
@@ -68,7 +71,9 @@ def _slanted_integral_image_modes(img, mode=1):
|
||||
image = np.copy(img)
|
||||
image = np.flipud(image)
|
||||
image = image.T
|
||||
mode3 = _slanted_integral_image(image)
|
||||
mode3 = np.zeros((image.shape[0] + 1, image.shape[1]))
|
||||
_slanted_integral_image(image, mode3)
|
||||
mode3 = mode3[1:, :mode3.shape[1]]
|
||||
mode3 = np.flipud(mode3.T)
|
||||
return mode3
|
||||
|
||||
@@ -76,7 +81,9 @@ def _slanted_integral_image_modes(img, mode=1):
|
||||
image = np.copy(img)
|
||||
image = np.fliplr(image)
|
||||
image = image.T
|
||||
mode4 = _slanted_integral_image(image)
|
||||
mode4 = np.zeros((image.shape[0] + 1, image.shape[1]))
|
||||
_slanted_integral_image(image, mode4)
|
||||
mode4 = mode4[1:, :mode4.shape[1]]
|
||||
mode4 = np.fliplr(mode4.T)
|
||||
return mode4
|
||||
|
||||
@@ -144,24 +151,22 @@ def censure_keypoints(image, no_of_scales=7, mode='DoB', threshold=0.03, rpc_thr
|
||||
image = np.ascontiguousarray(image)
|
||||
|
||||
# Generating all the scales
|
||||
start = time()
|
||||
scales = np.zeros((image.shape[0], image.shape[1], no_of_scales))
|
||||
scales = _get_filtered_image(image, no_of_scales, mode)
|
||||
print time() - start
|
||||
|
||||
# Suppressing points that are neither minima or maxima in their 3 x 3 x 3
|
||||
# neighbourhood to zero
|
||||
minimas = (minimum_filter(scales, (3, 3, 3)) == scales).astype(int) * scales
|
||||
maximas = (maximum_filter(scales, (3, 3, 3)) == scales).astype(int) * scales
|
||||
print time() - start
|
||||
|
||||
# Suppressing minimas and maximas weaker than threshold
|
||||
minimas[np.abs(minimas) < threshold] = 0
|
||||
maximas[np.abs(maximas) < threshold] = 0
|
||||
response = maximas + minimas
|
||||
print time() - start
|
||||
|
||||
for i in range(1, no_of_scales - 1):
|
||||
response[:, :, i] = _suppress_line(response[:, :, i], (1 + i / 3.0), rpc_threshold)
|
||||
print time() - start
|
||||
|
||||
# Returning keypoints with its scale
|
||||
keypoints = np.transpose(np.nonzero(response[:, :, 1:no_of_scales])) + [0, 0, 1]
|
||||
return keypoints
|
||||
|
||||
@@ -22,30 +22,37 @@ def _censure_dob_loop(double[:, ::1] image, cnp.int16_t n,
|
||||
filtered_image[i, j] = outer_wt * outer - (inner_wt + outer_wt) * inner
|
||||
|
||||
|
||||
def _slanted_integral_image(double[:, ::1] image):
|
||||
def _slanted_integral_image(double[:, ::1] image,
|
||||
double[:, ::1] integral_img):
|
||||
|
||||
cdef Py_ssize_t i, j
|
||||
cdef double[:] left_sum = np.zeros(image.shape[0], dtype=np.float)
|
||||
cdef double[:, :] integral_img = np.zeros((image.shape[0] + 1, image.shape[1]), dtype=np.float)
|
||||
|
||||
flipped_lr = np.asarray(image[:, ::-1])
|
||||
for i in range(image.shape[1] - image.shape[0], image.shape[1]):
|
||||
left_sum[image.shape[1] - 1 - i] = np.sum(flipped_lr.diagonal(i))
|
||||
left_sum_np = np.asarray(left_sum)
|
||||
#image = np.asarray(image)
|
||||
|
||||
left_sum_np = left_sum_np.cumsum(0)
|
||||
#right_sum_np = np.asarray()
|
||||
|
||||
right_sum_np = np.sum(image, 1).cumsum(0)
|
||||
|
||||
image[:, 0] = left_sum_np
|
||||
image[:, -1] = right_sum_np
|
||||
print '1'
|
||||
for i in range(image.shape[0]):
|
||||
image[i, 0] = left_sum_np[i]
|
||||
image[i, -1] = right_sum_np[i]
|
||||
|
||||
integral_img[1:, :] = image
|
||||
print '2'
|
||||
for i in range(1, integral_img.shape[0]):
|
||||
for j in range(integral_img.shape[1]):
|
||||
integral_img[i, j] = image[i - 1, j]
|
||||
|
||||
print '3'
|
||||
for i in range(1, integral_img.shape[0]):
|
||||
for j in range(1, integral_img.shape[1] - 1):
|
||||
integral_img[i, j] += integral_img[i, j - 1] + integral_img[i - 1, j + 1] - integral_img[i - 1, j]
|
||||
return integral_img[1:, :integral_img.shape[1]]
|
||||
print '4'
|
||||
|
||||
|
||||
|
||||
def _censure_octagon_loop(double[:, ::1] image, double[:, ::1] integral_img,
|
||||
@@ -63,7 +70,7 @@ def _censure_octagon_loop(double[:, ::1] image, double[:, ::1] integral_img,
|
||||
i_m = (mi - 1) / 2
|
||||
o_set = o_m + no
|
||||
i_set = i_m + ni
|
||||
|
||||
print '5'
|
||||
for i in range(o_set + 1, image.shape[0] - o_set - 1):
|
||||
for j in range(o_set + 1, image.shape[1] - o_set - 1):
|
||||
outer = integral_img1[i + o_set, j + o_m] - integral_img1[i + o_m, j + o_set] - integral_img[i + o_set, j - o_m] + integral_img[i + o_m, j - o_m]
|
||||
@@ -79,3 +86,4 @@ def _censure_octagon_loop(double[:, ::1] image, double[:, ::1] integral_img,
|
||||
inner += integral_img3[i - i_m, j + i_set] - integral_img3[i - i_set, j + i_m] - integral_img[-1, j + i_set + 1] - integral_img[i + i_m - 1, j + i_m] + integral_img[-1, j + i_m] + integral_img[i + i_m - 1, j + i_set + 1]
|
||||
|
||||
filtered_image[i, j] = outer_wt * outer - (outer_wt + inner_wt) * inner
|
||||
print '6'
|
||||
|
||||
Reference in New Issue
Block a user