-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathopen_2d.py
More file actions
executable file
·108 lines (88 loc) · 2.28 KB
/
open_2d.py
File metadata and controls
executable file
·108 lines (88 loc) · 2.28 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/python3
import numpy as np
import matplotlib.pyplot as plt
from skimage.morphology import square
from quantimpy import minkowski as mk
from quantimpy import morphology as mp
from math import prod
image0 = np.zeros([64,64],dtype=bool)
image0[8:56,8:56] = square(48,dtype=bool)
res0 = np.array([2.0, 2.0])
ext0 = [0, image0.shape[0]*res0[0], 0, image0.shape[1]*res0[1]]
image1 = np.zeros([128,128],dtype=bool)
image1[16:112,16:112] = square(96,dtype=bool)
image2 = np.zeros([256,256],dtype=bool)
image2[32:224,32:224] = square(192,dtype=bool)
res2 = np.array([0.5, 0.5])
ext2 = [0, image2.shape[0]*res2[0], 0, image2.shape[1]*res2[1]]
image3 = np.zeros([128,256],dtype=bool)
image3[16:112,32:224] = square(192,dtype=bool)[0::2,:]
res3 = np.array([1.0, 0.5])
ext3 = [0, image3.shape[0]*res3[0], 0, image3.shape[1]*res3[1]]
#plt.gray()
#plt.imshow(image0[:,:],extent=ext0)
#plt.show()
#
#plt.gray()
#plt.imshow(image1[:,:])
#plt.show()
#
#plt.gray()
#plt.imshow(image2[:,:],extent=ext2)
#plt.show()
#
#plt.gray()
#plt.imshow(image3[:,:],extent=ext3)
#plt.show()
erosion0 = mp.erode(image0,12,res0)
opening0 = mp.open(erosion0,12,res0)
erosion1 = mp.erode(image1,12)
opening1 = mp.open(erosion1,12)
erosion2 = mp.erode(image2,12,res2)
opening2 = mp.open(erosion2,12,res2)
erosion3 = mp.erode(image3,12,res3)
opening3 = mp.open(erosion3,12,res3)
#plt.gray()
#plt.imshow(erosion0[:,:],extent=ext0)
#plt.show()
#
#plt.gray()
#plt.imshow(erosion1[:,:])
#plt.show()
#
#plt.gray()
#plt.imshow(erosion2[:,:],extent=ext2)
#plt.show()
#
#plt.gray()
#plt.imshow(erosion3[:,:],extent=ext3)
#plt.show()
# These images should be the same (exept difference caused by resolution)
plt.gray()
plt.imshow(opening0[:,:],extent=ext0)
plt.show()
plt.gray()
plt.imshow(opening1[:,:])
plt.show()
plt.gray()
plt.imshow(opening2[:,:],extent=ext2)
plt.show()
plt.gray()
plt.imshow(opening3[:,:],extent=ext3)
plt.show()
opening0 = ~np.logical_and(image0,~opening0)
opening1 = ~np.logical_and(image1,~opening1)
opening2 = ~np.logical_and(image2,~opening2)
opening3 = ~np.logical_and(image3,~opening3)
plt.gray()
plt.imshow(opening0[:,:],extent=ext0)
plt.show()
plt.gray()
plt.imshow(opening1[:,:])
plt.show()
plt.gray()
plt.imshow(opening2[:,:],extent=ext2)
plt.show()
plt.gray()
plt.imshow(opening3[:,:],extent=ext3)
plt.show()