shancx 1.9.33.176__tar.gz → 1.9.33.178__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. {shancx-1.9.33.176 → shancx-1.9.33.178}/PKG-INFO +1 -1
  2. {shancx-1.9.33.176 → shancx-1.9.33.178}/setup.py +1 -1
  3. shancx-1.9.33.178/shancx/QC.py +223 -0
  4. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/geosProj.py +1 -1
  5. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx.egg-info/PKG-INFO +1 -1
  6. shancx-1.9.33.176/shancx/QC.py +0 -69
  7. {shancx-1.9.33.176 → shancx-1.9.33.178}/README.md +0 -0
  8. {shancx-1.9.33.176 → shancx-1.9.33.178}/setup.cfg +0 -0
  9. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/3D/__init__.py +0 -0
  10. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/Class.py +0 -0
  11. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/CudaPrefetcher1.py +0 -0
  12. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/Fake_image.py +0 -0
  13. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/Hsml.py +0 -0
  14. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/L2Loss.py +0 -0
  15. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/MetricTracker.py +0 -0
  16. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/Normalize.py +0 -0
  17. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/OptimizerWScheduler.py +0 -0
  18. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/Rmageresize.py +0 -0
  19. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/Savemodel.py +0 -0
  20. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/SmoothL1_losses.py +0 -0
  21. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/Tqdm.py +0 -0
  22. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/__init__.py +0 -0
  23. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/checknan.py +0 -0
  24. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/dsalgor.py +0 -0
  25. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/iouJU.py +0 -0
  26. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/mask.py +0 -0
  27. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/psnr.py +0 -0
  28. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/ssim.py +0 -0
  29. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/structural_similarity.py +0 -0
  30. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Algo/tool.py +0 -0
  31. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Calmetrics/__init__.py +0 -0
  32. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Calmetrics/calmetrics.py +0 -0
  33. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Calmetrics/calmetricsmatrixLib.py +0 -0
  34. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Calmetrics/rmseR2score.py +0 -0
  35. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Clip/__init__.py +0 -0
  36. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Cmd.py +0 -0
  37. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Df/DataFrame.py +0 -0
  38. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Df/__init__.py +0 -0
  39. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Df/tool.py +0 -0
  40. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Diffm/Psamples.py +0 -0
  41. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Diffm/__init__.py +0 -0
  42. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Diffm/test.py +0 -0
  43. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Doc/__init__.py +0 -0
  44. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/E/__init__.py +0 -0
  45. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Fillmiss/__init__.py +0 -0
  46. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Fillmiss/imgidwJU.py +0 -0
  47. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Fillmiss/imgidwLatLonJU.py +0 -0
  48. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Gpu/__init__.py +0 -0
  49. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/H9/__init__.py +0 -0
  50. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/H9/ahi_read_hsd.py +0 -0
  51. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/H9/ahisearchtable.py +0 -0
  52. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/H9/geometry.py +0 -0
  53. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Hug/__init__.py +0 -0
  54. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Inst.py +0 -0
  55. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Lib.py +0 -0
  56. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Mos/__init__.py +0 -0
  57. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/NN/__init__.py +0 -0
  58. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Path1.py +0 -0
  59. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Plot/GlobMap.py +0 -0
  60. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Plot/Gray2RGB.py +0 -0
  61. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Plot/__init__.py +0 -0
  62. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Plot/border.py +0 -0
  63. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Plot/draw_day_CR_PNG.py +0 -0
  64. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Plot/exam.py +0 -0
  65. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Plot/radarNmc.py +0 -0
  66. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Plot/single_china_map.py +0 -0
  67. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Point.py +0 -0
  68. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/RdPzl/__init__.py +0 -0
  69. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Read.py +0 -0
  70. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/SN/__init__.py +0 -0
  71. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Time/GetTime.py +0 -0
  72. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Time/__init__.py +0 -0
  73. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Time/timeCycle.py +0 -0
  74. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Time/tool.py +0 -0
  75. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Train/__init__.py +0 -0
  76. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Train/makelist.py +0 -0
  77. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Train/multiGpu.py +0 -0
  78. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Train/prepare.py +0 -0
  79. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/Train/renet50.py +0 -0
  80. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/ZR.py +0 -0
  81. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/__init__.py +0 -0
  82. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/args.py +0 -0
  83. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/bak.py +0 -0
  84. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/cmp.py +0 -0
  85. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/df2database.py +0 -0
  86. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/getResponse.py +0 -0
  87. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/info.py +0 -0
  88. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/netdfJU.py +0 -0
  89. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/sendM.py +0 -0
  90. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/tensBoard/__init__.py +0 -0
  91. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/tool.py +0 -0
  92. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx/wait.py +0 -0
  93. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx.egg-info/SOURCES.txt +0 -0
  94. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx.egg-info/dependency_links.txt +0 -0
  95. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx.egg-info/requires.txt +0 -0
  96. {shancx-1.9.33.176 → shancx-1.9.33.178}/shancx.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: shancx
