Skip to content

Commit

Permalink
World coordinates support (#3)
Browse files Browse the repository at this point in the history
* ENH: World coordinates support

* ENH: Update test for world coordinates version

* ENH: Version bump to 0.0.3
  • Loading branch information
ViktorvdValk authored May 31, 2021
1 parent 7c3cffe commit c0ff9b3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion checkerboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__author__ = "Viktor van der Valk"
__email__ = "[email protected]"

__version__ = "0.0.2"
__version__ = "0.0.3"


def get_module_version():
Expand Down
10 changes: 7 additions & 3 deletions checkerboard/_tests/test_dock_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import itk
import pytest
import numpy as np
from itk_napari_conversion import image_layer_from_image
from itk_napari_conversion import image_from_image_layer
import napari

# this is your plugin name declared in your napari.plugins entry point
MY_PLUGIN_NAME = "napari-checkerboard"
Expand All @@ -15,12 +18,13 @@ def image_generator(x1, x2, y1, y2, data_dir='none'):
image = np.zeros([100, 100], np.float32)
image[y1:y2, x1:x2] = 1
image = itk.image_view_from_array(image)
image = image_layer_from_image(image)
return image


def checkerboard_filter(*args, **kwargs):
filter = checkerboard.checkerboard()
return filter(*args, **kwargs)
cb_filter = checkerboard.checkerboard()
return cb_filter(*args, **kwargs)


# @pytest.mark.parametrize("widget_name", MY_WIDGET_NAMES)
Expand All @@ -41,4 +45,4 @@ def test_checkerboard():
image1 = image_generator(25, 75, 25, 75)
image2 = image_generator(1, 51, 10, 60)
result_image = checkerboard_filter(image1, image2, pattern=4)
assert type(result_image[0]) == np.ndarray
assert isinstance(result_image, napari.layers.Image)
28 changes: 17 additions & 11 deletions checkerboard/checkerboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import numpy as np
import itk
import checkerboard.utils as utils
from itk_napari_conversion import image_from_image_layer
from itk_napari_conversion import image_layer_from_image


def on_init(widget):
"""
Expand All @@ -15,23 +18,21 @@ def on_init(widget):
call_button="create checkerboard",
pattern={"max": 20, "step": 1,
"tooltip": "Select the gridsize of the checkerboard"})
def checkerboard(image1: "napari.types.ImageData",
image2: "napari.types.ImageData",
pattern: int = 3) -> 'napari.types.LayerDataTuple':
def checkerboard(image1: "napari.layers.Image",
image2: "napari.layers.Image",
pattern: int = 3) -> 'napari.layers.Image':
"""
Takes user input images and returns a checkerboard blend of the images.
"""
if image1 is None or image2 is None:
print("No images selected for registration.")
return error("No images selected for registration.")

image1 = np.asarray(image1).astype(np.float32)
image2 = np.asarray(image2).astype(np.float32)

itk_image1 = itk.GetImageFromArray(image1)
itk_image2 = itk.GetImageFromArray(image2)
input1 = itk_image1
input2 = itk_image2
# Convert image layer to itk_image
itk_image1 = image_from_image_layer(image1)
itk_image2 = image_from_image_layer(image2)
itk_image1 = itk_image1.astype(itk.F)
itk_image2 = itk_image2.astype(itk.F)

region_image1 = itk_image1.GetLargestPossibleRegion()
region_image2 = itk_image2.GetLargestPossibleRegion()
Expand Down Expand Up @@ -70,6 +71,9 @@ def checkerboard(image1: "napari.types.ImageData",
resampler.SetReferenceImage(itk_image2)
resampler.Update()
input1 = resampler.GetOutput()
else:
input1 = itk_image1
input2 = itk_image2

checkerboard_filter = itk.CheckerBoardImageFilter.New(input1, input2)

Expand All @@ -79,7 +83,9 @@ def checkerboard(image1: "napari.types.ImageData",
checkerboard_filter.Update()
checkerboard = checkerboard_filter.GetOutput()

return np.asarray(checkerboard).astype(np.float32), {'name': 'checkerboard'}
layer = image_layer_from_image(checkerboard)
layer.name = "checkerboard " + image1.name + " " + image2.name
return layer


@napari_hook_implementation
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ numpy>=1.19.0
napari>=0.4.6
magicgui>=0.2.6
itk-elastix>=0.11.1
itk_napari_conversion>=0.3.1
napari-itk-io>=0.1.0

0 comments on commit c0ff9b3

Please sign in to comment.