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

Improve interoperability with scipy #93

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6003605
added affine_transform (3D)
haesleinhuepf Jan 10, 2021
ea84982
API fine tuning
haesleinhuepf Jan 10, 2021
49710ef
enable passing a transform matrix
haesleinhuepf Jan 10, 2021
22cbd2a
added comments
haesleinhuepf Jan 10, 2021
433b7b4
added translate
haesleinhuepf Jan 10, 2021
fe88462
added rotate
haesleinhuepf Jan 10, 2021
44bacf1
added comments
haesleinhuepf Jan 10, 2021
e8d9bd8
changed angle parameter unit from radians to degrees
haesleinhuepf Jan 10, 2021
60cbbd6
added scale, deprecated resample
haesleinhuepf Jan 10, 2021
0632faa
updated comment
haesleinhuepf Jan 10, 2021
30fd228
added rigid transform
haesleinhuepf Jan 10, 2021
6051165
added demo notebook
haesleinhuepf Jan 10, 2021
b2b8f76
make affine transform compatible with scikit-image
haesleinhuepf Jan 10, 2021
4b733e0
added interoperability note
haesleinhuepf Jan 10, 2021
dca5f60
WIP: change functionality inside push (breaking change)
haesleinhuepf Jan 10, 2021
8c859dc
WIP: change functionality inside push (breaking change)
haesleinhuepf Jan 10, 2021
a417022
removed not used legacy test
haesleinhuepf Jan 10, 2021
6a3abcc
replace push and pull by push_zyx and pull_zyx
haesleinhuepf Jan 10, 2021
87293f7
replace push and pull by push_zyx and pull_zyx
haesleinhuepf Jan 10, 2021
3159089
replace push and pull by push_zyx and pull_zyx
haesleinhuepf Jan 10, 2021
f5716a5
replace push and pull by push_zyx and pull_zyx
haesleinhuepf Jan 10, 2021
3950745
partial bugfix (merge from master) of projections
haesleinhuepf Jan 10, 2021
5245ff4
replace push and pull by push_zyx and pull_zyx
haesleinhuepf Jan 10, 2021
af73012
DONE: replace push and pull by push_zyx and pull_zyx
haesleinhuepf Jan 10, 2021
269922d
replaced push_zyx calls with push
haesleinhuepf Jan 10, 2021
5278039
reran all notebooks
haesleinhuepf Jan 10, 2021
fbb49e8
improve interoperability with scipy
haesleinhuepf Jan 11, 2021
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ imsave("result.tif", cle.pull(labeled))

</td></tr><tr><td>

<img src="https://github.com/clEsperanto/pyclesperanto_prototype/raw/master/docs/images/screenshot_affine_transforms.png" width="300"/>

</td><td>

[Rotation, scaling, translation, affine transforms](https://github.com/clEsperanto/pyclesperanto_prototype/tree/master/demo/transforms/affine_transforms.ipynb)

</td></tr><tr><td>

<img src="https://github.com/clEsperanto/pyclesperanto_prototype/raw/master/docs/images/screenshot_multiply_vectors_and_matrices.png" width="300"/>

</td><td>
Expand Down
2 changes: 1 addition & 1 deletion demo/basics/browse_operations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.6"
}
},
"nbformat": 4,
Expand Down
99 changes: 33 additions & 66 deletions demo/basics/count_blobs.ipynb

Large diffs are not rendered by default.

134 changes: 24 additions & 110 deletions demo/basics/crop_and_paste_images.ipynb

Large diffs are not rendered by default.

74 changes: 15 additions & 59 deletions demo/basics/multiply_matrices.ipynb

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions demo/basics/multiply_vectors_and_matrices.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"voxel_size = np.asarray([[0.2], [0.2], [0.5]])\n",
"print(\"Array shape:\" + str(voxel_size.shape))\n",
"\n",
"gpu_voxel_size = cle.push_zyx(voxel_size)\n",
"print(\"GPU array shape:\" + str(voxel_size.shape))\n"
"gpu_voxel_size = cle.push(voxel_size)\n",
"print(\"GPU array shape:\" + str(voxel_size.shape))"
]
},
{
Expand All @@ -75,7 +75,7 @@
")\n",
"print(\"Array shape:\" + str(pointlist.shape))\n",
"\n",
"gpu_pointlist = cle.push_zyx(pointlist)\n",
"gpu_pointlist = cle.push(pointlist)\n",
"print(\"GPU array shape:\" + str(gpu_pointlist.shape))"
]
},
Expand Down Expand Up @@ -137,14 +137,6 @@
" [0. 1.2 0.2 0.4]\n",
" [4.5 5.5 3. 1. ]]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\users\\rober\\miniconda3\\lib\\site-packages\\pyopencl\\__init__.py:252: CompilerWarning: Non-empty compiler output encountered. Set the environment variable PYOPENCL_COMPILER_OUTPUT=1 to see more.\n",
" warn(\"Non-empty compiler output encountered. Set the \"\n"
]
}
],
"source": [
Expand Down Expand Up @@ -205,7 +197,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.6"
}
},
"nbformat": 4,
Expand Down
100 changes: 25 additions & 75 deletions demo/basics/spots_pointlists_matrices_tables.ipynb

