Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for issue #42 [completed, awaiting review] #50

Merged
merged 6 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ One can configure the tools, tags, upload images and do many more from the setti
```sh
python3 -m venv venv

source venv/bin/activate # On Windows use `venv\Scripts\activate`
```
source venv/bin/activate # On Windows use `venv\Scripts\activate`
```
3. Install the dependencies:
```sh
pip install -r requirements.txt
Expand Down Expand Up @@ -197,8 +197,17 @@ This command discovers and runs all test files (`test_*.py`) in the `server/test
2. Use the user interface to upload and annotate images.
3. The annotations and other interactions will be handled by the Flask server running at [http://localhost:5000](http://localhost:5000).

## Configurations (Optional)
You can customize some aspects of Annotate-Lab through configuration settings.
To do this, modify the `config.py` file in the `server` directory:
```python
# config.py
MASK_BACKGROUND_COLOR = (0, 0, 0) # Black background for masks
OUTLINE_THICKNESS = 5 # Thicker outlines (5 pixels)
Copy link
Owner

@sumn2u sumn2u Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to create an object and assign values as per UI tools value. This will give us more flexibility, granularity and will be in sync.

OUTLINE_THICKNESS_CONFIG = {
    "POLYGON": 2,
    "CIRCLE": 2,
    "BOUNDING_BOX": 2
}

```

## Outputs
Sample of annotated image along with its mask and settings is show below.
Sample of annotated image along with its mask and settings is show below.

![orange_annotation](./sample_images/orange_annotated-image.png)
![orange_annotation_mask](./sample_images/orange_masked-image.png)
Expand Down
12 changes: 6 additions & 6 deletions server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def download_image_with_annotations():
points = region['points']
scaled_points = [(x * width, y * height) for x, y in points]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we define the OUTLINE_THICKNESS_CONFIG object mentioned above , think we can access it like this.

from config import OUTLINE_THICKNESS_CONFIG 
....

# Load the outline thickness configuration
app.config.from_mapping(OUTLINE_THICKNESS_CONFIG)

OUTLINE_THICKNESS_CONFIG['LINE']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'll make this change

# Draw polygon with thicker outline
draw.line(scaled_points + [scaled_points[0]], fill=color, width=3) # Change width as desired
draw.line(scaled_points + [scaled_points[0]], fill=color, width=app.config['OUTLINE_THICKNESS_CONFIG']['POLYGON']) # Change width as desired
elif all(key in region for key in ('x', 'y', 'w', 'h')):
try:
x = float(region['x'][1:-1]) * width if isinstance(region['x'], str) else float(region['x'][0]) * width
Expand All @@ -305,7 +305,7 @@ def download_image_with_annotations():
except (ValueError, TypeError) as e:
raise ValueError(f"Invalid format in region dimensions: {region}, Error: {e}")
# Draw rectangle with thicker outline
draw.rectangle([x, y, x + w, y + h], outline=color, width=3)
draw.rectangle([x, y, x + w, y + h], outline=color, width=app.config['OUTLINE_THICKNESS_CONFIG']['BOUNDING_BOX'])
elif all(key in region for key in ('rx', 'ry', 'rw', 'rh')):
try:
rx = float(region['rx'][1:-1]) * width if isinstance(region['rx'], str) else float(region['rx'][0]) * width
Expand All @@ -315,7 +315,7 @@ def download_image_with_annotations():
except (ValueError, TypeError) as e:
raise ValueError(f"Invalid format in region dimensions: {region}, Error: {e}")
# Draw ellipse (circle if rw and rh are equal)
draw.ellipse([rx, ry, rx + rw, ry + rh], outline=color, width=3)
draw.ellipse([rx, ry, rx + rw, ry + rh], outline=color, width=app.config['OUTLINE_THICKNESS_CONFIG']['CIRCLE'])



Expand Down Expand Up @@ -375,7 +375,7 @@ def download_image_mask():
if 'points' in region and region['points']:
points = region['points']
scaled_points = [(int(x * width), int(y * height)) for x, y in points]
draw.polygon(scaled_points, outline=color, fill=color)
draw.polygon(scaled_points, outline=color, fill=color, width=app.config['OUTLINE_THICKNESS_CONFIG']['POLYGON'])
elif all(key in region for key in ('x', 'y', 'w', 'h')):
try:
x = float(region['x'][1:-1]) * width if isinstance(region['x'], str) else float(region['x'][0]) * width
Expand All @@ -385,7 +385,7 @@ def download_image_mask():
except (ValueError, TypeError) as e:
raise ValueError(f"Invalid format in region dimensions: {region}, Error: {e}")
# Draw rectangle for bounding box
draw.rectangle([x, y, x + w, y + h], outline=color, fill=color)
draw.rectangle([x, y, x + w, y + h], outline=color, fill=color, width=app.config['OUTLINE_THICKNESS_CONFIG']['BOUNDING_BOX'])
elif all(key in region for key in ('rx', 'ry', 'rw', 'rh')):
try:
rx = float(region['rx'][1:-1]) * width if isinstance(region['rx'], str) else float(region['rx'][0]) * width
Expand All @@ -395,7 +395,7 @@ def download_image_mask():
except (ValueError, TypeError) as e:
raise ValueError(f"Invalid format in region dimensions: {region}, Error: {e}")
# Draw ellipse (circle if rw and rh are equal)
draw.ellipse([rx, ry, rx + rw, ry + rh], outline=color, width=3, fill=color)
draw.ellipse([rx, ry, rx + rw, ry + rh], outline=color, width=app.config['OUTLINE_THICKNESS_CONFIG']['CIRCLE'], fill=color)

mask_byte_arr = BytesIO()
mask.save(mask_byte_arr, format='PNG')
Expand Down
7 changes: 6 additions & 1 deletion server/config.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
MASK_BACKGROUND_COLOR = (0, 0, 0)
MASK_BACKGROUND_COLOR = (0, 0, 0)
OUTLINE_THICKNESS_CONFIG = {
"POLYGON": 3,
"CIRCLE": 3,
"BOUNDING_BOX": 3
} # change outline thickness (currently only for downloaded files)
Loading