batoolset 0.1.0__py3-none-any.whl

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 (162) hide show
  1. batoolset/GUI/__init__.py +0 -0
  2. batoolset/GUI/list_gui.py +513 -0
  3. batoolset/GUI/multi_image_display.py +989 -0
  4. batoolset/GUI/open.py +325 -0
  5. batoolset/GUI/overlay_hints.py +45 -0
  6. batoolset/GUI/paint2.py +1345 -0
  7. batoolset/GUI/scrollablepaint.py +1152 -0
  8. batoolset/IJ_ROIs/__init__.py +0 -0
  9. batoolset/IJ_ROIs/tools.py +40 -0
  10. batoolset/PATH/__init__.py +0 -0
  11. batoolset/PATH/tools.py +79 -0
  12. batoolset/SQLite_tools/__init__.py +0 -0
  13. batoolset/SQLite_tools/tools.py +840 -0
  14. batoolset/__init__.py +0 -0
  15. batoolset/binary/__init__.py +0 -0
  16. batoolset/binary/tools.py +123 -0
  17. batoolset/binarytools/__init__.py +0 -0
  18. batoolset/binarytools/cell_center_detector.py +290 -0
  19. batoolset/clipboard_tools/__init__.py +0 -0
  20. batoolset/clipboard_tools/tools.py +7 -0
  21. batoolset/colors/__init__.py +0 -0
  22. batoolset/colors/colorgen.py +193 -0
  23. batoolset/colors/tools.py +22 -0
  24. batoolset/command_line/__init__.py +0 -0
  25. batoolset/command_line/tools.py +18 -0
  26. batoolset/dialogs/__init__.py +0 -0
  27. batoolset/dialogs/opensave.py +228 -0
  28. batoolset/dicts/__init__.py +0 -0
  29. batoolset/dicts/tools.py +299 -0
  30. batoolset/dims/__init__.py +0 -0
  31. batoolset/dims/tools.py +83 -0
  32. batoolset/draw/__init__.py +0 -0
  33. batoolset/draw/shapes/Position.py +183 -0
  34. batoolset/draw/shapes/__init__.py +0 -0
  35. batoolset/draw/shapes/automated_alignment_drawing_refactored.py +346 -0
  36. batoolset/draw/shapes/circle2d.py +99 -0
  37. batoolset/draw/shapes/compute_optimal_size_all_merged.py +317 -0
  38. batoolset/draw/shapes/ellipse2d.py +336 -0
  39. batoolset/draw/shapes/freehand2d.py +235 -0
  40. batoolset/draw/shapes/group.py +1830 -0
  41. batoolset/draw/shapes/image2d.py +2469 -0
  42. batoolset/draw/shapes/line2d.py +575 -0
  43. batoolset/draw/shapes/point2d.py +257 -0
  44. batoolset/draw/shapes/polygon2d.py +357 -0
  45. batoolset/draw/shapes/polyline2d.py +235 -0
  46. batoolset/draw/shapes/rect2d.py +388 -0
  47. batoolset/draw/shapes/rectangle2d.py +601 -0
  48. batoolset/draw/shapes/scalebar.py +304 -0
  49. batoolset/draw/shapes/serializablefont.py +126 -0
  50. batoolset/draw/shapes/serializableguiparams.py +10 -0
  51. batoolset/draw/shapes/square2d.py +103 -0
  52. batoolset/draw/shapes/textorientation.py +45 -0
  53. batoolset/draw/shapes/tools.py +467 -0
  54. batoolset/draw/shapes/transform2D.py +350 -0
  55. batoolset/draw/shapes/txt2d.py +550 -0
  56. batoolset/draw/widgets/__init__.py +0 -0
  57. batoolset/draw/widgets/col.py +343 -0
  58. batoolset/draw/widgets/image_group.py +248 -0
  59. batoolset/draw/widgets/image_organizer.py +96 -0
  60. batoolset/draw/widgets/paint.py +184 -0
  61. batoolset/draw/widgets/vectorial.py +257 -0
  62. batoolset/figure/__init__.py +0 -0
  63. batoolset/figure/alignment.py +814 -0
  64. batoolset/figure/column.py +1117 -0
  65. batoolset/figure/fig_tools.py +285 -0
  66. batoolset/figure/minimal_debugger_scale_etc.py +139 -0
  67. batoolset/figure/panel.py +697 -0
  68. batoolset/figure/row.py +852 -0
  69. batoolset/figure/user_selection.py +287 -0
  70. batoolset/files/__init__.py +0 -0
  71. batoolset/files/tools.py +1321 -0
  72. batoolset/images/__init__.py +0 -0
  73. batoolset/images/tools.py +81 -0
  74. batoolset/img.py +5216 -0
  75. batoolset/linux/__init__.py +0 -0
  76. batoolset/linux/tools.py +72 -0
  77. batoolset/lists/__init__.py +0 -0
  78. batoolset/lists/tools.py +436 -0
  79. batoolset/luts/__init__.py +0 -0
  80. batoolset/luts/lut_minimal_test.py +1207 -0
  81. batoolset/matplolib/__init__.py +0 -0
  82. batoolset/matplolib/tools.py +44 -0
  83. batoolset/np_tools/__init__.py +0 -0
  84. batoolset/np_tools/tools.py +252 -0
  85. batoolset/np_tools/trash.py +15 -0
  86. batoolset/pandas_tools/__init__.py +0 -0
  87. batoolset/pandas_tools/tools.py +880 -0
  88. batoolset/partials/__init__.py +0 -0
  89. batoolset/partials/tools.py +83 -0
  90. batoolset/plot_tools/__init__.py +0 -0
  91. batoolset/plot_tools/tools.py +70 -0
  92. batoolset/pyqt/__init__.py +0 -0
  93. batoolset/pyqt/tools.py +691 -0
  94. batoolset/re_tools/__init__.py +0 -0
  95. batoolset/re_tools/tools.py +35 -0
  96. batoolset/serialization/__init__.py +0 -0
  97. batoolset/serialization/tools.py +1192 -0
  98. batoolset/sets/__init__.py +0 -0
  99. batoolset/sets/tools.py +109 -0
  100. batoolset/settings/__init__.py +0 -0
  101. batoolset/settings/global_settings.py +134 -0
  102. batoolset/strings/__init__.py +0 -0
  103. batoolset/strings/tools.py +225 -0
  104. batoolset/ta/__init__.py +0 -0
  105. batoolset/ta/database/__init__.py +0 -0
  106. batoolset/ta/database/advanced_sql_plotter.py +1170 -0
  107. batoolset/ta/database/my_qt_table.py +79 -0
  108. batoolset/ta/database/preview_and_edit_sqlite_db.py +405 -0
  109. batoolset/ta/database/sql.py +2141 -0
  110. batoolset/ta/database/sql_column_name_dialog.py +122 -0
  111. batoolset/ta/measurements/TAmeasures.py +2226 -0
  112. batoolset/ta/measurements/__init__.py +0 -0
  113. batoolset/ta/measurements/measurements3D/__init__.py +0 -0
  114. batoolset/ta/measurements/measurements3D/get_point_on_surface_if_centroid_is_bad.py +175 -0
  115. batoolset/ta/measurements/measurements3D/height_map_to_projection.py +82 -0
  116. batoolset/ta/measurements/measurements3D/measures3D.py +208 -0
  117. batoolset/ta/measurements/measurements3D/triangulate.py +331 -0
  118. batoolset/ta/measurements/nematic.py +562 -0
  119. batoolset/ta/measurements/nematic_measurements.py +107 -0
  120. batoolset/ta/segmentation/__init__.py +0 -0
  121. batoolset/ta/segmentation/neo_wshed.py +314 -0
  122. batoolset/ta/selections/__init__.py +0 -0
  123. batoolset/ta/selections/selection.py +329 -0
  124. batoolset/ta/tracking/__init__.py +0 -0
  125. batoolset/ta/tracking/last_tracking_based_on_matching_or_on_translation_from_mermaid_warp.py +653 -0
  126. batoolset/ta/tracking/local_to_track_correspondance.py +138 -0
  127. batoolset/ta/tracking/rapid_detection_of_vertices.py +517 -0
  128. batoolset/ta/tracking/registration.py +108 -0
  129. batoolset/ta/tracking/swap_detector_and_fixer.py +296 -0
  130. batoolset/ta/tracking/track_correction.py +238 -0
  131. batoolset/ta/tracking/tracking_error_detector_and_fixer.py +3099 -0
  132. batoolset/ta/tracking/tracking_yet_another_approach_pyramidal_registration_n_neo_swapping_correction.py +725 -0
  133. batoolset/ta/utils/TA_tools.py +43 -0
  134. batoolset/ta/utils/__init__.py +0 -0
  135. batoolset/ta/utils/rps_tools.py +1783 -0
  136. batoolset/tests/__init__.py +0 -0
  137. batoolset/tests/rps_tools.py +51 -0
  138. batoolset/tests/tools.py +10 -0
  139. batoolset/tools/__init__.py +0 -0
  140. batoolset/tools/early_stopper_class.py +9 -0
  141. batoolset/tools/guided_data_recoverer.py +110 -0
  142. batoolset/tools/logger.py +100 -0
  143. batoolset/tools/mytimer.py +31 -0
  144. batoolset/tools/prompt_color.py +160 -0
  145. batoolset/tools/qthandler.py +118 -0
  146. batoolset/uitools/__init__.py +0 -0
  147. batoolset/uitools/blinker.py +56 -0
  148. batoolset/unsafe/__init__.py +0 -0
  149. batoolset/unsafe/tools.py +115 -0
  150. batoolset/utils/__init__.py +0 -0
  151. batoolset/utils/commontools.py +158 -0
  152. batoolset/utils/loadlist.py +728 -0
  153. batoolset/version.py +10 -0
  154. batoolset/xml/__init__.py +0 -0
  155. batoolset/xml/tools.py +65 -0
  156. batoolset/zip_tools/__init__.py +0 -0
  157. batoolset/zip_tools/tools.py +76 -0
  158. batoolset-0.1.0.dist-info/LICENSE +24 -0
  159. batoolset-0.1.0.dist-info/METADATA +45 -0
  160. batoolset-0.1.0.dist-info/RECORD +162 -0
  161. batoolset-0.1.0.dist-info/WHEEL +5 -0
  162. batoolset-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,350 @@