Large diffs are not rendered by default.

106 changes: 20 additions & 86 deletions demo/basics/voronoi_diagrams.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions demo/napari_gui/napari_.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
viewer.add_image(image, name='blobs')

# push image to GPU
input = cle.push_zyx(image)
input = cle.push(image)

# process the image
sigma = 1
Expand All @@ -20,7 +20,7 @@
labels = cle.connected_components_labeling_box(binary)

# pull result back
output = cle.pull_zyx(labels)
output = cle.pull(labels)

# add it to napari
viewer.add_labels(output)
Expand Down
4 changes: 2 additions & 2 deletions demo/napari_gui/napari_magicgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
def process_image(input: Image, sigma: float = 5) -> Labels:
if input:
# push image to GPU
input = cle.push_zyx(input.data)
input = cle.push(input.data)

# process the image
blurred = cle.gaussian_blur(input, sigma_x=sigma, sigma_y=sigma)
binary = cle.threshold_otsu(blurred)
labels = cle.connected_components_labeling_box(binary)

# pull result back
output = cle.pull_zyx(labels)
output = cle.pull(labels)
return output

# load data
Expand Down
96 changes: 25 additions & 71 deletions demo/neighbors/mesh_between_centroids.ipynb

Large diffs are not rendered by default.

127 changes: 23 additions & 104 deletions demo/neighbors/mesh_between_touching_neighbors.ipynb

Large diffs are not rendered by default.

162 changes: 40 additions & 122 deletions demo/neighbors/mesh_nearest_neighbors.ipynb

Large diffs are not rendered by default.

256 changes: 62 additions & 194 deletions demo/neighbors/mesh_with_distances.ipynb

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions demo/neighbors/neighborhood_definitions.ipynb

Large diffs are not rendered by default.

42 changes: 29 additions & 13 deletions demo/neighbors/quantitative_neighbor_maps.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.6"
}
},
"nbformat": 4,
Expand Down
147 changes: 35 additions & 112 deletions demo/tissues/parametric_maps.ipynb

Large diffs are not rendered by default.

163 changes: 42 additions & 121 deletions demo/tissues/tissue_neighborhood_quantification.ipynb

Large diffs are not rendered by default.

681 changes: 681 additions & 0 deletions demo/transforms/affine_transforms.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions demo/tribolium_morphometry/tribolium.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
def workflow(input: Image, sigma=3, threshold : float = 30) -> Labels:
if input:
# push image to GPU memory and show it
gpu_input = cle.push_zyx(input.data)
gpu_input = cle.push(input.data)

# Spot detection
# After some noise removal/smoothing, we perform a local maximum detection
Expand Down Expand Up @@ -86,7 +86,7 @@ def workflow(input: Image, sigma=3, threshold : float = 30) -> Labels:

gpu_labels = cle.mask(flip, flap)

output = cle.pull_zyx(gpu_labels)
output = cle.pull(gpu_labels)
return output

# Start up napari
Expand Down
261 changes: 49 additions & 212 deletions demo/tribolium_morphometry/tribolium_morphometry.ipynb

Large diffs are not rendered by default.

Binary file added docs/images/screenshot_affine_transforms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ results of the GPU-accelerated statistics are dictionaries which contain the sam
* `mode_of_proximal_neighbors_map` and alias `mode_of_distal_neighbors_map`
* `standard_deviation_of_n_nearest_neighbors_map`
* `standard_deviation_of_proximal_neighbors_map` and alias `standard_deviation_of_distal_neighbors_map`
* `affine_transform` (yet without shearing)
* `translate`
* `rotate`
* `scale`
* `rigid_transform`

### Backwards compatibility breaking changes
* `statistics_of_labelled_pixels` and `statistics_of_background_and_labelled_pixels` produce different output now.
Expand All @@ -49,6 +54,9 @@ dictionaries,e.g. `stats['area']` instead of `[s.area for s in stats]`. If not p
* `n_closest_points` ignores the background position and the distance to labels themselves per default now.
Consider passing `ignore_background=False` and `ignore_self=False` to go back to former functionality.

### Deprecation warnings
* `resample` has been deprecated. Use `scale` instead.

### Bug fixes
* `imshow` in 3D caused an error
* `push_regionprops_column` didn't actually push
Expand Down
1 change: 1 addition & 0 deletions pyclesperanto_prototype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ._tier3 import *
from ._tier4 import *
from ._tier5 import *
from ._tier8 import *
from ._tier9 import *

__version__ = "0.6.0"
5 changes: 3 additions & 2 deletions pyclesperanto_prototype/_tier0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
create_2d_yx,
create_2d_zx,
create_2d_zy,
create_2d_yz,
create_none,
)
from ._execute import execute
from ._operations import operation
from ._operations import operations
from ._pull import pull
from ._pull import pull_zyx
from ._push import push
from ._pull import pull
from ._push import push_zyx
from ._push import push
from ._plugin_function import plugin_function
from ._types import Image
from ._cl_info import cl_info
Expand Down
35 changes: 30 additions & 5 deletions pyclesperanto_prototype/_tier0/_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def create_from_pointlist(pointlist: OCLArray, *args):
from .._tier1 import maximum_x_projection
from .._tier0 import pull

max_pos = pull(maximum_x_projection(pointlist)).astype(int)
max_pos = pull(maximum_x_projection(pointlist)).T.astype(int)
max_pos = max_pos[0]

