/
test_preprocess.py
38 lines (25 loc) · 1.1 KB
/
test_preprocess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
from openpiv.preprocess import dynamic_masking
from skimage import img_as_float
from skimage.color import rgb2gray
from skimage.io import imread, imshow
from skimage.morphology import erosion
from skimage.data import binary_blobs
import matplotlib.pyplot as plt
import os
def test_dynamic_masking(display_images=False):
""" test dynamic_masking """
# I created an image using skimage.data.binary_blobs:
# img = erosion(binary_blobs(128,.01))+binary_blobs(128,.8)
# imsave('moon.png',img)
# it's a moon on a starry night
test_directory = os.path.split(os.path.abspath(__file__))[0]
img = rgb2gray(imread(os.path.join(test_directory,'moon.png')))
img1 = dynamic_masking(img_as_float(img),method='intensity')
assert(np.allclose(img[80:84,80:84],0.86908039)) # non-zero image
assert(np.allclose(img1[80:84,80:84],0.0)) # not it's black
if display_images:
fig,ax = plt.subplots(1,2)
ax[0].imshow(img)
ax[1].imshow(img1) # see if the moon has gone
plt.show()