-
Notifications
You must be signed in to change notification settings - Fork 19
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 #9 from LaurentRDC/develop
Version 0.4.2
- Loading branch information
Showing
11 changed files
with
149 additions
and
30 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
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
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
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
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
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
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
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,40 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Image manipulation involving symmetry | ||
""" | ||
from functools import partial | ||
from skimage.transform import rotate | ||
import numpy as np | ||
|
||
# TODO: out parameter? | ||
def nfold_symmetry(im, center, mod, **kwargs): | ||
""" | ||
Returns an images averaged according to n-fold rotational symmetry. | ||
Keyword arguments are passed to skimage.transform.rotate() | ||
Parameters | ||
---------- | ||
im : array_like, ndim 2 | ||
Image to be averaged. | ||
center : array_like, shape (2,) | ||
coordinates of the center (in pixels). | ||
mod : int | ||
Fold symmetry number. Valid numbers must be a divisor of 360. | ||
Returns | ||
------- | ||
out : `~numpy.ndarray` | ||
Raises | ||
------ | ||
ValueError | ||
If `mod` is not a divisor of 360 deg. | ||
""" | ||
if (360 % mod) != 0: | ||
raise ValueError('Rotational symmetry of {} is not valid.'.format(mod)) | ||
|
||
im = np.asarray(im) | ||
angles = range(0, 360, int(360/mod)) | ||
|
||
kwargs.update({'preserve_range': True}) | ||
return sum(rotate(im, angle, center = center, **kwargs) for angle in angles)/len(angles) |
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
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
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,25 @@ | ||
# -*- coding: utf-8 -*- | ||
import numpy as np | ||
from .. import nfold_symmetry | ||
import unittest | ||
|
||
np.random.seed(23) | ||
|
||
class TestNFoldSymmetry(unittest.TestCase): | ||
|
||
def test_trivial(self): | ||
""" Test nfold_symmetry averaging on trivial array """ | ||
im = np.zeros( (256, 256) ) | ||
rot = nfold_symmetry(im, center = (128, 128), mod = 3) | ||
self.assertTrue(np.allclose(rot, im)) | ||
|
||
# TODO: test preserve_range = False has not effect | ||
|
||
def test_valid_mod(self): | ||
""" Test the the N-fold symmetry argument is valid """ | ||
im = np.empty( (128, 128) ) | ||
with self.assertRaises(ValueError): | ||
nfold_symmetry(im, center = (64,64), mod = 1.7) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |