Skip to content

Commit

Permalink
Merge branch 'master' of github.com:scikit-image/scikit-image into fe…
Browse files Browse the repository at this point in the history
…ature_hog_review
  • Loading branch information
PuppySaturation committed Jan 25, 2015
2 parents 6bc40d7 + 8b24d27 commit 4999910
Show file tree
Hide file tree
Showing 48 changed files with 878 additions and 529 deletions.
5 changes: 4 additions & 1 deletion CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,7 @@
Extended the image labelling implementation so it also works on 3D images.

- Salvatore Scaramuzzino
RectTool example
RectTool example

- Kevin Keraudren
Fix and test for feature.peak_local_max
3 changes: 0 additions & 3 deletions bento.info
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ Library:
Extension: skimage.graph._spath
Sources:
skimage/graph/_spath.pyx
Extension: skimage.morphology.cmorph
Sources:
skimage/morphology/cmorph.pyx
Extension: skimage.graph.heap
Sources:
skimage/graph/heap.pyx
Expand Down
1 change: 0 additions & 1 deletion skimage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import imp as _imp
import functools as _functools
import warnings as _warnings
from skimage._shared.utils import deprecated as _deprecated

pkg_dir = _osp.abspath(_osp.dirname(__file__))
data_dir = _osp.join(pkg_dir, 'data')
Expand Down
28 changes: 14 additions & 14 deletions skimage/draw/_draw.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def _coords_inside_image(rr, cc, shape, val=None):
rr, cc : (N,) ndarray of int
Indices of pixels.
shape : tuple
Image shape which is used to determine maximum extents of output pixel
coordinates.
Image shape which is used to determine the maximum extent of output
pixel coordinates.
val : ndarray of float, optional
Values of pixels at coordinates [rr, cc].
Expand Down Expand Up @@ -223,9 +223,9 @@ def polygon(y, x, shape=None):
x : (N,) ndarray
X-coordinates of vertices of polygon.
shape : tuple, optional
Image shape which is used to determine maximum extents of output pixel
coordinates. This is useful for polygons which exceed the image size.
By default the full extents of the polygon are used.
Image shape which is used to determine the maximum extent of output
pixel coordinates. This is useful for polygons which exceed the image
size. By default the full extent of the polygon are used.
Returns
-------
Expand Down Expand Up @@ -303,9 +303,9 @@ def circle_perimeter(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t radius,
bresenham : Bresenham method (default)
andres : Andres method
shape : tuple, optional
Image shape which is used to determine maximum extents of output pixel
Image shape which is used to determine the maximum extent of output pixel
coordinates. This is useful for circles which exceed the image size.
By default the full extents of the polygon are used.
By default the full extent of the circle are used.
Returns
-------
Expand Down Expand Up @@ -411,9 +411,9 @@ def circle_perimeter_aa(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t radius,
radius: int
Radius of circle.
shape : tuple, optional
Image shape which is used to determine maximum extents of output pixel
Image shape which is used to determine the maximum extent of output pixel
coordinates. This is useful for circles which exceed the image size.
By default the full extents of the polygon are used.
By default the full extent of the circle are used.
Returns
-------
Expand Down Expand Up @@ -499,9 +499,9 @@ def ellipse_perimeter(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t yradius,
orientation : double, optional (default 0)
Major axis orientation in clockwise direction as radians.
shape : tuple, optional
Image shape which is used to determine maximum extents of output pixel
Image shape which is used to determine the maximum extent of output pixel
coordinates. This is useful for ellipses which exceed the image size.
By default the full extents of the polygon are used.
By default the full extent of the ellipse are used.
Returns
-------
Expand Down Expand Up @@ -774,9 +774,9 @@ def bezier_curve(Py_ssize_t y0, Py_ssize_t x0,
weight : double
Middle control point weight, it describes the line tension.
shape : tuple, optional
Image shape which is used to determine maximum extents of output pixel
coordinates. This is useful for curves which exceed the image size.
By default the full extents of the polygon are used.
Image shape which is used to determine the maximum extent of output
pixel coordinates. This is useful for curves which exceed the image
size. By default the full extent of the curve are used.
Returns
-------
Expand Down
8 changes: 4 additions & 4 deletions skimage/draw/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def ellipse(cy, cx, yradius, xradius, shape=None):
yradius, xradius : double
Minor and major semi-axes. ``(x/xradius)**2 + (y/yradius)**2 = 1``.
shape : tuple, optional
Image shape which is used to determine maximum extents of output pixel
Image shape which is used to determine the maximum extent of output pixel
coordinates. This is useful for ellipses which exceed the image size.
By default the full extents of the ellipse are used.
By default the full extent of the ellipse are used.
Returns
-------
Expand Down Expand Up @@ -85,9 +85,9 @@ def circle(cy, cx, radius, shape=None):
radius: double
Radius of circle.
shape : tuple, optional
Image shape which is used to determine maximum extents of output pixel
Image shape which is used to determine the maximum extent of output pixel
coordinates. This is useful for circles which exceed the image size.
By default the full extents of the circle are used.
By default the full extent of the circle are used.
Returns
-------
Expand Down
4 changes: 2 additions & 2 deletions skimage/feature/peak.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ def peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1,
peak_threshold = max(np.max(image.ravel()) * threshold_rel, threshold_abs)

# get coordinates of peaks
coordinates = np.transpose((image > peak_threshold).nonzero())
coordinates = np.argwhere(image > peak_threshold)

if coordinates.shape[0] > num_peaks:
intensities = image[coordinates[:, 0], coordinates[:, 1]]
intensities = image.flat[np.ravel_multi_index(coordinates.transpose(),image.shape)]
idx_maxsort = np.argsort(intensities)[::-1]
coordinates = coordinates[idx_maxsort][:num_peaks]

Expand Down
9 changes: 9 additions & 0 deletions skimage/feature/tests/test_peak.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ def test_num_peaks():
assert (3, 5) in peaks_limited


def test_num_peaks3D():
# Issue 1354: the old code only hold for 2D arrays
# and this code would die with IndexError
image = np.zeros((10, 10, 100))
image[5,5,::5] = np.arange(20)
peaks_limited = peak.peak_local_max(image, min_distance=1, num_peaks=2)
assert len(peaks_limited) == 2


def test_reorder_labels():
image = np.random.uniform(size=(40, 60))
i, j = np.mgrid[0:40, 0:60]
Expand Down
4 changes: 2 additions & 2 deletions skimage/filters/rank/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ followed by the moving window is given hereunder
/--------------------------/
\-------------------------- ...

We compare cmorph.dilate to this histogram based method to show how
We compare grey.dilate to this histogram based method to show how
computational costs increase with respect to image size or structuring element
size. This implementation gives better results for large structuring elements.

Expand All @@ -26,7 +26,7 @@ update the local histogram. The histogram size is 8-bit (256 bins) for 8-bit
images and 2 to 16-bit for 16-bit images depending on the maximum value of the
image.

The filter is applied up to the image border, the neighboorhood used is
The filter is applied up to the image border, the neighborhood used is
adjusted accordingly. The user may provide a mask image (same size as input
image) where non zero values are the part of the image participating in the
histogram computation. By default the entire image is filtered.
15 changes: 7 additions & 8 deletions skimage/filters/rank/tests/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import skimage
from skimage import img_as_ubyte, img_as_float
from skimage import data, util, morphology
from skimage.morphology import cmorph, disk
from skimage.morphology import grey, disk
from skimage.filters import rank
from skimage._shared._warnings import expected_warnings

Expand Down Expand Up @@ -87,7 +87,6 @@ def check_all():
def test_random_sizes():
# make sure the size is not a problem

niter = 10
elem = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]], dtype=np.uint8)
for m, n in np.random.random_integers(1, 100, size=(10, 2)):
mask = np.ones((m, n), dtype=np.uint8)
Expand Down Expand Up @@ -118,31 +117,31 @@ def test_random_sizes():
assert_equal(image16.shape, out16.shape)


def test_compare_with_cmorph_dilate():
def test_compare_with_grey_dilation():
# compare the result of maximum filter with dilate

image = (np.random.rand(100, 100) * 256).astype(np.uint8)
out = np.empty_like(image)
mask = np.ones(image.shape, dtype=np.uint8)

for r in range(1, 20, 1):
for r in range(3, 20, 2):
elem = np.ones((r, r), dtype=np.uint8)
rank.maximum(image=image, selem=elem, out=out, mask=mask)
cm = cmorph._dilate(image=image, selem=elem)
cm = grey.dilation(image=image, selem=elem)
assert_equal(out, cm)


def test_compare_with_cmorph_erode():
def test_compare_with_grey_erosion():
# compare the result of maximum filter with erode

image = (np.random.rand(100, 100) * 256).astype(np.uint8)
out = np.empty_like(image)
mask = np.ones(image.shape, dtype=np.uint8)

for r in range(1, 20, 1):
for r in range(3, 20, 2):
elem = np.ones((r, r), dtype=np.uint8)
rank.minimum(image=image, selem=elem, out=out, mask=mask)
cm = cmorph._erode(image=image, selem=elem)
cm = grey.erosion(image=image, selem=elem)
assert_equal(out, cm)


Expand Down
48 changes: 24 additions & 24 deletions skimage/measure/_regionprops.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,21 @@ def __init__(self, slice, label, label_image, intensity_image,
self._intensity_image = intensity_image
self._cache_active = cache_active

@_cached_property
@property
def area(self):
return self.moments[0, 0]

@_cached_property
@property
def bbox(self):
return (self._slice[0].start, self._slice[1].start,
self._slice[0].stop, self._slice[1].stop)

@_cached_property
@property
def centroid(self):
row, col = self.local_centroid
return row + self._slice[0].start, col + self._slice[1].start

@_cached_property
@property
def convex_area(self):
return np.sum(self.convex_image)

Expand All @@ -138,35 +138,35 @@ def convex_image(self):
from ..morphology.convex_hull import convex_hull_image
return convex_hull_image(self.image)

@_cached_property
@property
def coords(self):
rr, cc = np.nonzero(self.image)
return np.vstack((rr + self._slice[0].start,
cc + self._slice[1].start)).T

@_cached_property
@property
def eccentricity(self):
l1, l2 = self.inertia_tensor_eigvals
if l1 == 0:
return 0
return sqrt(1 - l2 / l1)

@_cached_property
@property
def equivalent_diameter(self):
return sqrt(4 * self.moments[0, 0] / PI)

@_cached_property
@property
def euler_number(self):
euler_array = self.filled_image != self.image
_, num = label(euler_array, neighbors=8, return_num=True)
return -num + 1

@_cached_property
@property
def extent(self):
rows, cols = self.image.shape
return self.moments[0, 0] / (rows * cols)

@_cached_property
@property
def filled_area(self):
return np.sum(self.filled_image)

Expand Down Expand Up @@ -200,35 +200,35 @@ def intensity_image(self):
raise AttributeError('No intensity image specified.')
return self._intensity_image[self._slice] * self.image

@_cached_property
@property
def _intensity_image_double(self):
return self.intensity_image.astype(np.double)

@_cached_property
@property
def local_centroid(self):
m = self.moments
row = m[0, 1] / m[0, 0]
col = m[1, 0] / m[0, 0]
return row, col

@_cached_property
@property
def max_intensity(self):
return np.max(self.intensity_image[self.image])

@_cached_property
@property
def mean_intensity(self):
return np.mean(self.intensity_image[self.image])

@_cached_property
@property
def min_intensity(self):
return np.min(self.intensity_image[self.image])

@_cached_property
@property
def major_axis_length(self):
l1, _ = self.inertia_tensor_eigvals
return 4 * sqrt(l1)

@_cached_property
@property
def minor_axis_length(self):
_, l2 = self.inertia_tensor_eigvals
return 4 * sqrt(l2)
Expand All @@ -243,15 +243,15 @@ def moments_central(self):
return _moments.moments_central(self.image.astype(np.uint8),
row, col, 3)

@_cached_property
@property
def moments_hu(self):
return _moments.moments_hu(self.moments_normalized)

@_cached_property
def moments_normalized(self):
return _moments.moments_normalized(self.moments_central, 3)

@_cached_property
@property
def orientation(self):
a, b, b, c = self.inertia_tensor.flat
b = -b
Expand All @@ -263,20 +263,20 @@ def orientation(self):
else:
return - 0.5 * atan2(2 * b, (a - c))

@_cached_property
@property
def perimeter(self):
return perimeter(self.image, 4)

@_cached_property
@property
def solidity(self):
return self.moments[0, 0] / np.sum(self.convex_image)

@_cached_property
@property
def weighted_centroid(self):
row, col = self.weighted_local_centroid
return row + self._slice[0].start, col + self._slice[1].start

@_cached_property
@property
def weighted_local_centroid(self):
m = self.weighted_moments
row = m[0, 1] / m[0, 0]
Expand All @@ -293,7 +293,7 @@ def weighted_moments_central(self):
return _moments.moments_central(self._intensity_image_double,
row, col, 3)

@_cached_property
@property
def weighted_moments_hu(self):
return _moments.moments_hu(self.weighted_moments_normalized)

Expand Down
Loading

0 comments on commit 4999910

Please sign in to comment.