Skip to content

Commit

Permalink
mel roto export
Browse files Browse the repository at this point in the history
Currently for prototyping agentic workflows.
  • Loading branch information
aevri committed Feb 2, 2025
1 parent 2a69ca6 commit a4e771a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mel/cmd/mel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import mel.cmd.rotomapuuid
import mel.cmd.status
import mel.cmd.timelog
import mel.cmd.rotoexport # new import for the export command

COMMANDS = {
"root": {
Expand Down Expand Up @@ -71,6 +72,7 @@
"organise": mel.cmd.rotomaporganise,
"rm": mel.cmd.rotomaprm,
"uuid": mel.cmd.rotomapuuid,
"export": mel.cmd.rotoexport # new export command
},
}

Expand Down
50 changes: 50 additions & 0 deletions mel/cmd/rotoexport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Export command for rotomap.
This command processes all images in a given directory: if a corresponding mask file exists,
the masked areas are replaced with solid green for anonymity.
Assumes mask files are named as <basename>_mask<ext> (e.g., img.png -> img_mask.png).
"""

import cv2
import numpy as np

import mel.lib.common
import mel.rotomap.moles
import mel.rotomap.mask


def setup_parser(parser):
parser.add_argument('source', help="image to load from.")
parser.add_argument('output', help="image to save to.")


def load_image(image_path):
# flags = cv2.IMREAD_UNCHANGED + cv2.IMREAD_ANYDEPTH + cv2.IMREAD_ANYCOLOR
flags = cv2.IMREAD_COLOR
try:
original_image = cv2.imread(str(image_path), flags)
if original_image is None:
raise OSError(f"File not recognized by opencv: {image_path}")
original_image = cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB)
except Exception as e:
raise OSError(f"Error handling image at: {image_path}") from e

mask = mel.rotomap.mask.load(image_path)
green = np.zeros(original_image.shape, np.uint8)
green[:, :, 1] = 255
image = cv2.bitwise_and(original_image, original_image, mask=mask)
not_mask = cv2.bitwise_not(mask)
green = cv2.bitwise_and(green, green, mask=not_mask)
image = cv2.bitwise_or(image, green)
return image


def process_args(args):
image = load_image(args.source)

# Convert RGB to BGR for cv2.imwrite
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

mel.lib.common.write_image(args.output, image)

return 0

0 comments on commit a4e771a

Please sign in to comment.