Add tests for foreground preservation and refactor geometry node asset
- Implement test to ensure foreground preserves source RGB and Ben2 alpha in WorkerTest. - Remove outdated tests related to background distance and original background depth. - Update geometry node asset to reflect new naming conventions and structure. - Introduce validation for depth plane asset, ensuring correct input/output configurations and attribute handling. - Adjust confidence and edge parameters in geometry node asset to support a wider range of values.
This commit is contained in:
@@ -30,6 +30,25 @@ class WorkerTest(unittest.TestCase):
|
||||
def setUpClass(cls):
|
||||
cls.worker = load_worker()
|
||||
|
||||
def test_foreground_preserves_source_rgb_and_ben2_alpha(self):
|
||||
alpha = SimpleNamespace(size=(2, 1))
|
||||
source_rgba = SimpleNamespace(size=(2, 1), applied_alpha=None)
|
||||
source_rgba.putalpha = lambda value: setattr(
|
||||
source_rgba,
|
||||
"applied_alpha",
|
||||
value,
|
||||
)
|
||||
source = SimpleNamespace(convert=lambda _mode: source_rgba)
|
||||
foreground_rgba = SimpleNamespace(
|
||||
getchannel=lambda _name: alpha,
|
||||
)
|
||||
foreground = SimpleNamespace(convert=lambda _mode: foreground_rgba)
|
||||
|
||||
result = self.worker.preserve_source_rgb(source, foreground)
|
||||
|
||||
self.assertIs(result, source_rgba)
|
||||
self.assertIs(result.applied_alpha, alpha)
|
||||
|
||||
def test_collect_images_is_sorted_and_filters_suffixes(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
@@ -138,49 +157,6 @@ class WorkerTest(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(args.remove_background_model_dir, "ben2")
|
||||
|
||||
def test_background_distance_sets_fixed_background_depth(self):
|
||||
prediction = SimpleNamespace(
|
||||
depth=np.array(
|
||||
[[
|
||||
[1.0, 2.0, 3.0, 4.0],
|
||||
[5.0, -9.0, -2.0, 8.0],
|
||||
[9.0, -3.0, 4.0, 12.0],
|
||||
[13.0, 14.0, 15.0, 16.0],
|
||||
]]
|
||||
),
|
||||
conf=np.arange(16, dtype=np.float32).reshape(1, 4, 4),
|
||||
)
|
||||
foreground_mask = np.array(
|
||||
[[
|
||||
[True, True, True, True],
|
||||
[True, True, False, True],
|
||||
[True, True, True, True],
|
||||
[True, True, True, True],
|
||||
]],
|
||||
dtype=bool,
|
||||
)
|
||||
original_confidence = prediction.conf.copy()
|
||||
|
||||
self.worker.apply_depth_background_array(
|
||||
prediction,
|
||||
foreground_mask,
|
||||
8.0,
|
||||
)
|
||||
|
||||
np.testing.assert_array_equal(
|
||||
prediction.depth,
|
||||
[[
|
||||
[-8.0, -8.0, -8.0, -8.0],
|
||||
[-8.0, -8.0, -8.0, -8.0],
|
||||
[-8.0, -3.0, 4.0, -8.0],
|
||||
[-8.0, -8.0, -8.0, -8.0],
|
||||
]],
|
||||
)
|
||||
np.testing.assert_array_equal(
|
||||
prediction.conf,
|
||||
original_confidence,
|
||||
)
|
||||
|
||||
def test_ai_depth_is_converted_for_positive_displacement(self):
|
||||
prediction = SimpleNamespace(
|
||||
depth=np.array([[[0.25, 1.0], [1.5, 2.0]]]),
|
||||
@@ -215,26 +191,6 @@ class WorkerTest(unittest.TestCase):
|
||||
1.5,
|
||||
)
|
||||
|
||||
def test_original_background_uses_fixed_negative_depth(self):
|
||||
luminance = np.full((3, 3), 0.5, dtype=np.float32)
|
||||
alpha = np.full((3, 3), 255, dtype=np.uint8)
|
||||
alpha[1, 0] = 0
|
||||
|
||||
depth = self.worker.compose_original_background_depth(
|
||||
luminance,
|
||||
alpha,
|
||||
3.0,
|
||||
)
|
||||
|
||||
np.testing.assert_allclose(
|
||||
depth,
|
||||
[
|
||||
[-3.0, -3.0, -3.0],
|
||||
[-3.0, 0.5, -3.0],
|
||||
[-3.0, -3.0, -3.0],
|
||||
],
|
||||
)
|
||||
|
||||
def test_prepares_a_single_image_file(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
image_path = Path(directory) / "input.png"
|
||||
@@ -646,6 +602,8 @@ class WorkerTest(unittest.TestCase):
|
||||
save_options = []
|
||||
|
||||
class FakeImage:
|
||||
size = (1, 1)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
@@ -656,6 +614,12 @@ class WorkerTest(unittest.TestCase):
|
||||
self.mode = mode
|
||||
return self
|
||||
|
||||
def getchannel(self, _name):
|
||||
return self
|
||||
|
||||
def putalpha(self, _alpha):
|
||||
return None
|
||||
|
||||
def save(self, path, **options):
|
||||
save_options.append(options)
|
||||
Path(path).touch()
|
||||
@@ -726,6 +690,8 @@ class WorkerTest(unittest.TestCase):
|
||||
inference_options = []
|
||||
|
||||
class FakeImage:
|
||||
size = (1, 1)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
@@ -736,6 +702,12 @@ class WorkerTest(unittest.TestCase):
|
||||
self.mode = mode
|
||||
return self
|
||||
|
||||
def getchannel(self, _name):
|
||||
return self
|
||||
|
||||
def putalpha(self, _alpha):
|
||||
return None
|
||||
|
||||
def save(self, path, **options):
|
||||
Path(path).touch()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user