diff --git a/README.md b/README.md index b566306..1c0b70c 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) +``` + ## 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) diff --git a/server/app.py b/server/app.py index 8b19a1e..d9445c6 100644 --- a/server/app.py +++ b/server/app.py @@ -295,7 +295,7 @@ def download_image_with_annotations(): points = region['points'] scaled_points = [(x * width, y * height) for x, y in points] # 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 @@ -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 @@ -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']) @@ -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 @@ -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 @@ -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') diff --git a/server/config.py b/server/config.py index a709cf7..1e23bc8 100644 --- a/server/config.py +++ b/server/config.py @@ -1 +1,6 @@ -MASK_BACKGROUND_COLOR = (0, 0, 0) \ No newline at end of file +MASK_BACKGROUND_COLOR = (0, 0, 0) +OUTLINE_THICKNESS_CONFIG = { + "POLYGON": 3, + "CIRCLE": 3, + "BOUNDING_BOX": 3 +} # change outline thickness (currently only for downloaded files) \ No newline at end of file