3
- Version: 1.9.33.176
3
+ Version: 1.9.33.178
4
4
  Summary: A simple timer decorator
5
5
  Home-page: https://gitee.com/shancx
6
6
  Author: shancx
@@ -3,7 +3,7 @@
3
3
  from setuptools import setup, find_packages
4
4
  setup(
5
5
  name="shancx",
6
- version="1.9.33.176",
6
+ version="1.9.33.178",
7
7
  packages=find_packages(),
8
8
  description="A simple timer decorator",
9
9
  long_description=open("README.md").read(),
@@ -0,0 +1,223 @@
1
+ import cv2
2
+ import numpy as np
3
+ from numba import jit
4
+ def removeSmallPatches(binary_mask, min_pixels=50, min_area=40):
5
+ binary_mask = (binary_mask > 0).astype(np.uint8)
6
+ num_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(
7
+ binary_mask, connectivity=8
8
+ )
9
+ output_mask = np.zeros_like(binary_mask)
10
+ for i in range(1, num_labels):
11
+ pixel_count = stats[i, cv2.CC_STAT_AREA]
12
+ if pixel_count < min_pixels:
13
+ continue
14
+ component_mask = (labels == i).astype(np.uint8)
15
+ contours, _ = cv2.findContours(component_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
16
+ if contours:
17
+ contour = contours[0]
18
+ area = cv2.contourArea(contour)
19
+ if area < min_area:
20
+ continue
21
+ output_mask[labels == i] = 255
22
+ return output_mask
23
+
24
+ """
25
+ mask = removeSmallPatches(b, min_pixels=50, min_area=40)
26
+ data = np.where(mask, data, 0)
27
+ filtered_data = np.full([256,256],0)
28
+ filtered_data[mask] = e[mask]
29
+ """
30
+
31
+ import cv2
32
+ import numpy as np
33
+ from concurrent.futures import ThreadPoolExecutor
34
+ def process_block_optimized(args):
35
+ block, coords, min_pixels, min_area = args
36
+ y, x, y_end, x_end = coords
37
+ num_labels, labels, stats, _ = cv2.connectedComponentsWithStats(block, 8)
38
+ result = np.zeros_like(block)
39
+ valid_labels = []
40
+ for i in range(1, num_labels):
41
+ if stats[i, cv2.CC_STAT_AREA] >= min_pixels:
42
+ valid_labels.append(i)
43
+ for i in valid_labels:
44
+ component_mask = (labels == i).astype(np.uint8)
45
+ contours, _ = cv2.findContours(component_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
46
+ if contours and cv2.contourArea(contours[0]) >= min_area:
47
+ result[labels == i] = 255
48
+ return result, coords
49
+ def removeSmallPatches_fast(binary_mask, min_pixels=100, min_area=40, num_workers=3):
50
+ binary_mask = (binary_mask > 0).astype(np.uint8)
51
+ h, w = binary_mask.shape
52
+ output = np.zeros_like(binary_mask)
53
+ block_size = 2000
54
+ blocks = []
55
+ for y in range(0, h, block_size):
56
+ for x in range(0, w, block_size):
57
+ y_end, x_end = min(y+block_size, h), min(x+block_size, w)
58
+ block = binary_mask[y:y_end, x:x_end]
59
+ blocks.append((block, (y, x, y_end, x_end), min_pixels, min_area))
60
+ with ThreadPoolExecutor(num_workers) as executor:
61
+ for result, (y, x, y_end, x_end) in executor.map(process_block_optimized, blocks):
62
+ output[y:y_end, x:x_end] = result
63
+ return output
64
+
65
+ """
66
+ mask = removeSmallPatches(b, min_pixels=50, min_area=40)
67
+ data = np.where(mask, data, 0)
68
+ filtered_data = np.full([256,256],0)
69
+ filtered_data[mask] = e[mask]
70
+ """
71
+
72
+ import cv2
73
+ import numpy as np
74
+ from numba import jit, prange
75
+ from concurrent.futures import ThreadPoolExecutor
76
+ def removeSmallPatches_optimized(binary_mask, min_pixels=50, min_area=40):
77
+ binary_mask = (binary_mask > 0).astype(np.uint8)
78
+ num_labels, labels, stats, _ = cv2.connectedComponentsWithStats(binary_mask, connectivity=8)
79
+ output_mask = np.zeros_like(binary_mask)
80
+ valid_labels = [i for i in range(1, num_labels) if stats[i, cv2.CC_STAT_AREA] >= min_pixels]
81
+ for i in valid_labels:
82
+ contour_mask = (labels == i).astype(np.uint8)
83
+ contours, _ = cv2.findContours(contour_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
84
+
85
+ if contours and cv2.contourArea(contours[0]) >= min_area:
86
+ output_mask[labels == i] = 255
87
+
88
+ return output_mask
89
+
90
+ @jit(nopython=True, parallel=True, nogil=True)
91
+ def numba_filter_components(labels, stats, min_pixels, min_area):
92
+ height, width = labels.shape
93
+ output = np.zeros((height, width), dtype=np.uint8)
94
+ for i in prange(1, stats.shape[0]):
95
+ if stats[i, 4] >= min_pixels: # stats[i, 4] 对应 cv2.CC_STAT_AREA
96
+ for y in range(height):
97
+ for x in range(width):
98
+ if labels[y, x] == i:
99
+ output[y, x] = 255
100
+ return output
101
+ def removeSmallPatches_numba(binary_mask, min_pixels=50, min_area=40):
102
+ binary_mask = (binary_mask > 0).astype(np.uint8)
103
+ num_labels, labels, stats, _ = cv2.connectedComponentsWithStats(binary_mask, connectivity=8)
104
+ output_mask = numba_filter_components(labels, stats, min_pixels, min_area)
105
+ if min_area > 0:
106
+ num_labels2, labels2, stats2, _ = cv2.connectedComponentsWithStats(output_mask, connectivity=8)
107
+ final_output = np.zeros_like(output_mask)
108
+ for i in range(1, num_labels2):
109
+ contour_mask = (labels2 == i).astype(np.uint8)
110
+ contours, _ = cv2.findContours(contour_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
111
+ if contours and cv2.contourArea(contours[0]) >= min_area:
112
+ final_output[labels2 == i] = 255
113
+ return final_output
114
+ return output_mask
115
+ def process_block_optimized_v2(args):
116
+ block, coords, min_pixels, min_area = args
117
+ num_labels, labels, stats, _ = cv2.connectedComponentsWithStats(block, connectivity=8)
118
+ result = np.zeros_like(block)
119
+ valid_labels = []
120
+ for i in range(1, num_labels):
121
+ if stats[i, cv2.CC_STAT_AREA] >= min_pixels:
122
+ valid_labels.append(i)
123
+ for i in valid_labels:
124
+ component_indices = (labels == i)
125
+ if component_indices.any():
126
+ component_mask = component_indices.astype(np.uint8)
127
+ contours, _ = cv2.findContours(component_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
128
+ if contours and cv2.contourArea(contours[0]) >= min_area:
129
+ result[component_indices] = 255
130
+ return result, coords
131
+ def removeSmallPatches_fast_v2(binary_mask, min_pixels=100, min_area=40, num_workers=4):
132
+ binary_mask = (binary_mask > 0).astype(np.uint8)
133
+ h, w = binary_mask.shape
134
+ optimal_block_size = max(500, min(2000, (h * w) // (num_workers * 10000)))
135
+ output = np.zeros_like(binary_mask)
136
+ blocks = []
137
+ for y in range(0, h, optimal_block_size):
138
+ for x in range(0, w, optimal_block_size):
139
+ y_end, x_end = min(y + optimal_block_size, h), min(x + optimal_block_size, w)
140
+ block = binary_mask[y:y_end, x:x_end].copy()
141
+ blocks.append((block, (y, x, y_end, x_end), min_pixels, min_area))
142
+ actual_workers = min(num_workers, len(blocks))
143
+ with ThreadPoolExecutor(max_workers=actual_workers) as executor:
144
+ for result, (y, x, y_end, x_end) in executor.map(process_block_optimized_v2, blocks):
145
+ output[y:y_end, x:x_end] = result
146
+ return output
147
+ def get_optimal_function(binary_mask, min_pixels=50, min_area=40):
148
+ h, w = binary_mask.shape
149
+ total_pixels = h * w
150
+ if total_pixels < 1000000: # 小于100万像素
151
+ return removeSmallPatches_optimized
152
+ if min_area <= 0:
153
+ return removeSmallPatches_numba
154
+ return removeSmallPatches_fast_v2
155
+ def auto_remove_small_patches(binary_mask, min_pixels=50, min_area=40):
156
+ optimal_func = get_optimal_function(binary_mask, min_pixels, min_area)
157
+ return optimal_func(binary_mask, min_pixels, min_area)
158
+ """
159
+ try:
160
+ result = auto_remove_small_patches(binary_mask, min_pixels=50, min_area=40)
161
+ except Exception as e:
162
+ from original_module import removeSmallPatches
163
+ result = removeSmallPatches(binary_mask, min_pixels=50, min_area=40)
164
+ removeSmallPatches_numba optimum performance min_area <= 0
165
+ removeSmallPatches_fast_v2 area
166
+ """
167
+ @jit(nopython=True, parallel=True, nogil=True)
168
+ def QC_simple_numba(mat, dbzTH = 10.0, areaTH=20):
169
+ # Create a copy of the matrix
170
+ mat1 = np.copy(mat)
171
+ rows, cols = mat1.shape
172
+
173
+ # Create binary mask based on threshold
174
+ mask = np.zeros((rows, cols), dtype=np.uint8)
175
+ for i in range(rows):
176
+ for j in range(cols):
177
+ if mat1[i, j] > dbzTH:
178
+ mask[i, j] = 1
179
+ # Simple 8-connectivity region labeling (flood fill algorithm)
180
+ labels = np.zeros((rows, cols), dtype=np.int32)
181
+ current_label = 1
182
+ region_areas = []
183
+ for i in range(rows):
184
+ for j in range(cols):
185
+ # If current pixel is foreground and not yet labeled
186
+ if mask[i, j] == 1 and labels[i, j] == 0:
187
+ # Start flood fill
188
+ stack = [(i, j)]
189
+ labels[i, j] = current_label
190
+ area = 0
191
+
192
+ while stack:
193
+ x, y = stack.pop()
194
+ area += 1
195
+
196
+ # Check 8 surrounding pixels
197
+ for dx in [-1, 0, 1]:
198
+ for dy in [-1, 0, 1]:
199
+ nx, ny = x + dx, y + dy
200
+ # Check bounds and conditions
201
+ if (0 <= nx < rows and 0 <= ny < cols and
202
+ mask[nx, ny] == 1 and labels[nx, ny] == 0):
203
+ labels[nx, ny] = current_label
204
+ stack.append((nx, ny))
205
+
206
+ region_areas.append(area)
207
+ current_label += 1
208
+
209
+ # Apply area threshold filtering
210
+ for i in range(rows):
211
+ for j in range(cols):
212
+ if labels[i, j] > 0 and region_areas[labels[i, j] - 1] < areaTH:
213
+ mat1[i, j] = 0
214
+ return mat1
215
+ def QC_ref_numba(mat, dbzTH = 10, areaTH=20):
216
+ for i in range(len(mat)):
217
+ mat[i] = QC_simple_numba(mat[i], dbzTH, areaTH)
218
+ return mat
219
+ """
220
+ CR = subset["CR"].data[0].copy()
221
+ CR[CR < 6] = 0
222
+ CR = QC_ref_numba(CR[None], areaTH=15)[0]
223
+ """
@@ -58,7 +58,7 @@ class goesProjMSG10():
58
58
  self.CFAC=FAC[resolution]
59
59
  self.LFAC=FAC[resolution]
60
60
 
61
- def transform(self,latD,lonDe,ROC=5,ROL=-30):
61
+ def transform(self,latD,lonDe,ROC=-10,ROL=-30):
62
62
  lat=np.radians(latD)
63
63
  lon=np.radians(lonDe)
64
64
  ba2=np.square(self.eb/self.ea)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: shancx
3
- Version: 1.9.33.176
3
+ Version: 1.9.33.178
4
4
  Summary: A simple timer decorator
5
5
  Home-page: https://gitee.com/shancx
6
6
  Author: shancx
@@ -1,69 +0,0 @@
1
- import cv2
2
- import numpy as np
3
- def removeSmallPatches(binary_mask, min_pixels=50, min_area=40):
4
- binary_mask = (binary_mask > 0).astype(np.uint8)
5
- num_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(
6
- binary_mask, connectivity=8
7
- )
8
- output_mask = np.zeros_like(binary_mask)
9
- for i in range(1, num_labels):
10
- pixel_count = stats[i, cv2.CC_STAT_AREA]
11
- if pixel_count < min_pixels:
12
- continue
13
- component_mask = (labels == i).astype(np.uint8)
14
- contours, _ = cv2.findContours(component_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
15
- if contours:
16
- contour = contours[0]
17
- area = cv2.contourArea(contour)
18
- if area < min_area:
19
- continue
20
- output_mask[labels == i] = 255
21
- return output_mask
22
-
23
- """
24
- mask = removeSmallPatches(b, min_pixels=50, min_area=40)
25
- data = np.where(mask, data, 0)
26
- filtered_data = np.full([256,256],0)
27
- filtered_data[mask] = e[mask]
28
- """
29
-
30
- import cv2
31
- import numpy as np
32
- from concurrent.futures import ThreadPoolExecutor
33
- def process_block_optimized(args):
34
- block, coords, min_pixels, min_area = args
35
- y, x, y_end, x_end = coords
36
- num_labels, labels, stats, _ = cv2.connectedComponentsWithStats(block, 8)
37
- result = np.zeros_like(block)
38
- valid_labels = []
39
- for i in range(1, num_labels):
40
- if stats[i, cv2.CC_STAT_AREA] >= min_pixels:
41
- valid_labels.append(i)
42
- for i in valid_labels:
43
- component_mask = (labels == i).astype(np.uint8)
44
- contours, _ = cv2.findContours(component_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
45
- if contours and cv2.contourArea(contours[0]) >= min_area:
46
- result[labels == i] = 255
47
- return result, coords
48
- def removeSmallPatches_fast(binary_mask, min_pixels=100, min_area=40, num_workers=3):
49
- binary_mask = (binary_mask > 0).astype(np.uint8)
50
- h, w = binary_mask.shape
51
- output = np.zeros_like(binary_mask)
52
- block_size = 2000
53
- blocks = []
54
- for y in range(0, h, block_size):
55
- for x in range(0, w, block_size):
56
- y_end, x_end = min(y+block_size, h), min(x+block_size, w)
57
- block = binary_mask[y:y_end, x:x_end]
58
- blocks.append((block, (y, x, y_end, x_end), min_pixels, min_area))
59
- with ThreadPoolExecutor(num_workers) as executor:
60
- for result, (y, x, y_end, x_end) in executor.map(process_block_optimized, blocks):
61
- output[y:y_end, x:x_end] = result
62
- return output
63
-
64
- """
65
- mask = removeSmallPatches(b, min_pixels=50, min_area=40)
66
- data = np.where(mask, data, 0)
67
- filtered_data = np.full([256,256],0)
68
- filtered_data[mask] = e[mask]
69
- """
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes