Skip to content
Snippets Groups Projects
Commit a9734938 authored by Olivier Bertrand's avatar Olivier Bertrand
Browse files

Create tests for patterns

parent f097a2a0
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ the noise (default: random generated noise)
noise = np.random.randn(s, s)
# calculate filter
fx = np.arange(s/2)+1
fx = np.arange(s / 2) + 1
# index from 0-s/2,s/2-0 -> middle highest index
fx = np.hstack([fx, fx[-1::-1]])
fx = fx[:, np.newaxis]
......@@ -45,7 +45,7 @@ the noise (default: random generated noise)
f = f**(-beta)
# apply filter in frequency domain
# calculate disrete furier transformations
fnoise = np.fft.ifft2(np.fft.fft2(noise)*f)
fnoise = np.fft.ifft2(np.fft.fft2(noise) * f)
# trim to image size
fnoise = fnoise[:img_size[0], :img_size[1]]
......@@ -65,8 +65,8 @@ def gray2red(img):
img = img[..., np.newaxis]
img = img.repeat(3, axis=2)
maxval = np.max(img)
img[:, :, 1] = maxval-img[:, :, 0]
img[:, :, 2] = maxval-img[:, :, 0]
img[:, :, 1] = maxval - img[:, :, 0]
img[:, :, 2] = maxval - img[:, :, 0]
img[:, :, 0] = maxval
return img
......@@ -83,16 +83,16 @@ def norm_img(img):
return img.astype(np.uint8)
def rectangular_pattern(width, length, beta=1.4, pixel_per_mm=1):
def rectangular_pattern(width, height, beta=1.4, pixel_per_mm=1):
"""generate a rectangular pattern
:param width: width of the pattern in mm
:param length: length of the pattern in mm
:param height: height of the pattern in mm
:param beta: beta coef for generating a 1/(f^beta) pattern
:param pixel_per_mm: number of pixel per mm
:returns: a rectangular random image
:rtype: np.ndarray
"""
corridor = np.array([width, length])
corridor_px = corridor*pixel_per_mm # in px
corridor = np.array([height, width])
corridor_px = corridor * pixel_per_mm # in px
return generate_1overf_noise(corridor_px, beta)
import unittest
import numpy as np
import navipy.arenatools.patterns as tobetested
# import matplotlib.pyplot as plt
class TestCase(unittest.TestCase):
def setUp(self):
self.width = 201
self.height = 100
self.beta = 2
self.pixel_per_mm = 2
self.image = tobetested.rectangular_pattern(self.width,
self.height,
self.beta,
self.pixel_per_mm)
def test_rectangular_patter(self):
"""Chech the image dimension"""
# Check image dimension
# * height
# * width
self.assertEqual(self.image.shape[0],
self.height * self.pixel_per_mm)
self.assertEqual(self.image.shape[1],
self.width * self.pixel_per_mm)
def test_norm_img(self):
"""Check that normalised image span [0,255]"""
im = np.random.rand(100, 101)
im = tobetested.norm_img(im)
self.assertEqual(im.min(), 0)
self.assertEqual(im.max(), 255)
def test_gray2red(self):
"""Check that green=blue, red == max"""
red = tobetested.gray2red(self.image.copy())
# The red channel should be equal to max
np.testing.assert_array_equal(red[..., 0], self.image.max())
# Green==Blue
np.testing.assert_array_equal(red[..., 1], red[..., 2])
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment