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

Add pyramid_gaussian support for float32 #4696

Merged
merged 1 commit into from May 12, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion skimage/transform/pyramids.py
Expand Up @@ -7,7 +7,7 @@

def _smooth(image, sigma, mode, cval, multichannel=None):
"""Return image with each channel smoothed by the Gaussian filter."""
smoothed = np.empty(image.shape, dtype=np.double)
smoothed = np.empty_like(image)

# apply Gaussian filter to all channels independently
if multichannel:
Expand Down
12 changes: 11 additions & 1 deletion skimage/transform/tests/test_pyramids.py
@@ -1,12 +1,12 @@
import math
import pytest
import numpy as np
from skimage import data
from skimage.transform import pyramids

from skimage._shared import testing
from skimage._shared.testing import (assert_array_equal, assert_, assert_equal,
assert_almost_equal)
from skimage._shared._warnings import expected_warnings


image = data.astronaut()
Expand Down Expand Up @@ -135,3 +135,13 @@ def test_check_factor():
pyramids._check_factor(0.99)
with testing.raises(ValueError):
pyramids._check_factor(- 2)


@pytest.mark.parametrize('dtype, expected',
zip(['float32', 'float64', 'uint8', 'int64'],
['float32', 'float64', 'float64', 'float64']))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A list of tuples would have been clearer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitated =)

def test_pyramid_gaussian_dtype_support(dtype, expected):
img = np.random.randn(32, 8).astype(dtype)
pyramid = pyramids.pyramid_gaussian(img)

assert np.all([im.dtype == expected for im in pyramid])