Spaces:
Runtime error
Runtime error
showing lines
Browse files- app.py +11 -5
- line_fit.py +1 -1
app.py
CHANGED
@@ -19,8 +19,8 @@ linefit = LineFit(30, 0.3)
|
|
19 |
|
20 |
def get_blob_centroids(mask):
|
21 |
centers = []
|
22 |
-
print(mask.dtype)
|
23 |
-
print(mask.shape)
|
24 |
contours, hierarchies = cv2.findContours(
|
25 |
mask, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
|
26 |
for i in contours:
|
@@ -29,7 +29,7 @@ def get_blob_centroids(mask):
|
|
29 |
cx = int(M['m10']/M['m00'])
|
30 |
cy = int(M['m01']/M['m00'])
|
31 |
centers.append([cx,cy])
|
32 |
-
print(cx,cy)
|
33 |
return centers
|
34 |
|
35 |
def predict_mask(input_img, threshold):
|
@@ -59,7 +59,7 @@ def predict_mask(input_img, threshold):
|
|
59 |
d, lines = linefit.predict((p>threshold).astype(np.uint8)*255)
|
60 |
ds.append(d)
|
61 |
m = Image.fromarray(p>threshold)
|
62 |
-
imgd.bitmap([0,0], m, fill=random.choice(colors))
|
63 |
for line in lines:
|
64 |
imgd.line(line, fill ="blue", width = 1)
|
65 |
|
@@ -68,6 +68,12 @@ def predict_mask(input_img, threshold):
|
|
68 |
demo = gr.Blocks()
|
69 |
|
70 |
with demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
with gr.Row():
|
72 |
with gr.Column():
|
73 |
img = gr.Image(
|
@@ -85,7 +91,7 @@ with demo:
|
|
85 |
btn = gr.Button("Run")
|
86 |
with gr.Column():
|
87 |
img2 = gr.Image()
|
88 |
-
text = gr.Text()
|
89 |
|
90 |
btn.click(fn=predict_mask, inputs=[img, threshold], outputs=[img2,text], )
|
91 |
examples = gr.Examples(examples=['test0001.png',
|
|
|
19 |
|
20 |
def get_blob_centroids(mask):
|
21 |
centers = []
|
22 |
+
# print(mask.dtype)
|
23 |
+
# print(mask.shape)
|
24 |
contours, hierarchies = cv2.findContours(
|
25 |
mask, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
|
26 |
for i in contours:
|
|
|
29 |
cx = int(M['m10']/M['m00'])
|
30 |
cy = int(M['m01']/M['m00'])
|
31 |
centers.append([cx,cy])
|
32 |
+
# print(cx,cy)
|
33 |
return centers
|
34 |
|
35 |
def predict_mask(input_img, threshold):
|
|
|
59 |
d, lines = linefit.predict((p>threshold).astype(np.uint8)*255)
|
60 |
ds.append(d)
|
61 |
m = Image.fromarray(p>threshold)
|
62 |
+
# imgd.bitmap([0,0], m, fill=random.choice(colors))
|
63 |
for line in lines:
|
64 |
imgd.line(line, fill ="blue", width = 1)
|
65 |
|
|
|
68 |
demo = gr.Blocks()
|
69 |
|
70 |
with demo:
|
71 |
+
with gr.Column():
|
72 |
+
gr.Markdown("""
|
73 |
+
# Measure the diameter fibers
|
74 |
+
Select fibers that you want to measure. (Only the center of each sketched blob is considered).
|
75 |
+
The recommended pixel size for uploaded images is 256x256.
|
76 |
+
""")
|
77 |
with gr.Row():
|
78 |
with gr.Column():
|
79 |
img = gr.Image(
|
|
|
91 |
btn = gr.Button("Run")
|
92 |
with gr.Column():
|
93 |
img2 = gr.Image()
|
94 |
+
text = gr.Text(label='Measurements')
|
95 |
|
96 |
btn.click(fn=predict_mask, inputs=[img, threshold], outputs=[img2,text], )
|
97 |
examples = gr.Examples(examples=['test0001.png',
|
line_fit.py
CHANGED
@@ -155,7 +155,7 @@ class LineFit:
|
|
155 |
mask_meas_lines = self.mask_measured_lines(im, lines)
|
156 |
#for line in lines:
|
157 |
# plt.plot(*self.line_to_arrays(line), 'c-')
|
158 |
-
return calculated_diameter,
|
159 |
|
160 |
if __name__ == "__main__":
|
161 |
import os
|
|
|
155 |
mask_meas_lines = self.mask_measured_lines(im, lines)
|
156 |
#for line in lines:
|
157 |
# plt.plot(*self.line_to_arrays(line), 'c-')
|
158 |
+
return calculated_diameter, lines
|
159 |
|
160 |
if __name__ == "__main__":
|
161 |
import os
|