if len(max_pos) == 3: # 3D image requested
Expand Down Expand Up @@ -89,17 +89,42 @@ def create_square_matrix_from_two_labelmaps(labelmap1: OCLArray, labelmap2: OCLA
def create_vector_from_square_matrix(square_matrix : OCLArray, *args):
return create([1, square_matrix.shape[0]])


def create_2d_xy(input):
return create([input.shape[2], input.shape[1]])
if len(input.shape) == 3:
return create([input.shape[2], input.shape[1]])
else:
return create([input.shape[1], input.shape[0]])

def create_2d_yx(input):
return create([input.shape[1], input.shape[2]])
if len(input.shape) == 3:
return create([input.shape[1], input.shape[2]])
else:
return create([input.shape[0], 1])

def create_2d_zy(input):
return create([input.shape[0], input.shape[1]])
if len(input.shape) == 3:
return create([input.shape[0], input.shape[1]])
else:
return create([1, input.shape[0]])

def create_2d_yz(input):
if len(input.shape) == 3:
return create([input.shape[1], input.shape[0]])
else:
return create([input.shape[0], 1])

def create_2d_zx(input):
return create([input.shape[0], input.shape[2]])
if len(input.shape) == 3:
return create([input.shape[0], input.shape[2]])
else:
return create([1, input.shape[1]])

def create_2d_xz(input):
if len(input.shape) == 3:
return create([input.shape[2], input.shape[0]])
else:
return create([input.shape[1], 1])

def create_none(*args):
return None
14 changes: 6 additions & 8 deletions pyclesperanto_prototype/_tier0/_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ def pull(oclarray):
----------
.. [1] https://clij.github.io/clij2-docs/reference_pull
"""
import warnings
warnings.warn(
"Deprecated: The behaviour of `pull()` will change in a future release. Switch to using push_zyx now to prvent issues in the future.",
DeprecationWarning
)

return oclarray.get().T

return oclarray.get()

def pull_zyx(oclarray):
import warnings
warnings.warn(
"Deprecated: `pull_zyx()` is now deprecated as it does the same as `pull()`.",
DeprecationWarning
)
return oclarray.get()
14 changes: 7 additions & 7 deletions pyclesperanto_prototype/_tier0/_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ def push(any_array):
----------
.. [1] https://clij.github.io/clij2-docs/reference_push
"""
import warnings
warnings.warn(
"Deprecated: The behaviour of `push()` will change in a future release. Switch to using push_zyx now to prevent issues in the future.",
DeprecationWarning
)

if isinstance(any_array, OCLArray):
return any_array

transposed = any_array.astype(np.float32).T
transposed = any_array.astype(np.float32)
return OCLArray.from_array(transposed)


def push_zyx(any_array):
import warnings
warnings.warn(
"Deprecated: `push_zyx()` is now deprecated as it does the same as `push()`.",
DeprecationWarning
)

if isinstance(any_array, OCLArray):
return any_array

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .._tier1 import copy
from .._tier0 import empty_image_like
from .._tier0 import push_zyx
from .._tier0 import push
from .._tier0 import execute
from .._tier0 import plugin_function
Expand Down
4 changes: 2 additions & 2 deletions pyclesperanto_prototype/_tier1/_maximum_x_projection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .._tier0 import execute
from .._tier0 import plugin_function
from .._tier0 import Image
from .._tier0 import create_2d_zy
from .._tier0 import create_2d_yz

@plugin_function(output_creator=create_2d_zy, categories=['projection'])
@plugin_function(output_creator=create_2d_yz, categories=['projection'])
def maximum_x_projection(source : Image, destination_max : Image = None):
"""Determines the maximum intensity projection of an image along X.

Expand Down
9 changes: 7 additions & 2 deletions pyclesperanto_prototype/_tier1/_resample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .._tier1 import copy
from .._tier0 import empty_image_like
from .._tier0 import push_zyx
from .._tier0 import push
from .._tier0 import execute
from .._tier0 import plugin_function
Expand Down Expand Up @@ -30,6 +29,12 @@ def resample(source : Image, destination : Image = None, factor_x : float = 1, f
----------
.. [1] https://clij.github.io/clij2-docs/reference_resample
"""
import warnings
warnings.warn(
"Deprecated: pyclesperanto_prototype.resample() is deprecated. Use scale() instead",
DeprecationWarning
)

import numpy as np

source_dimensions = source.shape
Expand All @@ -52,7 +57,7 @@ def resample(source : Image, destination : Image = None, factor_x : float = 1, f
if destination is None:
destination = create(destination_dimensions)

gpu_transform_matrix = push_zyx(transform_matrix)
gpu_transform_matrix = push(transform_matrix)

kernel_suffix = ''
if linear_interpolation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def write_values_to_positions(positions_and_values : Image, destination : Image
"""

if destination is None:
max_pos = pull(maximum_x_projection(positions_and_values)).astype(int)
max_pos = pull(maximum_x_projection(positions_and_values)).T.astype(int)
max_pos = max_pos[0]

if len(max_pos) == 4: # 3D image requested
Expand Down
9 changes: 4 additions & 5 deletions pyclesperanto_prototype/_tier3/_exclude_labels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pyclesperanto_prototype._tier0 import plugin_function
from pyclesperanto_prototype._tier0 import Image
from .._tier0 import push
from .._tier0 import push_zyx
from .._tier0 import pull
from .._tier0 import create_none
from .._tier0 import create_like
Expand Down Expand Up @@ -41,15 +40,15 @@ def exclude_labels(binary_flaglist : Image, label_map_input : Image, label_map_d

flaglist_np = pull(binary_flaglist)

flaglist_np[0] = 0
flaglist_np[0][0] = 0

count = 1
for i in range(1, num_labels):
if (flaglist_np[i] == 0):
flaglist_np[i] = count
if (flaglist_np[0][i] == 0):
flaglist_np[0][i] = count
count = count + 1
else:
flaglist_np[i] = 0
flaglist_np[0][i] = 0

label_index_map = push(flaglist_np)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from .._tier0 import plugin_function
from .._tier0 import Image
from .. import smaller_constant, greater_constant, binary_or
from .._tier0 import push
from .._tier0 import push_zyx
from .._tier0 import pull
from .._tier0 import create_none
from .._tier0 import create_like
from .._tier1 import replace_intensities
import numpy as np

@plugin_function(output_creator=create_none, categories=['label processing', 'in assistant'])
def exclude_labels_outside_size_range(input : Image, destination : Image = None, minimum_size : float = 0, maximum_size : float = 100):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from .._tier0 import plugin_function
from .._tier0 import Image
from .. import smaller_constant, greater_constant, binary_or
from .._tier0 import push
from .._tier0 import push_zyx
from .._tier0 import pull
from .._tier0 import create_none
from .._tier0 import create_like
from .._tier1 import replace_intensities
import numpy as np

@plugin_function(output_creator=create_none, categories=['label processing'])
def exclude_labels_with_values_out_of_range(values_vector : Image, label_map_input : Image, label_map_destination : Image = None, minimum_value_range : float = 0, maximum_value_range : float = 100):
Expand Down
Loading