Skip to content

Commit

Permalink
ENH: Additional itkwasm method tests, add baselines
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jan 26, 2024
1 parent 199073c commit e1a63cd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 49 deletions.
10 changes: 7 additions & 3 deletions test/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from ngff_zarr import itk_image_to_ngff_image, to_ngff_zarr
from zarr.storage import DirectoryStore, MemoryStore

test_data_ipfs_cid = "bafybeifkrfjreee5e7rfoi2ka3t2n23jlqwsrqwg4gmbyqcrc47iet27km"
test_data_sha256 = "861dd3acb8391a3ac2b10b3487c33ee74da1415ef30b9f4c37c7f8f49e802c32"
test_data_ipfs_cid = "bafybeiawyalfemcmlfbizetoqilpmbk6coowu7cqr7av6aff4dpjwlsk6m"
test_data_sha256 = "3f32e9e8fac84de3fbe63d0a6142b2eb65cadd8c9e1c3ba7f93080a6bc2150ef"

test_dir = Path(__file__).resolve().parent
extract_dir = "data"
Expand All @@ -21,7 +21,7 @@ def input_images():
pooch.retrieve(
fname="data.tar.gz",
path=test_dir,
url=f"https://{test_data_ipfs_cid}.ipfs.w3s.link",
url=f"https://{test_data_ipfs_cid}.ipfs.w3s.link/data.tar.gz",
known_hash=f"sha256:{test_data_sha256}",
processor=untar,
)
Expand All @@ -44,6 +44,10 @@ def input_images():
image_ngff = itk_image_to_ngff_image(image)
result["2th_cthead1"] = image_ngff

image = itk.imread(test_data_dir / "input" / "MR-head.nrrd")
image_ngff = itk_image_to_ngff_image(image)
result["MR-head"] = image_ngff

return result


Expand Down
84 changes: 38 additions & 46 deletions test/test_to_ngff_zarr_itkwasm.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from ngff_zarr import Methods, to_multiscales

from ._data import store_new_multiscales, verify_against_baseline
from ._data import verify_against_baseline


def test_bin_shrink_isotropic_scale_factors(input_images):
dataset_name = "cthead1"
image = input_images[dataset_name]
baseline_name = "2_4/ITKWASM_BIN_SHRINK.zarr"
multiscales = to_multiscales(image, [2, 4], method=Methods.ITKWASM_BIN_SHRINK)
store_new_multiscales(dataset_name, baseline_name, multiscales)
verify_against_baseline(dataset_name, baseline_name, multiscales)

baseline_name = "auto/ITKWASM_BIN_SHRINK.zarr"
multiscales = to_multiscales(image, method=Methods.ITKWASM_BIN_SHRINK)
store_new_multiscales(dataset_name, baseline_name, multiscales)
verify_against_baseline(dataset_name, baseline_name, multiscales)


Expand All @@ -22,72 +20,66 @@ def test_gaussian_isotropic_scale_factors(input_images):
image = input_images[dataset_name]
baseline_name = "2_4/ITKWASM_GAUSSIAN.zarr"
multiscales = to_multiscales(image, [2, 4], method=Methods.ITKWASM_GAUSSIAN)
store_new_multiscales(dataset_name, baseline_name, multiscales)
verify_against_baseline(dataset_name, baseline_name, multiscales)

baseline_name = "auto/ITKWASM_GAUSSIAN.zarr"
multiscales = to_multiscales(image, method=Methods.ITKWASM_GAUSSIAN)
store_new_multiscales(dataset_name, baseline_name, multiscales)
verify_against_baseline(dataset_name, baseline_name, multiscales)


# dataset_name = "cthead1"
# image = input_images[dataset_name]
# baseline_name = "2_3/DASK_IMAGE_GAUSSIAN"
# multiscale = to_multiscale(image, [2, 3], method=Methods.DASK_IMAGE_GAUSSIAN)
# verify_against_baseline(dataset_name, baseline_name, multiscale)

# dataset_name = "small_head"
# image = input_images[dataset_name]
# baseline_name = "2_3_4/DASK_IMAGE_GAUSSIAN"
# multiscale = to_multiscale(image, [2, 3, 4], method=Methods.DASK_IMAGE_GAUSSIAN)
# verify_against_baseline(dataset_name, baseline_name, multiscale)