1
+ from batoolset.settings.global_settings import set_UI # set the UI to qtpy
2
+ set_UI()
3
+ from batoolset.draw.shapes.freehand2d import Freehand2D
4
+ from batoolset.draw.shapes.polyline2d import PolyLine2D
5
+ from batoolset.serialization.tools import clone_object
6
+ from qtpy.QtCore import QRectF, QPointF,QPoint
7
+ from qtpy.QtGui import QTransform, QPolygonF,QPolygon
8
+ import numpy as np
9
+ from batoolset.draw.shapes import polyline2d, freehand2d
10
+ from batoolset.draw.shapes.ellipse2d import Ellipse2D
11
+ from batoolset.draw.shapes.line2d import Line2D
12
+ from batoolset.draw.shapes.point2d import Point2D
13
+ from batoolset.draw.shapes.polygon2d import Polygon2D
14
+ from batoolset.draw.shapes.rectangle2d import Rectangle2D
15
+
16
+
17
+ def translated(shape, point):
18
+ # get the rotated
19
+
20
+ # if not centroid:
21
+ centroid = get_centroid(get_points(shape))
22
+
23
+ if isinstance(centroid, (QPointF, QPoint)):
24
+ centroid = (centroid.x(), centroid.y())
25
+
26
+ # new_centoid=
27
+ transform = Transform2D()
28
+ transform.translate(point[0], point[1])
29
+
30
+ print(centroid)
31
+
32
+ centroid = transform.apply(centroid)
33
+
34
+ print('after', centroid)
35
+
36
+ # then see how to return the modified shape
37
+ # whatever the shape I need to center it to some position
38
+ # and to clone it
39
+
40
+ clone = clone_object(shape)
41
+ # clone.theta = clone.theta+angle
42
+ # then I need to center the stuff
43
+ clone.set_to_center(centroid)
44
+
45
+ # in some cases I may need to do more crazy stuff
46
+
47
+ return clone
48
+
49
+ def rotated(shape, angle, centroid=None):
50
+ # get the rotated
51
+
52
+ if not centroid:
53
+ centroid = get_centroid(get_points(shape))
54
+
55
+ if isinstance(centroid, (QPointF, QPoint)):
56
+ centroid = (centroid.x(), centroid.y())
57
+
58
+ # new_centoid=
59
+ transform = Transform2D()
60
+ transform.translate(centroid[0], centroid[1])
61
+ transform.rotate(angle)
62
+ transform.translate(-centroid[0], -centroid[1])
63
+
64
+ centroid = transform.apply(centroid)
65
+ # then see how to return the modified shape
66
+ # whatever the shape I need to center it to some position
67
+ # and to clone it
68
+
69
+ clone = clone_object(shape)
70
+ clone.theta = clone.theta+angle
71
+ # then I need to center the stuff
72
+ clone.set_to_center(centroid)
73
+
74
+ # in some cases I may need to do more crazy stuff
75
+
76
+ return clone
77
+
78
+ def get_centroid(points):
79
+ """Calculate the centroid of a list of 2D points.
80
+
81
+ Args:
82
+ points (list of tuple): List of (x, y) points.
83
+
84
+ Returns:
85
+ tuple: The (x, y) coordinates of the centroid.
86
+ """
87
+ if not points:
88
+ raise ValueError("The list of points is empty.")
89
+
90
+ try:
91
+ x_coords = [p[0] for p in points]
92
+ y_coords = [p[1] for p in points]
93
+ except:
94
+ x_coords = [p.x() for p in points]
95
+ y_coords = [p.y() for p in points]
96
+
97
+ centroid_x = sum(x_coords) / len(points)
98
+ centroid_y = sum(y_coords) / len(points)
99
+
100
+ return centroid_x, centroid_y
101
+
102
+ def get_points(shape):
103
+
104
+ # TODO --> I could do that for all shapes
105
+ if isinstance(shape, QRectF):
106
+ """Get the corners/vertices of a QRectF.
107
+
108
+ Args:
109
+ rect (QRectF): The rectangle from which to get the corners.
110
+
111
+ Returns:
112
+ list of tuple: A list containing the corners (x, y).
113
+ """
114
+ top_left = (shape.topLeft().x(), shape.topLeft().y())
115
+ top_right = (shape.topRight().x(), shape.topRight().y())
116
+ bottom_left = (shape.bottomLeft().x(), shape.bottomLeft().y())
117
+ bottom_right = (shape.bottomRight().x(), shape.bottomRight().y())
118
+
119
+ return [top_left, top_right, bottom_left, bottom_right]
120
+ elif isinstance(shape, (QPolygon, QPolygonF, Polygon2D, PolyLine2D, Freehand2D)):
121
+ # print('entering')
122
+ vertices = []
123
+ for point in shape:
124
+ vertices.append((point.x(), point.y()))
125
+ if shape.first() == shape.last(): # if poly is closed --> remove the point
126
+ vertices=vertices[:-1]
127
+ return vertices
128
+ elif isinstance(shape,Point2D):
129
+ return [(shape.x(), shape.y())]
130
+ elif isinstance(shape,Line2D):
131
+ return [((shape.x1()+shape.x2())/2., (shape.y1()+shape.y2())/2.)]
132
+ elif isinstance(shape,Rectangle2D):
133
+ return [shape.top_left(), shape.top_right(), shape.bottom_left(), shape.bottom_right()]
134
+ elif isinstance(shape, Line2D):
135
+ return [(shape.x1(), shape.y1()), (shape.x2(), shape.y2())]
136
+ elif isinstance(shape, Line2D):
137
+ return [(shape.x1(), shape.y1()), (shape.x2(), shape.y2())]
138
+ # elif isinstance(shape, Ellipse2D): # probably need the rect
139
+ #
140
+
141
+ def get_bounding_rect(points, return_qrectf=False):
142
+ """Get the bounding rectangle of a list of 2D points.
143
+
144
+ Args:
145
+ points (list of tuple): List of (x, y) points.
146
+
147
+ Returns:
148
+ tuple: (min_x, min_y, max_x, max_y) representing the bounding rectangle.
149
+ """
150
+ if not points:
151
+ raise ValueError("The list of points is empty.")
152
+
153
+ # Initialize the min and max values with the first point
154
+ min_x, min_y = points[0]
155
+ max_x, max_y = points[0]
156
+
157
+ # Iterate over all points to find the min and max x and y values
158
+ for (x, y) in points:
159
+ if x < min_x:
160
+ min_x = x
161
+ if x > max_x:
162
+ max_x = x
163
+ if y < min_y:
164
+ min_y = y
165
+ if y > max_y:
166
+ max_y = y
167
+ if return_qrectf:
168
+ return QRectF(min_x, min_y, max_x-min_x, max_y-min_y)
169
+ return min_x, min_y, max_x, max_y
170
+
171
+
172
+ class Transform2D:
173
+ def __init__(self):
174
+ # Initialize with the identity matrix
175
+ self.matrix = np.identity(3)
176
+
177
+ def translate(self, tx, ty):
178
+ """Apply a translation by (tx, ty)."""
179
+ translation_matrix = np.array([
180
+ [1, 0, tx],
181
+ [0, 1, ty],
182
+ [0, 0, 1]
183
+ ])
184
+ self.matrix = np.dot(self.matrix, translation_matrix)
185
+ return self
186
+
187
+ def rotate(self, theta):
188
+ """Apply a rotation by theta degrees."""
189
+ radians = np.radians(theta)
190
+ cos_theta = np.cos(radians)
191
+ sin_theta = np.sin(radians)
192
+ rotation_matrix = np.array([
193
+ [cos_theta, -sin_theta, 0],
194
+ [sin_theta, cos_theta, 0],
195
+ [0, 0, 1]
196
+ ])
197
+ self.matrix = np.dot(self.matrix, rotation_matrix)
198
+ return self
199
+
200
+ def scale(self, sx, sy):
201
+ """Apply scaling by (sx, sy)."""
202
+ scale_matrix = np.array([
203
+ [sx, 0, 0],
204
+ [0, sy, 0],
205
+ [0, 0, 1]
206
+ ])
207
+ self.matrix = np.dot(self.matrix, scale_matrix)
208
+ return self
209
+
210
+ def apply(self, points, auto_unpack_if_single=True):
211
+ """Apply the transformation to a list of 2D points."""
212
+ if isinstance(points, tuple):
213
+ points=[points]
214
+ transformed_points = []
215
+ for point in points:
216
+ x, y = point
217
+ # Homogeneous coordinate vector
218
+ point_matrix = np.array([x, y, 1])
219
+ transformed_point = np.dot(self.matrix, point_matrix)
220
+ transformed_points.append((transformed_point[0], transformed_point[1]))
221
+ if auto_unpack_if_single and len(transformed_points)==1:
222
+ return transformed_points[0]
223
+ return transformed_points
224
+
225
+ def reset(self):
226
+ """Reset the transformation matrix to the identity matrix."""
227
+ self.matrix = np.identity(3)
228
+ return self
229
+
230
+ def get_matrix(self):
231
+ """Get the current transformation matrix."""
232
+ return self.matrix
233
+
234
+
235
+
236
+
237
+
238
+ if __name__ == '__main__':
239
+
240
+
241
+ # Example usage
242
+ transform = Transform2D()
243
+ transform.translate(2, 3).rotate(45).scale(2, 2)
244
+ points = [(1, 1), (2, 2), (3, 3)]
245
+ transformed_points = transform.apply(points)
246
+ print("Transformed Points:", transformed_points)
247
+ print("Transformation Matrix:\n", transform.get_matrix())
248
+
249
+
250
+ transform = Transform2D()
251
+ transform.translate(-10,10).translate(10,-10)
252
+ print(transform.apply(points)) # does not work
253
+ print("Transformation Matrix:\n", transform.get_matrix())
254
+
255
+ # now implement that for squares and other shapes --> TODO
256
+ # very good that works
257
+ transform = Transform2D()
258
+ transform.translate(0, 0).translate(1,-1)
259
+ print(transform.apply(points)) # does not work
260
+ print("Transformation Matrix:\n", transform.get_matrix())
261
+
262
+ # points = [(10,20), (200+10,300+20), (210,20), (10, 320)]
263
+ rect = QRectF(10,20,200, 300)
264
+ points = get_points(rect)
265
+ print('points',points)
266
+ print('get_centroid',get_centroid(points))
267
+ center = rect.center()
268
+ points.append((center.x(),center.y()))
269
+
270
+ print(center)
271
+ transform = Transform2D()
272
+ transform.translate(center.x(),center.y())
273
+ transform.rotate(45)
274
+ transform.translate(-center.x(),-center.y())
275
+
276
+ print(transform.apply(points))
277
+
278
+
279
+ qtrafo = QTransform()
280
+ qtrafo.translate(center.x(), center.y())
281
+ qtrafo.rotate(45)
282
+ qtrafo.translate(-center.x(), -center.y())
283
+
284
+ print(qtrafo.map(10,20))
285
+ print(qtrafo.map(210,320))
286
+ print(qtrafo.map(center.x(),center.y()))
287
+
288
+ # Example usage
289
+ # points = [(1, 1), (2, 2), (3, 3), (-1, -1), (4, 0)]
290
+ bounding_rect = get_bounding_rect(points)
291
+ print("Bounding Rectangle:", bounding_rect)
292
+
293
+ # is that really correct --> looks like there is a bug!!!
294
+
295
+ print(get_bounding_rect(transform.apply(points)))
296
+ print(qtrafo.mapRect(rect)) # la sortie est pas du tout la meme
297
+
298
+
299
+ print(get_bounding_rect(transform.apply(points), return_qrectf=True)) # no it's ok but I really need the four corner to get the real bounding rect
300
+ # and then that works perfectly
301
+
302
+ polygon = QPolygonF([QPointF(0, 0), QPointF(1, 1), QPointF(2, 0), QPointF(1, -1)])
303
+ print(polygon.isClosed())
304
+ vertices = get_points(polygon)
305
+ print(vertices)
306
+ if polygon.first() != polygon.last():
307
+ polygon.append(polygon.first())
308
+ vertices = get_points(polygon)
309
+ print(vertices)
310
+
311
+ # what is map rect doing in fact
312
+ # the map rect seems to work though
313
+
314
+ vertices2 = []
315
+ for vx in vertices:
316
+ vertices2.append(vx[0])
317
+ vertices2.append(vx[1])
318
+ print(len(vertices2))
319
+ # poly = Polygon2D(*vertices2)
320
+ p2d = Polygon2D(*vertices)
321
+
322
+ print(get_points(p2d))
323
+
324
+
325
+ print('p2d rot',rotated(p2d, 45).listVertices()) # pb is that it creates super minor rounding errors but maybe still ok!!!
326
+ print('p2d rot',rotated(p2d, 45,(256,256)).listVertices()) # pb is that it creates super minor rounding errors but maybe still ok!!!
327
+
328
+
329
+ # maybe that works
330
+ # just try it maybe
331
+
332
+ r2d = Rectangle2D(0,0,256,516)
333
+ print('rect rot',rotated(r2d, 90).boundingRect())
334
+ print('rect rot',rotated(r2d, 90,(256,256)).boundingRect())
335
+
336
+ print('dab', r2d.x(), r2d.y(), r2d.width(), r2d.height())
337
+
338
+
339
+ print(r2d.boundingRect().center(), 'vs',get_centroid(get_points(r2d)), get_points(r2d))
340
+ trans = translated(r2d,(10,25))
341
+ print('dab',trans.x(),trans.y(), trans.width(), trans.height(), trans.boundingRect())
342
+ # --> à tester --> mais peut etre ok --> dessiner ttes les shapes tournées dans le truc # see if I can chain things or not ???
343
+
344
+ # bug
345
+
346
+ el2d = Ellipse2D(0,0,256,512)
347
+ trans =translated(r2d, (10, 25))
348
+ print(trans.x(),trans.y(), trans.width(), trans.height()) # --> ok it seems
349
+
350
+ # TODO --> maybe try all for real now