Skip to content

Commit

Permalink
🔥 remove line width
Browse files Browse the repository at this point in the history
  • Loading branch information
danton267 committed Sep 26, 2023
1 parent b305f4e commit e08c9ba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 37 deletions.
12 changes: 0 additions & 12 deletions callbacks/control_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,6 @@ def annotation_mode(
)


@callback(
Output("image-viewer", "figure", allow_duplicate=True),
Input("paintbrush-width", "value"),
prevent_initial_call=True,
)
def annotation_width(width_value):
"""This callback is responsible for changing the brush width"""
patched_figure = Patch()
patched_figure["layout"]["newshape"]["line"]["width"] = width_value
return patched_figure


@callback(
Output("image-viewer", "figure", allow_duplicate=True),
Input("current-class-selection", "data"),
Expand Down
15 changes: 0 additions & 15 deletions components/control_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,21 +399,6 @@ def layout():
),
]
),
dmc.Space(h=30),
_control_item(
"Drawing width",
"paintbrush-text",
dmc.Slider(
id="paintbrush-width",
value=5,
min=1,
max=20,
step=1,
color="gray",
size="sm",
style={"width": "257px"},
),
),
dmc.Space(h=10),
dmc.Modal(
title="Warning",
Expand Down
34 changes: 24 additions & 10 deletions utils/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def __init__(self, annotation_store, global_store):
"id": annotation_class["class_id"],
"type": self.annotation_type,
"class": annotation_class["label"],
"line_width": shape["line"]["width"],
# TODO: This is the same across all images in a dataset
"image_shape": global_store["image_shapes"][0],
"svg_data": self.svg_data,
Expand Down Expand Up @@ -212,7 +211,7 @@ def rectangle_to_array(self, svg_data, image_shape, mask_class):
return mask

@classmethod
def line_to_array(self, svg_data, image_shape, mask_class, line_width):
def line_to_array(self, svg_data, image_shape, mask_class):
image_height, image_width = image_shape
x0 = svg_data["x0"]
y0 = svg_data["y0"]
Expand All @@ -228,7 +227,6 @@ def line_to_array(self, svg_data, image_shape, mask_class, line_width):
mask = np.zeros((image_height, image_width), dtype=np.uint8)
rr, cc = draw.line(y0, x0, y1, x1)
mask[rr, cc] = mask_class
# mask = morphology.dilation(mask, morphology.disk(radius=line_width))
return mask

@classmethod
Expand Down Expand Up @@ -264,20 +262,36 @@ def closed_path_to_array(self, svg_data, image_shape, mask_class):
return mask

@classmethod
def opened_path_to_array(self, svg_data, image_shape, mask_class, line_width):
def opened_path_to_array(self, svg_data, image_shape, mask_class):
image_height, image_width = image_shape
path_data = svg_data["path"]
path = parse_path(path_data)

# Create an empty image
mask = np.zeros((image_height, image_width), dtype=np.uint8)

radius = 4

# Convert SVG path to points and draw on the image
for curve in path:
for t in np.linspace(0, 1, 1000):
x, y = curve.point(t).real, curve.point(t).imag
x = max(min(int(x), image_width - 1), 0)
y = max(min(int(y), image_height - 1), 0)
mask[y, x] = mask_class
# mask = morphology.dilation(mask, morphology.disk(radius=line_width))
for t in np.linspace(
0, 1, 500
): # Reduced the number of points to decrease overlap
cx, cy = (
curve.point(t).real,
curve.point(t).imag,
) # Center of the circle
cx, cy = max(min(int(cx), image_width - 1), 0), max(
min(int(cy), image_height - 1), 0
)

# Draw a disk around (cx, cy) with the given radius
for dy in range(-radius, radius + 1):
for dx in range(-radius, radius + 1):
if (
dx**2 + dy**2 <= radius**2
): # Check if point is inside circle
x, y = cx + dx, cy + dy
if 0 <= x < image_width and 0 <= y < image_height:
mask[y, x] = mask_class
return mask

0 comments on commit e08c9ba

Please sign in to comment.