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

Fix 2D image conversion to ignore z when dropping border #85

Merged
merged 1 commit into from
Dec 9, 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
5 changes: 4 additions & 1 deletion src/arcade_collection/convert/convert_to_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def convert_to_images(
object_id = object_id + 1

# Remove 1 pixel border.
array = raw_array[:, :, 1:-1, 1:-1, 1:-1].copy()
if height == 1:
array = raw_array[:, :, :, 1:-1, 1:-1].copy()
else:
array = raw_array[:, :, 1:-1, 1:-1, 1:-1].copy()

if separate:
chunks = [
Expand Down
87 changes: 87 additions & 0 deletions tests/arcade_collection/convert/test_convert_to_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,79 @@ def setUp(self):

self.locations_tar = build_tar_instance(contents)

def test_convert_to_images_full_without_chunks_2d_image(self):
frame_spec = (5, 6, 1)
box = (8, 8, 1)
chunk_size = 6
image_type = ImageType.FULL

contents = {
f"{self.series_key}_000005.LOCATIONS.json": [
{
"id": 1,
"location": [
{"region": "DEFAULT", "voxels": [[1, 1, 0], [2, 1, 0], [2, 2, 0]]},
{"region": "REGION", "voxels": [[1, 2, 0]]},
],
},
{
"id": 2,
"location": [
{"region": "DEFAULT", "voxels": [[5, 3, 0], [5, 4, 0]]},
{"region": "REGION", "voxels": [[6, 3, 0], [6, 4, 0]]},
],
},
]
}

locations_tar = build_tar_instance(contents)

chunk_00 = np.array(
[
[
[
[
[1, 1, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 2, 2],
[0, 0, 0, 0, 2, 2],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
]
],
[
[
[0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 2],
[0, 0, 0, 0, 0, 2],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
]
],
]
]
)

expected_images = [(0, 0, chunk_00, None)]

images = convert_to_images(
self.series_key,
locations_tar,
frame_spec,
self.regions,
box,
chunk_size,
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
self.assertTrue(np.array_equal(expected_chunk[2], chunk[2]))
self.assertIsNone(chunk[3])

def test_convert_to_images_full_without_chunks(self):
chunk_size = 6
image_type = ImageType.FULL
Expand Down Expand Up @@ -157,6 +230,7 @@ def test_convert_to_images_full_without_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -258,6 +332,7 @@ def test_convert_to_images_full_by_frame_without_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -311,6 +386,7 @@ def test_convert_to_images_flat_by_frame_without_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -366,6 +442,7 @@ def test_convert_to_images_flat_rgba_by_frame_without_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -459,6 +536,7 @@ def test_convert_to_images_full_binary_without_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -560,6 +638,7 @@ def test_convert_to_images_full_binary_by_frame_without_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -613,6 +692,7 @@ def test_convert_to_images_flat_binary_by_frame_without_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -669,6 +749,7 @@ def test_convert_to_images_full_with_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -737,6 +818,7 @@ def test_convert_to_images_full_by_frame_with_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -783,6 +865,7 @@ def test_convert_to_images_flat_by_frame_with_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -853,6 +936,7 @@ def test_convert_to_images_flat_rgba_by_frame_with_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -909,6 +993,7 @@ def test_convert_to_images_full_binary_with_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -977,6 +1062,7 @@ def test_convert_to_images_full_binary_by_frame_with_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down Expand Up @@ -1023,6 +1109,7 @@ def test_convert_to_images_flat_binary_by_frame_with_chunks(self):
image_type,
)

self.assertEqual(len(expected_images), len(images))
for expected_chunk, chunk in zip(expected_images, images):
self.assertEqual(expected_chunk[0], chunk[0])
self.assertEqual(expected_chunk[1], chunk[1])
Expand Down
Loading