Commit 2d20fef9 authored by Emmanuel Roubin's avatar Emmanuel Roubin
Browse files

tests structuring elements

parent dd4a8d70
......@@ -17,9 +17,9 @@ class TestFonctionCov(unittest.TestCase):
def test_alongAxis(self):
im = tifffile.imread( "tools/data/snow/snow.tif" )
c = cov.alongAxis( im, range(4) )
# c shoud be [[86833030. 74757580. 53643410. 35916468.] # axis 0
# [86833030. 76282920. 56910720. 39792388.] # axis 1
# [86833030. 76410500. 57040076. 39938920.]] # axis 2
# c should be [[86833030. 74757580. 53643410. 35916468.] # axis 0
# [86833030. 76282920. 56910720. 39792388.] # axis 1
# [86833030. 76410500. 57040076. 39938920.]] # axis 2
self.assertAlmostEqual(sum(c[:,3])/c[0,0], 1.3318408137585245, places=5)
def test_subPixel(self):
......
# -*- coding: utf-8 -*-
from __future__ import print_function
import unittest
import os
import tifffile
import numpy
import spam.mesh.structured as smesh
class testAll(unittest.TestCase):
def tearDown(self):
try:
pass
except OSError:
pass
# tests structured meshes
def test_structuringElement(self):
a=smesh.structuringElement(radius=5,order=numpy.inf,margin=2)
b=smesh.structuringElement(radius=7,order=2,margin=0)
c=smesh.structuringElement(radius=8,order=1,margin=8)
self.assertEqual(int(a.sum()+len(a)+b.sum()+len(b)+c.sum()+len(c)), 3646)
if __name__ == '__main__':
unittest.main()
......@@ -463,11 +463,11 @@ def structuringElement(radius=1, order=numpy.inf, margin=0, dim=3):
The structural element
"""
tb = tuple([2*radius+2*border+1 for _ in range(dim)])
tb = tuple([2*radius+2*margin+1 for _ in range(dim)])
ts = tuple([2*radius+1 for _ in range(dim)])
c = numpy.abs(numpy.indices(ts) - radius)
d = numpy.zeros(tb)
s = [slice(border, border+2*radius+1) for _ in range(dim)]
s = [slice(margin, margin+2*radius+1) for _ in range(dim)]
d[s] = numpy.power(numpy.sum(numpy.power(c, order), axis=0),1.0/float(order)) <= radius
return d.astype('<u1')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment