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.
- batoolset/GUI/__init__.py +0 -0
- batoolset/GUI/list_gui.py +513 -0
- batoolset/GUI/multi_image_display.py +989 -0
- batoolset/GUI/open.py +325 -0
- batoolset/GUI/overlay_hints.py +45 -0
- batoolset/GUI/paint2.py +1345 -0
- batoolset/GUI/scrollablepaint.py +1152 -0
- batoolset/IJ_ROIs/__init__.py +0 -0
- batoolset/IJ_ROIs/tools.py +40 -0
- batoolset/PATH/__init__.py +0 -0
- batoolset/PATH/tools.py +79 -0
- batoolset/SQLite_tools/__init__.py +0 -0
- batoolset/SQLite_tools/tools.py +840 -0
- batoolset/__init__.py +0 -0
- batoolset/binary/__init__.py +0 -0
- batoolset/binary/tools.py +123 -0
- batoolset/binarytools/__init__.py +0 -0
- batoolset/binarytools/cell_center_detector.py +290 -0
- batoolset/clipboard_tools/__init__.py +0 -0
- batoolset/clipboard_tools/tools.py +7 -0
- batoolset/colors/__init__.py +0 -0
- batoolset/colors/colorgen.py +193 -0
- batoolset/colors/tools.py +22 -0
- batoolset/command_line/__init__.py +0 -0
- batoolset/command_line/tools.py +18 -0
- batoolset/dialogs/__init__.py +0 -0
- batoolset/dialogs/opensave.py +228 -0
- batoolset/dicts/__init__.py +0 -0
- batoolset/dicts/tools.py +299 -0
- batoolset/dims/__init__.py +0 -0
- batoolset/dims/tools.py +83 -0
- batoolset/draw/__init__.py +0 -0
- batoolset/draw/shapes/Position.py +183 -0
- batoolset/draw/shapes/__init__.py +0 -0
- batoolset/draw/shapes/automated_alignment_drawing_refactored.py +346 -0
- batoolset/draw/shapes/circle2d.py +99 -0
- batoolset/draw/shapes/compute_optimal_size_all_merged.py +317 -0
- batoolset/draw/shapes/ellipse2d.py +336 -0
- batoolset/draw/shapes/freehand2d.py +235 -0
- batoolset/draw/shapes/group.py +1830 -0
- batoolset/draw/shapes/image2d.py +2469 -0
- batoolset/draw/shapes/line2d.py +575 -0
- batoolset/draw/shapes/point2d.py +257 -0
- batoolset/draw/shapes/polygon2d.py +357 -0
- batoolset/draw/shapes/polyline2d.py +235 -0
- batoolset/draw/shapes/rect2d.py +388 -0
- batoolset/draw/shapes/rectangle2d.py +601 -0
- batoolset/draw/shapes/scalebar.py +304 -0
- batoolset/draw/shapes/serializablefont.py +126 -0
- batoolset/draw/shapes/serializableguiparams.py +10 -0
- batoolset/draw/shapes/square2d.py +103 -0
- batoolset/draw/shapes/textorientation.py +45 -0
- batoolset/draw/shapes/tools.py +467 -0
- batoolset/draw/shapes/transform2D.py +350 -0
- batoolset/draw/shapes/txt2d.py +550 -0
- batoolset/draw/widgets/__init__.py +0 -0
- batoolset/draw/widgets/col.py +343 -0
- batoolset/draw/widgets/image_group.py +248 -0
- batoolset/draw/widgets/image_organizer.py +96 -0
- batoolset/draw/widgets/paint.py +184 -0
- batoolset/draw/widgets/vectorial.py +257 -0
- batoolset/figure/__init__.py +0 -0
- batoolset/figure/alignment.py +814 -0
- batoolset/figure/column.py +1117 -0
- batoolset/figure/fig_tools.py +285 -0
- batoolset/figure/minimal_debugger_scale_etc.py +139 -0
- batoolset/figure/panel.py +697 -0
- batoolset/figure/row.py +852 -0
- batoolset/figure/user_selection.py +287 -0
- batoolset/files/__init__.py +0 -0
- batoolset/files/tools.py +1321 -0
- batoolset/images/__init__.py +0 -0
- batoolset/images/tools.py +81 -0
- batoolset/img.py +5216 -0
- batoolset/linux/__init__.py +0 -0
- batoolset/linux/tools.py +72 -0
- batoolset/lists/__init__.py +0 -0
- batoolset/lists/tools.py +436 -0
- batoolset/luts/__init__.py +0 -0
- batoolset/luts/lut_minimal_test.py +1207 -0
- batoolset/matplolib/__init__.py +0 -0
- batoolset/matplolib/tools.py +44 -0
- batoolset/np_tools/__init__.py +0 -0
- batoolset/np_tools/tools.py +252 -0
- batoolset/np_tools/trash.py +15 -0
- batoolset/pandas_tools/__init__.py +0 -0
- batoolset/pandas_tools/tools.py +880 -0
- batoolset/partials/__init__.py +0 -0
- batoolset/partials/tools.py +83 -0
- batoolset/plot_tools/__init__.py +0 -0
- batoolset/plot_tools/tools.py +70 -0
- batoolset/pyqt/__init__.py +0 -0
- batoolset/pyqt/tools.py +691 -0
- batoolset/re_tools/__init__.py +0 -0
- batoolset/re_tools/tools.py +35 -0
- batoolset/serialization/__init__.py +0 -0
- batoolset/serialization/tools.py +1192 -0
- batoolset/sets/__init__.py +0 -0
- batoolset/sets/tools.py +109 -0
- batoolset/settings/__init__.py +0 -0
- batoolset/settings/global_settings.py +134 -0
- batoolset/strings/__init__.py +0 -0
- batoolset/strings/tools.py +225 -0
- batoolset/ta/__init__.py +0 -0
- batoolset/ta/database/__init__.py +0 -0
- batoolset/ta/database/advanced_sql_plotter.py +1170 -0
- batoolset/ta/database/my_qt_table.py +79 -0
- batoolset/ta/database/preview_and_edit_sqlite_db.py +405 -0
- batoolset/ta/database/sql.py +2141 -0
- batoolset/ta/database/sql_column_name_dialog.py +122 -0
- batoolset/ta/measurements/TAmeasures.py +2226 -0
- batoolset/ta/measurements/__init__.py +0 -0
- batoolset/ta/measurements/measurements3D/__init__.py +0 -0
- batoolset/ta/measurements/measurements3D/get_point_on_surface_if_centroid_is_bad.py +175 -0
- batoolset/ta/measurements/measurements3D/height_map_to_projection.py +82 -0
- batoolset/ta/measurements/measurements3D/measures3D.py +208 -0
- batoolset/ta/measurements/measurements3D/triangulate.py +331 -0
- batoolset/ta/measurements/nematic.py +562 -0
- batoolset/ta/measurements/nematic_measurements.py +107 -0
- batoolset/ta/segmentation/__init__.py +0 -0
- batoolset/ta/segmentation/neo_wshed.py +314 -0
- batoolset/ta/selections/__init__.py +0 -0
- batoolset/ta/selections/selection.py +329 -0
- batoolset/ta/tracking/__init__.py +0 -0
- batoolset/ta/tracking/last_tracking_based_on_matching_or_on_translation_from_mermaid_warp.py +653 -0
- batoolset/ta/tracking/local_to_track_correspondance.py +138 -0
- batoolset/ta/tracking/rapid_detection_of_vertices.py +517 -0
- batoolset/ta/tracking/registration.py +108 -0
- batoolset/ta/tracking/swap_detector_and_fixer.py +296 -0
- batoolset/ta/tracking/track_correction.py +238 -0
- batoolset/ta/tracking/tracking_error_detector_and_fixer.py +3099 -0
- batoolset/ta/tracking/tracking_yet_another_approach_pyramidal_registration_n_neo_swapping_correction.py +725 -0
- batoolset/ta/utils/TA_tools.py +43 -0
- batoolset/ta/utils/__init__.py +0 -0
- batoolset/ta/utils/rps_tools.py +1783 -0
- batoolset/tests/__init__.py +0 -0
- batoolset/tests/rps_tools.py +51 -0
- batoolset/tests/tools.py +10 -0
- batoolset/tools/__init__.py +0 -0
- batoolset/tools/early_stopper_class.py +9 -0
- batoolset/tools/guided_data_recoverer.py +110 -0
- batoolset/tools/logger.py +100 -0
- batoolset/tools/mytimer.py +31 -0
- batoolset/tools/prompt_color.py +160 -0
- batoolset/tools/qthandler.py +118 -0
- batoolset/uitools/__init__.py +0 -0
- batoolset/uitools/blinker.py +56 -0
- batoolset/unsafe/__init__.py +0 -0
- batoolset/unsafe/tools.py +115 -0
- batoolset/utils/__init__.py +0 -0
- batoolset/utils/commontools.py +158 -0
- batoolset/utils/loadlist.py +728 -0
- batoolset/version.py +10 -0
- batoolset/xml/__init__.py +0 -0
- batoolset/xml/tools.py +65 -0
- batoolset/zip_tools/__init__.py +0 -0
- batoolset/zip_tools/tools.py +76 -0
- batoolset-0.1.0.dist-info/LICENSE +24 -0
- batoolset-0.1.0.dist-info/METADATA +45 -0
- batoolset-0.1.0.dist-info/RECORD +162 -0
- batoolset-0.1.0.dist-info/WHEEL +5 -0
- batoolset-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
# this class will be used to triangulate a cell in order to compute its 3D properties such as area
|
|
2
|
+
import random
|
|
3
|
+
|
|
4
|
+
from scipy.spatial import Delaunay
|
|
5
|
+
from skimage.draw import polygon_perimeter
|
|
6
|
+
|
|
7
|
+
from batoolset.img import Img, RGB_to_int24
|
|
8
|
+
|
|
9
|
+
from batoolset.ta.measurements.measurements3D.get_point_on_surface_if_centroid_is_bad import point_on_surface
|
|
10
|
+
from batoolset.ta.measurements.measurements3D.measures3D import compute_3D_surfacearea
|
|
11
|
+
from batoolset.ta.tracking.rapid_detection_of_vertices import detect_vertices_and_bonds, associate_vertices_to_cells
|
|
12
|
+
import numpy as np
|
|
13
|
+
import matplotlib.pyplot as plt
|
|
14
|
+
from skimage.measure import regionprops
|
|
15
|
+
from skimage import measure
|
|
16
|
+
import traceback
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# print(unprocessed_clone.shape)
|
|
20
|
+
# labels = label(RGB_to_int24(unprocessed_clone), connectivity=1, background=0xFFFFFF)
|
|
21
|
+
# vertices = detect_vertices_and_bonds(labels)
|
|
22
|
+
|
|
23
|
+
# check what I really need and add it there
|
|
24
|
+
# instead of region I could have the coords of the image
|
|
25
|
+
|
|
26
|
+
# is there a way to make it generic for cells and for clones --> think about it --> probably yes by just using the coords
|
|
27
|
+
# maybe check there is a single ID below
|
|
28
|
+
#
|
|
29
|
+
# coords_etdited = region.coords.tolist()
|
|
30
|
+
# coords_etdited.append(region.centroid)
|
|
31
|
+
#
|
|
32
|
+
# verts = np.where((vertices == 255) & (
|
|
33
|
+
# clone_id == cell.label)) # if image has too many labels then use that if there are several clones inside the stuff
|
|
34
|
+
#
|
|
35
|
+
# tmpsss = np.zeros_like(labels)
|
|
36
|
+
# tmpsss[verts] = 255
|
|
37
|
+
# plt.imshow(tmpsss)
|
|
38
|
+
# plt.show()
|
|
39
|
+
#
|
|
40
|
+
# verts = list(zip(verts[0], verts[1]))
|
|
41
|
+
# # print(np.where(vertices == 255))
|
|
42
|
+
# coords_etdited.extend(verts)
|
|
43
|
+
# # coords_etdited = verts
|
|
44
|
+
#
|
|
45
|
+
# coords_etdited = np.asarray(coords_etdited)
|
|
46
|
+
|
|
47
|
+
# this is for filtering of the coords --> I could keep a light version of this in fact --> just make it generic
|
|
48
|
+
|
|
49
|
+
# from shapely.geometry import Polygon
|
|
50
|
+
#
|
|
51
|
+
# for triangle in triangles:
|
|
52
|
+
# centroid_y, centroid_x = sum(triangle) / len(triangle)
|
|
53
|
+
#
|
|
54
|
+
# # print('me', centroid_y, centroid_x)
|
|
55
|
+
# if clone_id[int(centroid_y), int(centroid_x)] == cell.label:
|
|
56
|
+
# poly = Polygon(triangle)
|
|
57
|
+
#
|
|
58
|
+
# plt.plot(*poly.exterior.xy)
|
|
59
|
+
#
|
|
60
|
+
# # parfait --> maintenant voir comment faire ça mieux et si je peux utiliser shapely ou pas ???
|
|
61
|
+
#
|
|
62
|
+
# # figure()
|
|
63
|
+
# # axis('equal')
|
|
64
|
+
# # plot(coords_etdited[:, 0], coords_etdited[:, 1], '.')
|
|
65
|
+
# # for i, j in edges:
|
|
66
|
+
# # plot(coords_etdited[[i, j], 0], coords_etdited[[i, j], 1])
|
|
67
|
+
# # plt.triplot(coords_etdited[:, 0], coords_etdited[:, 1], tris)
|
|
68
|
+
# plt.show()
|
|
69
|
+
|
|
70
|
+
# labels, vertices,
|
|
71
|
+
def triangulate(coords_to_triangulate, triangulated_object_ID=None, labels_to_check=None):
|
|
72
|
+
# TODO export all these triangulations so that they are more simply done
|
|
73
|
+
# nb triangulation would be simpler if using just the vertices instead of the full contour --> maybe rely on vertices also for the edges and that is simple to do in a way
|
|
74
|
+
# all this triangulation is only useful provided the image is 3D/has heightmap because otherwise the metrics are much simpler to handle
|
|
75
|
+
# print('oubsi qsdsqdqsdqsd q')
|
|
76
|
+
|
|
77
|
+
# this is slow here so it must be done once and much before in fact!!!
|
|
78
|
+
|
|
79
|
+
# ça marche pas non plus faut vraiment plus de points
|
|
80
|
+
|
|
81
|
+
# plt.imshow(cells2)
|
|
82
|
+
# plt.show()
|
|
83
|
+
|
|
84
|
+
# plt.imshow(vertices)
|
|
85
|
+
# plt.show()
|
|
86
|
+
# ça marche --> essayer d'ajouter des vertices
|
|
87
|
+
|
|
88
|
+
tri = Delaunay(coords_to_triangulate)
|
|
89
|
+
triangles = coords_to_triangulate[tri.vertices]
|
|
90
|
+
|
|
91
|
+
# TODO also need compute the 3D area of the shape
|
|
92
|
+
|
|
93
|
+
# print(triangles)
|
|
94
|
+
|
|
95
|
+
# Polygon([(3.0, 0.0), (2.0, 0.0), (2.0, 0.75), (2.5, 0.75), (2.5, 0.6), (2.25, 0.6), (2.25, 0.2), (3.0, 0.2),
|
|
96
|
+
# (3.0, 0.0)])
|
|
97
|
+
|
|
98
|
+
# ça marche par contre bug si inner hole --> faudrait faire qq chose de plus smart en fait
|
|
99
|
+
# --> en fait devrait pas arriver --> en fait just warner l'utilisateur
|
|
100
|
+
# sinon checker les triangles par rapport à l'image originale en fait c'est facile dans mon cas les points des interbonds doivent se trouver dans le clone --> pas trop dur en fait
|
|
101
|
+
# mieux le centroid du triangle doit se trouver dans le clone et ça c'est vraimet super facile à faire et en plus j'ai pas besoin de truc compliques --> 100 % codable en python et TA compat à 100%
|
|
102
|
+
|
|
103
|
+
# indices_to_delete
|
|
104
|
+
|
|
105
|
+
# TODO check this code and verify how generic it is!!!
|
|
106
|
+
if labels_to_check is not None and triangulated_object_ID is not None:
|
|
107
|
+
# print('entering delete phase', triangles.shape)
|
|
108
|
+
indices_to_delete = []
|
|
109
|
+
for iii, triangle in enumerate(triangles):
|
|
110
|
+
centroid_y, centroid_x = sum(triangle) / len(triangle)
|
|
111
|
+
|
|
112
|
+
# print('me', centroid_y, centroid_x)
|
|
113
|
+
# can I do it more smartly ??? using another ID
|
|
114
|
+
if labels_to_check[int(centroid_y), int(centroid_x)] != triangulated_object_ID:
|
|
115
|
+
# poly = Polygon(triangle)
|
|
116
|
+
|
|
117
|
+
# plt.plot(*poly.exterior.xy)
|
|
118
|
+
|
|
119
|
+
# parfait --> maintenant voir comment faire ça mieux et si je peux utiliser shapely ou pas ???
|
|
120
|
+
|
|
121
|
+
# can I delete it
|
|
122
|
+
indices_to_delete.append(iii)
|
|
123
|
+
|
|
124
|
+
# print('indices_to_delete',indices_to_delete) # --> ok --> seems to work
|
|
125
|
+
# ça marche bien ça --> à réutiliser!!!
|
|
126
|
+
triangles = np.delete(triangles, indices_to_delete, axis=0)
|
|
127
|
+
|
|
128
|
+
# print('after delete', triangles.shape)
|
|
129
|
+
# check if that work
|
|
130
|
+
|
|
131
|
+
return triangles
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
# if image is not plot as shapely if not then plot on the image --> very good idea
|
|
135
|
+
# TODO allow maybe fill and chose a color or generate random colors as in TA !!! --> would be a very good idea and that would make my life easier!!!
|
|
136
|
+
def plot_triangulation(triangles, img_to_plot_triangles_over=None):
|
|
137
|
+
if img_to_plot_triangles_over is None:
|
|
138
|
+
from shapely.geometry import Polygon
|
|
139
|
+
for triangle in triangles:
|
|
140
|
+
poly = Polygon(triangle)
|
|
141
|
+
plt.plot(*poly.exterior.xy)
|
|
142
|
+
plt.axis('equal')
|
|
143
|
+
plt.show()
|
|
144
|
+
else:
|
|
145
|
+
for triangle in triangles:
|
|
146
|
+
r = triangle[:, 0] # get the y coords of the simplex
|
|
147
|
+
c = triangle[:, 1] # get the x coords of the simplex
|
|
148
|
+
|
|
149
|
+
# print(np.asarray(r))
|
|
150
|
+
# print(c)
|
|
151
|
+
|
|
152
|
+
# TODO maybe plot the poygon and its contour too
|
|
153
|
+
rr, cc = polygon_perimeter(r, c, shape=img_to_plot_triangles_over.shape)
|
|
154
|
+
|
|
155
|
+
# print(rr, cc)
|
|
156
|
+
#
|
|
157
|
+
# print(type(rr), print(rr.dtype), rr.shape)
|
|
158
|
+
# print(rr)
|
|
159
|
+
img_to_plot_triangles_over[rr, cc] = random.randint(128,255) # not bad
|
|
160
|
+
return img_to_plot_triangles_over
|
|
161
|
+
|
|
162
|
+
if __name__ == '__main__':
|
|
163
|
+
|
|
164
|
+
# everything is fine --> just need finalize the thing and also measure the area and things like that
|
|
165
|
+
# also find a way to order pixels and get the perimeter right
|
|
166
|
+
# si > sqrt 2 alors need a connection --> put this as a section and try connect to first or last of every list --> maybe not so hard to implement and in the end all the points should be connected but try on a real example !!!
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
# TODO !!!
|
|
170
|
+
|
|
171
|
+
# do several tests
|
|
172
|
+
# do tests with classical cells and with clones just to see how it behaves
|
|
173
|
+
if True:
|
|
174
|
+
# cell triangulation test
|
|
175
|
+
# get any image with cells get vertices for cells
|
|
176
|
+
# get centroid if inside the cell or a random point
|
|
177
|
+
# launch the triangulation and display it
|
|
178
|
+
|
|
179
|
+
CHECK_CONCAVE_CELLS_TRIANGULATION = True # maybe not really necessary for epithelial cells but really key for clones
|
|
180
|
+
|
|
181
|
+
cells = Img('/E/Sample_images/sample_images_PA/mini/focused_Series012/tracked_cells_resized.png')
|
|
182
|
+
cells = RGB_to_int24(cells)
|
|
183
|
+
vertices = detect_vertices_and_bonds(cells)
|
|
184
|
+
vertices = np.where(vertices == 255)
|
|
185
|
+
t0_cells_n_vertices = associate_vertices_to_cells(cells, vertices, forbidden_colors=(0, 0xFFFFFF))
|
|
186
|
+
# now for every cell do the triangulation
|
|
187
|
+
# --> TODO
|
|
188
|
+
labels = measure.label(cells, connectivity=1, background=0xFFFFFF) # FOUR_CONNECTED
|
|
189
|
+
# plt.imshow(labels)
|
|
190
|
+
# plt.show()
|
|
191
|
+
counter = 0
|
|
192
|
+
out = np.zeros_like(cells)
|
|
193
|
+
|
|
194
|
+
for region in regionprops(labels):
|
|
195
|
+
# region.bbox
|
|
196
|
+
# counter += 1
|
|
197
|
+
# if counter == 60:
|
|
198
|
+
cell_ID = cells[region.coords[0][0], region.coords[0][1]]
|
|
199
|
+
# region.coords
|
|
200
|
+
# print(type(np.asarray(t0_cells_n_vertices[cell_ID])))
|
|
201
|
+
# print(type(region.coords))
|
|
202
|
+
|
|
203
|
+
try:
|
|
204
|
+
|
|
205
|
+
points_for_triangulation = t0_cells_n_vertices[cell_ID] # why not all the cells are also entered in there --> do I have a bug and if so where ???
|
|
206
|
+
# if centroid is in the cell --> add it to the cells and that would be ok!!! otherwise take a random point in the cell
|
|
207
|
+
points_for_triangulation.append(point_on_surface(region, labels))
|
|
208
|
+
except:
|
|
209
|
+
traceback.print_exc()
|
|
210
|
+
print('no vertices detected for this cell! --> need fix the algorithm')
|
|
211
|
+
# --> indeed it fails at detecting cells at the edges!!! -> need fix that --> see how I was doing that in TA and do the same here
|
|
212
|
+
continue
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
try:
|
|
216
|
+
if not CHECK_CONCAVE_CELLS_TRIANGULATION:
|
|
217
|
+
triangles = triangulate(np.asarray(points_for_triangulation))
|
|
218
|
+
else:
|
|
219
|
+
triangles = triangulate(np.asarray(points_for_triangulation),triangulated_object_ID=cell_ID, labels_to_check=cells)
|
|
220
|
+
|
|
221
|
+
plot_triangulation(triangles, out)
|
|
222
|
+
except:
|
|
223
|
+
traceback.print_exc()
|
|
224
|
+
print('failed for cell', region.area,
|
|
225
|
+
region.bbox) # area 64 but not enough vertices --> I probably have a bug in my vertices code --> TODO --> fix that --> most likely at the edges
|
|
226
|
+
# TODO fix the algo
|
|
227
|
+
|
|
228
|
+
# print(triangles)
|
|
229
|
+
# break
|
|
230
|
+
plt.imshow(out)
|
|
231
|
+
plt.show()
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
if False:
|
|
236
|
+
|
|
237
|
+
from personal.pyTA.clones.clone_fuser import get_clone_contour
|
|
238
|
+
heightmap = None # but for a real case this must be done
|
|
239
|
+
|
|
240
|
+
# triangulate a clone
|
|
241
|
+
# clone = Img('/E/Sample_images/sample_images_PA/mini/focused_Series012/tracked_clone.tif')
|
|
242
|
+
# clone = Img('/E/Sample_images/sample_images_PA/mini/focused_Series012/tracked_clone_003.png')
|
|
243
|
+
# clone = Img('/E/Sample_images/sample_images_PA/mini/focused_Series012/tracked_clone.png')
|
|
244
|
+
clone = Img('/E/Sample_images/sample_images_PA/mini/focused_Series012/tracked_clone_001.png')
|
|
245
|
+
# ça marche super --> mettre ce code de partout!!!
|
|
246
|
+
|
|
247
|
+
clone_id, clone_contour = get_clone_contour(fused_clone=None, unprocessed_clone=clone,
|
|
248
|
+
return_clone_id=True)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
# print(clone.shape)
|
|
252
|
+
# nb can I use that also for clones ???
|
|
253
|
+
|
|
254
|
+
# both are ok
|
|
255
|
+
if False:
|
|
256
|
+
plt.imshow(clone_id)
|
|
257
|
+
plt.show()
|
|
258
|
+
|
|
259
|
+
plt.imshow(clone_contour)
|
|
260
|
+
plt.show()
|
|
261
|
+
|
|
262
|
+
clone = RGB_to_int24(clone)
|
|
263
|
+
cell_labels = measure.label(clone, connectivity=1, background=0xFFFFFF)
|
|
264
|
+
#
|
|
265
|
+
vertices = detect_vertices_and_bonds(cell_labels)
|
|
266
|
+
|
|
267
|
+
# ce truc est ok
|
|
268
|
+
if False:
|
|
269
|
+
plt.imshow(vertices)
|
|
270
|
+
plt.show()
|
|
271
|
+
|
|
272
|
+
# why no cells here --> see what the pb is I must have a bug in my code somewhere though
|
|
273
|
+
|
|
274
|
+
# du coup ça ne marche pas ici
|
|
275
|
+
t0_cells_n_vertices = associate_vertices_to_cells(clone_id, vertices, forbidden_colors=(0, 0xFFFFFF))
|
|
276
|
+
|
|
277
|
+
# print(t0_cells_n_vertices) # pourtant c'est bon --> j'ai une tonne de vx pr la cellule --> pkoi pas trouvée alors
|
|
278
|
+
|
|
279
|
+
# get the clone and try to triangulate it, then I'll be done !!!
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
# labels = measure.label(clone, connectivity=1, background=0xFFFFFF) # FOUR_CONNECTED
|
|
283
|
+
out = np.zeros_like(clone_id)
|
|
284
|
+
|
|
285
|
+
for region in regionprops(clone_id):
|
|
286
|
+
# region.bbox
|
|
287
|
+
# counter += 1
|
|
288
|
+
# if counter == 60:
|
|
289
|
+
cell_ID = clone_id[region.coords[0][0], region.coords[0][1]]
|
|
290
|
+
# region.coords
|
|
291
|
+
# print(type(np.asarray(t0_cells_n_vertices[cell_ID])))
|
|
292
|
+
# print(type(region.coords))
|
|
293
|
+
|
|
294
|
+
try:
|
|
295
|
+
|
|
296
|
+
points_for_triangulation = t0_cells_n_vertices[
|
|
297
|
+
cell_ID] # why not all the cells are also entered in there --> do I have a bug and if so where ???
|
|
298
|
+
# if centroid is in the cell --> add it to the cells and that would be ok!!! otherwise take a random point in the cell
|
|
299
|
+
# here that may even be smart to add the centoid of all cells contained in the clone --> TODO because smart
|
|
300
|
+
points_for_triangulation.append(point_on_surface(region, labels))
|
|
301
|
+
except:
|
|
302
|
+
traceback.print_exc()
|
|
303
|
+
print('no vertices detected for this cell2! --> need fix the algorithm')
|
|
304
|
+
# --> indeed it fails at detecting cells at the edges!!! -> need fix that --> see how I was doing that in TA and do the same here
|
|
305
|
+
continue
|
|
306
|
+
|
|
307
|
+
try:
|
|
308
|
+
# there is a bug in there dunno where
|
|
309
|
+
triangles = triangulate(np.asarray(points_for_triangulation), triangulated_object_ID=cell_ID, labels_to_check=clone_id) # need filter the triangulation for concave shapes of clones which is very frequent
|
|
310
|
+
|
|
311
|
+
# make it measure the 3D area of the clone --> TODO
|
|
312
|
+
print('area cell', cell_ID, compute_3D_surfacearea(triangles, heightmap=heightmap)) # --> ça marche enfin on dirait! --> cool
|
|
313
|
+
|
|
314
|
+
plot_triangulation(triangles, out)
|
|
315
|
+
except:
|
|
316
|
+
traceback.print_exc()
|
|
317
|
+
print('failed for cell2', region.area,
|
|
318
|
+
region.bbox) # area 64 but not enough vertices --> I probably have a bug in my vertices code --> TODO --> fix that --> most likely at the edges
|
|
319
|
+
# TODO fix the algo
|
|
320
|
+
|
|
321
|
+
# print(triangles)
|
|
322
|
+
# break
|
|
323
|
+
plt.imshow(out)
|
|
324
|
+
plt.show()
|
|
325
|
+
|
|
326
|
+
# plt.imshow(labels)
|
|
327
|
+
# plt.show()
|
|
328
|
+
|
|
329
|
+
# tt marche --> plutot cool en fait
|
|
330
|
+
|
|
331
|
+
|