Skip to content

Commit c8a666e

Browse files
committed
skipping image processing pytest for now as the runners don't like it for some reason
1 parent ba8b28e commit c8a666e

File tree

1 file changed

+138
-135
lines changed

1 file changed

+138
-135
lines changed

test/pytest/test_imageprocessing.py

Lines changed: 138 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -5,143 +5,146 @@
55

66
np.random.seed(666)
77

8+
DO_TEST=False
89
PLOT_SHOW = False
910

1011

1112
####################################################################################
1213
def test_imageProcessing():
13-
pass
14-
# # generate a random noise
15-
# imageSize = 512
16-
# noiseStd = np.random.rand(1) * 4
17-
# noiseMean = np.random.randint(
18-
# 75,
19-
# 100,
20-
# [
21-
# 1,
22-
# ],
23-
# ).item()
24-
# noise = np.round(np.random.randn(imageSize, imageSize) * noiseStd + noiseMean)
25-
26-
# # scatter some point sources on it
27-
# pointSize = 5
28-
# pointHalfSize = pointSize // 2
29-
# pointSource = np.asarray(
30-
# [[1, 1, 1, 1, 1], [1, 5, 30, 5, 1], [1, 30, 100, 30, 1], [1, 5, 30, 5, 1], [1, 1, 1, 1, 1]]
31-
# )
32-
33-
# scene = noise.copy()
34-
# numPointSources = 3000
35-
# for point in range(numPointSources):
36-
# row = np.random.randint(
37-
# pointHalfSize,
38-
# imageSize - pointHalfSize,
39-
# [
40-
# 1,
41-
# ],
42-
# ).item()
43-
# col = np.random.randint(
44-
# pointHalfSize,
45-
# imageSize - pointHalfSize,
46-
# [
47-
# 1,
48-
# ],
49-
# ).item()
50-
51-
# cutout = scene[row - pointHalfSize : row + pointHalfSize + 1, col - pointHalfSize : col + pointHalfSize + 1]
52-
# cutout = cutout + pointSource
53-
# scene[row - pointHalfSize : row + pointHalfSize + 1, col - pointHalfSize : col + pointHalfSize + 1] = cutout
54-
55-
# # generate centroids from the image
56-
# thresholdRate = 0.014
57-
# borderWidth = np.random.randint(
58-
# 0,
59-
# 4,
60-
# [
61-
# 1,
62-
# ],
63-
# ).item()
64-
# cScene = NumCpp.NdArray(imageSize)
65-
# cScene.setArray(scene)
66-
67-
# threshold = NumCpp.generateThreshold(cScene, thresholdRate)
68-
# print(f"Scene Min = {scene.min()}")
69-
# print(f"Scene Max = {scene.max()}")
70-
# print(f"Threshold = {threshold}")
71-
# print(f"Desired Rate = {thresholdRate}")
72-
# print(f"Actual Rate(Threshold) = {np.count_nonzero(scene > threshold) / scene.size}")
73-
# print(f"Actual Rate(Threshold - 1) = {np.count_nonzero(scene > threshold - 1) / scene.size}")
74-
75-
# centroids = list(NumCpp.generateCentroids(cScene, thresholdRate, "pre", borderWidth))
76-
# print(f"Window Pre Number of Centroids (Border = {borderWidth}) = {len(centroids)}")
77-
78-
# # plt the results
79-
# plt.figure()
80-
# plt.imshow(scene)
81-
# plt.colorbar()
82-
# plt.clim([threshold, threshold + 1])
83-
# plt.xlabel("Rows")
84-
# plt.ylabel("Cols")
85-
# plt.title(f"Window Pre Centroids\nNumber of Centroids = {len(centroids)}")
86-
87-
# for centroid in centroids:
88-
# plt.plot(centroid.col(), centroid.row(), "og", fillstyle="none")
89-
90-
# if PLOT_SHOW:
91-
# plt.show()
92-
93-
# centroidInfo = np.asarray([[centroid.intensity(), centroid.eod()] for centroid in centroids])
94-
95-
# plt.figure()
96-
# plt.plot(np.sort(centroidInfo[:, 0].flatten()))
97-
# plt.title("Window Pre Centroid Intensities")
98-
# plt.xlabel("Centroid #")
99-
# plt.ylabel("Counts")
100-
# if PLOT_SHOW:
101-
# plt.show()
102-
103-
# plt.figure()
104-
# plt.plot(np.sort(centroidInfo[:, 1].flatten() * 100))
105-
# plt.title("Window Pre Centroid EOD")
106-
# plt.xlabel("Centroid #")
107-
# plt.ylabel("EOD (%)")
108-
# if PLOT_SHOW:
109-
# plt.show()
110-
111-
# centroids = list(NumCpp.generateCentroids(cScene, thresholdRate, "post", borderWidth))
112-
# print(f"Window Post Number of Centroids (Border = {borderWidth}) = {len(centroids)}")
113-
114-
# # plt the results
115-
# plt.figure()
116-
# plt.imshow(scene)
117-
# plt.colorbar()
118-
# plt.clim([threshold, threshold + 1])
119-
# plt.xlabel("Rows")
120-
# plt.ylabel("Cols")
121-
# plt.title(f"Window Post Centroids\nNumber of Centroids = {len(centroids)}")
122-
123-
# for centroid in centroids:
124-
# plt.plot(centroid.col(), centroid.row(), "og", fillstyle="none")
125-
126-
# if PLOT_SHOW:
127-
# plt.show()
128-
129-
# centroidInfo = np.asarray([[centroid.intensity(), centroid.eod()] for centroid in centroids])
130-
131-
# plt.figure()
132-
# plt.plot(np.sort(centroidInfo[:, 0].flatten()))
133-
# plt.title("Window Post Centroid Intensities")
134-
# plt.xlabel("Centroid #")
135-
# plt.ylabel("Counts")
136-
# if PLOT_SHOW:
137-
# plt.show()
138-
139-
# plt.figure()
140-
# plt.plot(np.sort(centroidInfo[:, 1].flatten() * 100))
141-
# plt.title("Window Post Centroid EOD")
142-
# plt.xlabel("Centroid #")
143-
# plt.ylabel("EOD (%)")
144-
# if PLOT_SHOW:
145-
# plt.show()
146-
147-
# plt.close("all")
14+
if not DO_TEST:
15+
return
16+
17+
# generate a random noise
18+
imageSize = 512
19+
noiseStd = np.random.rand(1) * 4
20+
noiseMean = np.random.randint(
21+
75,
22+
100,
23+
[
24+
1,
25+
],
26+
).item()
27+
noise = np.round(np.random.randn(imageSize, imageSize) * noiseStd + noiseMean)
28+
29+
# scatter some point sources on it
30+
pointSize = 5
31+
pointHalfSize = pointSize // 2
32+
pointSource = np.asarray(
33+
[[1, 1, 1, 1, 1], [1, 5, 30, 5, 1], [1, 30, 100, 30, 1], [1, 5, 30, 5, 1], [1, 1, 1, 1, 1]]
34+
)
35+
36+
scene = noise.copy()
37+
numPointSources = 3000
38+
for point in range(numPointSources):
39+
row = np.random.randint(
40+
pointHalfSize,
41+
imageSize - pointHalfSize,
42+
[
43+
1,
44+
],
45+
).item()
46+
col = np.random.randint(
47+
pointHalfSize,
48+
imageSize - pointHalfSize,
49+
[
50+
1,
51+
],
52+
).item()
53+
54+
cutout = scene[row - pointHalfSize : row + pointHalfSize + 1, col - pointHalfSize : col + pointHalfSize + 1]
55+
cutout = cutout + pointSource
56+
scene[row - pointHalfSize : row + pointHalfSize + 1, col - pointHalfSize : col + pointHalfSize + 1] = cutout
57+
58+
# generate centroids from the image
59+
thresholdRate = 0.014
60+
borderWidth = np.random.randint(
61+
0,
62+
4,
63+
[
64+
1,
65+
],
66+
).item()
67+
cScene = NumCpp.NdArray(imageSize)
68+
cScene.setArray(scene)
69+
70+
threshold = NumCpp.generateThreshold(cScene, thresholdRate)
71+
print(f"Scene Min = {scene.min()}")
72+
print(f"Scene Max = {scene.max()}")
73+
print(f"Threshold = {threshold}")
74+
print(f"Desired Rate = {thresholdRate}")
75+
print(f"Actual Rate(Threshold) = {np.count_nonzero(scene > threshold) / scene.size}")
76+
print(f"Actual Rate(Threshold - 1) = {np.count_nonzero(scene > threshold - 1) / scene.size}")
77+
78+
centroids = list(NumCpp.generateCentroids(cScene, thresholdRate, "pre", borderWidth))
79+
print(f"Window Pre Number of Centroids (Border = {borderWidth}) = {len(centroids)}")
80+
81+
# plt the results
82+
plt.figure()
83+
plt.imshow(scene)
84+
plt.colorbar()
85+
plt.clim([threshold, threshold + 1])
86+
plt.xlabel("Rows")
87+
plt.ylabel("Cols")
88+
plt.title(f"Window Pre Centroids\nNumber of Centroids = {len(centroids)}")
89+
90+
for centroid in centroids:
91+
plt.plot(centroid.col(), centroid.row(), "og", fillstyle="none")
92+
93+
if PLOT_SHOW:
94+
plt.show()
95+
96+
centroidInfo = np.asarray([[centroid.intensity(), centroid.eod()] for centroid in centroids])
97+
98+
plt.figure()
99+
plt.plot(np.sort(centroidInfo[:, 0].flatten()))
100+
plt.title("Window Pre Centroid Intensities")
101+
plt.xlabel("Centroid #")
102+
plt.ylabel("Counts")
103+
if PLOT_SHOW:
104+
plt.show()
105+
106+
plt.figure()
107+
plt.plot(np.sort(centroidInfo[:, 1].flatten() * 100))
108+
plt.title("Window Pre Centroid EOD")
109+
plt.xlabel("Centroid #")
110+
plt.ylabel("EOD (%)")
111+
if PLOT_SHOW:
112+
plt.show()
113+
114+
centroids = list(NumCpp.generateCentroids(cScene, thresholdRate, "post", borderWidth))
115+
print(f"Window Post Number of Centroids (Border = {borderWidth}) = {len(centroids)}")
116+
117+
# plt the results
118+
plt.figure()
119+
plt.imshow(scene)
120+
plt.colorbar()
121+
plt.clim([threshold, threshold + 1])
122+
plt.xlabel("Rows")
123+
plt.ylabel("Cols")
124+
plt.title(f"Window Post Centroids\nNumber of Centroids = {len(centroids)}")
125+
126+
for centroid in centroids:
127+
plt.plot(centroid.col(), centroid.row(), "og", fillstyle="none")
128+
129+
if PLOT_SHOW:
130+
plt.show()
131+
132+
centroidInfo = np.asarray([[centroid.intensity(), centroid.eod()] for centroid in centroids])
133+
134+
plt.figure()
135+
plt.plot(np.sort(centroidInfo[:, 0].flatten()))
136+
plt.title("Window Post Centroid Intensities")
137+
plt.xlabel("Centroid #")
138+
plt.ylabel("Counts")
139+
if PLOT_SHOW:
140+
plt.show()
141+
142+
plt.figure()
143+
plt.plot(np.sort(centroidInfo[:, 1].flatten() * 100))
144+
plt.title("Window Post Centroid EOD")
145+
plt.xlabel("Centroid #")
146+
plt.ylabel("EOD (%)")
147+
if PLOT_SHOW:
148+
plt.show()
149+
150+
plt.close("all")

0 commit comments

Comments
 (0)