-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from CellProfiler/features/kirsch-operator
Kirsch operator
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
addons: | ||
apt: | ||
packages: | ||
- python-imaging | ||
- python-matplotlib | ||
- python-numpy | ||
- python-scipy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import numpy | ||
import scipy.ndimage.filters | ||
|
||
|
||
def kirsch(image): | ||
convolution_mask = [5, -3, -3, -3, -3, -3, 5, 5] | ||
|
||
derivatives = numpy.zeros(image.shape) | ||
|
||
kernel = numpy.zeros((3, 3), image.dtype) | ||
kindex = numpy.array([[0, 1, 2], | ||
[7, -1, 3], | ||
[6, 5, 4]]) | ||
for _ in range(len(convolution_mask)): | ||
kernel[kindex >= 0] = numpy.array(convolution_mask)[kindex[kindex >= 0]] | ||
derivatives = numpy.maximum( | ||
derivatives, scipy.ndimage.filters.convolve(image, kernel)) | ||
|
||
convolution_mask = convolution_mask[-1:] + convolution_mask[:-1] | ||
|
||
return derivatives |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ def run_tests(self): | |
]), | ||
install_requires=[ | ||
"numpy", | ||
"pillow", | ||
"scikit-image", | ||
"scipy", | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import centrosome.kirsch | ||
import scipy.misc | ||
import numpy as np | ||
import unittest | ||
|
||
class TestKirsch(unittest.TestCase): | ||
def test_01_01_kirsch(self): | ||
# | ||
# Test a maximum at all possible orientations | ||
# | ||
r = np.random.RandomState([ord(_) for _ in "kirsch"]) | ||
for coords in (((0, -1), (-1, -1), (-1, 0)), | ||
((-1, -1), (-1, 0), (-1, 1)), | ||
((-1, 0), (-1, 1), (0, 1)), | ||
((-1, 1), ( 0, 1), (1, 1)), | ||
(( 0, 1), ( 1, 1), (1, 0)), | ||
(( 1, 1), ( 1, 0), (1, -1)), | ||
(( 1, 0), ( 1, -1), (0, -1)), | ||
(( 1, -1), ( 0, -1), (-1, -1))): | ||
img = r.uniform(size=(3, 3)) * .1 | ||
expected = -3 * img | ||
for ioff, joff in coords: | ||
img[ioff + 1, joff + 1] += .5 | ||
expected[ioff + 1, joff+1] = img[ioff + 1, joff+1] * 5 | ||
expected[1, 1] = 0 | ||
result = centrosome.kirsch.kirsch(img) | ||
self.assertEqual(result[1, 1], np.sum(expected)) |