def test_gaussian_anisotropic_scale_factors(input_images):
dataset_name = "cthead1"
image = input_images[dataset_name]
scale_factors = [{"x": 2, "y": 2}, {"x": 2, "y": 4}]
multiscales = to_multiscales(image, scale_factors, method=Methods.ITKWASM_GAUSSIAN)
baseline_name = "x2y2_x2y4/ITKWASM_GAUSSIAN.zarr"
store_new_multiscales(dataset_name, baseline_name, multiscales)
baseline_name = "2_3/ITKWASM_GAUSSIAN.zarr"
multiscales = to_multiscales(image, [2, 3], method=Methods.ITKWASM_GAUSSIAN)
verify_against_baseline(dataset_name, baseline_name, multiscales)

# dataset_name = "small_head"
# image = input_images[dataset_name]
# scale_factors = [
# {"x": 3, "y": 2, "z": 4},
# {"x": 2, "y": 2, "z": 2},
# {"x": 1, "y": 2, "z": 1},
# ]
# multiscale = to_multiscale(image, scale_factors, method=Methods.DASK_IMAGE_GAUSSIAN)
# baseline_name = "x3y2z4_x2y2z2_x1y2z1/DASK_IMAGE_GAUSSIAN"
# verify_against_baseline(dataset_name, baseline_name, multiscale)
dataset_name = "MR-head"
image = input_images[dataset_name]
baseline_name = "2_3_4/ITKWASM_GAUSSIAN.zarr"
multiscales = to_multiscales(image, [2, 3, 4], method=Methods.ITKWASM_GAUSSIAN)
verify_against_baseline(dataset_name, baseline_name, multiscales)


# def test_gaussian_anisotropic_scale_factors(input_images):
# dataset_name = "cthead1"
# image = input_images[dataset_name]
# scale_factors = [{"x": 2, "y": 2}, {"x": 2, "y": 4}]
# multiscales = to_multiscales(image, scale_factors, method=Methods.ITKWASM_GAUSSIAN)
# baseline_name = "x2y2_x2y4/ITKWASM_GAUSSIAN.zarr"
# verify_against_baseline(dataset_name, baseline_name, multiscales)

# dataset_name = "MR-head"
# image = input_images[dataset_name]
# scale_factors = [
# {"x": 3, "y": 2, "z": 4},
# {"x": 6, "y": 4, "z": 4},
# {"x": 6, "y": 8, "z": 4},
# ]
# multiscales = to_multiscales(image, scale_factors, method=Methods.ITKWASM_GAUSSIAN)
# baseline_name = "x3y2z4_6242z4_x6y8z4/ITKWASM_GAUSSIAN.zarr"
# verify_against_baseline(dataset_name, baseline_name, multiscales)


def test_label_image_isotropic_scale_factors(input_images):
dataset_name = "2th_cthead1"
image = input_images[dataset_name]
baseline_name = "2_4/ITKWASM_LABEL_IMAGE.zarr"
multiscales = to_multiscales(image, [2, 4], method=Methods.ITKWASM_LABEL_IMAGE)
store_new_multiscales(dataset_name, baseline_name, multiscales)
verify_against_baseline(dataset_name, baseline_name, multiscales)

dataset_name = "2th_cthead1"
image = input_images[dataset_name]
baseline_name = "2_3/ITKWASM_LABEL_IMAGE.zarr"
multiscales = to_multiscales(image, [2, 3], method=Methods.ITKWASM_LABEL_IMAGE)
store_new_multiscales(dataset_name, baseline_name, multiscales)
verify_against_baseline(dataset_name, baseline_name, multiscales)


def test_label_image_anisotropic_scale_factors(input_images):
dataset_name = "2th_cthead1"
image = input_images[dataset_name]
scale_factors = [{"x": 2, "y": 2}, {"x": 2, "y": 4}]
multiscales = to_multiscales(
image, scale_factors, method=Methods.ITKWASM_LABEL_IMAGE
)
baseline_name = "x2y4_x2y8/ITKWASM_LABEL_IMAGE.zarr"
store_new_multiscales(dataset_name, baseline_name, multiscales)
verify_against_baseline(dataset_name, baseline_name, multiscales)
# def test_label_image_anisotropic_scale_factors(input_images):
# dataset_name = "2th_cthead1"
# image = input_images[dataset_name]
# scale_factors = [{"x": 2, "y": 2}, {"x": 2, "y": 4}]
# multiscales = to_multiscales(
# image, scale_factors, method=Methods.ITKWASM_LABEL_IMAGE
# )
# baseline_name = "x2y4_x2y4/ITKWASM_LABEL_IMAGE.zarr"
# store_new_multiscales(dataset_name, baseline_name, multiscales)
# verify_against_baseline(dataset_name, baseline_name, multiscales)

0 comments on commit e1a63cd

Please sign in to comment.