Add image extraction functionality with background removal
- Implemented ExtractImageRegion operator for extracting image regions using box or lasso selection. - Added RemoveImageRegionBackground job for background removal from selected image regions. - Created utility functions for polygon bounds, selection canvas creation, and applying selection masks. - Integrated image processing using PIL and numpy for efficient pixel manipulation. - Enhanced user experience with modal drawing and status updates during extraction.
This commit is contained in:
@@ -220,7 +220,7 @@ class ServerTest(unittest.TestCase):
|
||||
"download-model",
|
||||
"download-required-models",
|
||||
"analyze-balloon",
|
||||
"analyze-image-lasso",
|
||||
"extract-image-background",
|
||||
"remove-background",
|
||||
"extract-frames",
|
||||
"generate-depth",
|
||||
@@ -401,16 +401,16 @@ class ServerTest(unittest.TestCase):
|
||||
self.assertEqual(tuple(result[0, 0]), (20, 40, 60, 64))
|
||||
self.assertEqual(tuple(result[3, 3]), (0, 0, 0, 0))
|
||||
|
||||
def test_image_lasso_canvas_clears_rgba_outside_the_selection(self):
|
||||
def test_image_extract_canvas_clears_rgba_outside_the_selection(self):
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
image_lasso = sys.modules["server.jobs.image_lasso"]
|
||||
image_extract = sys.modules["server.jobs.image_extract"]
|
||||
source_path = self.storage_root / "source.png"
|
||||
pixels = np.full((2, 2, 4), (20, 40, 60, 255), dtype=np.uint8)
|
||||
Image.fromarray(pixels, mode="RGBA").save(source_path)
|
||||
|
||||
canvas, _selection, bounds = image_lasso.create_lasso_canvas(
|
||||
canvas, _selection, bounds = image_extract.create_selection_canvas(
|
||||
source_path,
|
||||
((-1, -1), (2, -1), (-1, 2)),
|
||||
)
|
||||
@@ -421,14 +421,14 @@ class ServerTest(unittest.TestCase):
|
||||
self.assertEqual(tuple(result[2, 2]), (0, 0, 0, 0))
|
||||
self.assertEqual(tuple(result[1, 1]), (20, 40, 60, 255))
|
||||
|
||||
def test_image_lasso_crops_to_alpha_with_pixel_padding(self):
|
||||
def test_image_extract_crops_to_alpha_with_pixel_padding(self):
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
image_lasso = sys.modules["server.jobs.image_lasso"]
|
||||
image_extract = sys.modules["server.jobs.image_extract"]
|
||||
pixels = np.zeros((4, 5, 4), dtype=np.uint8)
|
||||
pixels[1:3, 2:4] = (20, 40, 60, 255)
|
||||
result, bounds = image_lasso.crop_to_alpha(
|
||||
result, bounds = image_extract.crop_to_alpha(
|
||||
Image.fromarray(pixels, mode="RGBA"),
|
||||
(10, 20, 15, 24),
|
||||
padding=1,
|
||||
|
||||
Reference in New Issue
Block a user