Skip to content

Commit

Permalink
Merge pull request #70 from lagru/update-to-0-19
Browse files Browse the repository at this point in the history
WIP: Update notebooks for EuroSciPy 2022
  • Loading branch information
emmanuelle authored Aug 23, 2022
2 parents fdbe476 + 69675bb commit e06284c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 26 deletions.
6 changes: 3 additions & 3 deletions lectures/00_images_are_arrays.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,13 @@
"green = np.zeros((300, 300))\n",
"blue = np.zeros((300, 300))\n",
"\n",
"r, c = draw.circle(100, 100, 100)\n",
"r, c = draw.disk(center=(100, 100), radius=100)\n",
"red[r, c] = 1\n",
"\n",
"r, c = draw.circle(100, 200, 100)\n",
"r, c = draw.disk(center=(100, 200), radius=100)\n",
"green[r, c] = 1\n",
"\n",
"r, c = draw.circle(200, 150, 100)\n",
"r, c = draw.disk(center=(200, 150), radius=100)\n",
"blue[r, c] = 1\n",
"\n",
"f, axes = plt.subplots(1, 3)\n",
Expand Down
2 changes: 1 addition & 1 deletion lectures/3_morphological_operations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"metadata": {},
"outputs": [],
"source": [
"skdemo.imshow_all(image, morphology.erosion(image, sq), shape=(1, 2))"
"skdemo.imshow_all(image, morphology.erosion(image, sq))"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion lectures/4_segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
"indices = draw.circle_perimeter(100, 220, 25)\n",
"\n",
"astronaut_labels[indices] = 1\n",
"astronaut_labels[points[:, 1].astype(np.int), points[:, 0].astype(np.int)] = 2\n",
"astronaut_labels[points[:, 1].astype(int), points[:, 0].astype(int)] = 2\n",
"\n",
"image_show(astronaut_labels);"
]
Expand Down
10 changes: 5 additions & 5 deletions lectures/5_tophat_filters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
}
],
"source": [
"image_show(morph.closing(text, selem=morph.rectangle(3,3)))"
"image_show(morph.closing(text, footprint=morph.rectangle(3,3)))"
]
},
{
Expand Down Expand Up @@ -218,7 +218,7 @@
}
],
"source": [
"image_show(morph.closing(text, selem=morph.rectangle(31,31)))"
"image_show(morph.closing(text, footprint=morph.rectangle(31,31)))"
]
},
{
Expand Down Expand Up @@ -263,7 +263,7 @@
}
],
"source": [
"bth = morph.black_tophat(text, selem=morph.rectangle(31,31))\n",
"bth = morph.black_tophat(text, footprint=morph.rectangle(31,31))\n",
"image_show(bth)"
]
},
Expand Down Expand Up @@ -366,7 +366,7 @@
"elapsed = list()\n",
"for sz in [3, 11, 31]:\n",
" tic=time.perf_counter()\n",
" a = morph.closing(text, selem=morph.rectangle(sz,sz))\n",
" a = morph.closing(text, footprint=morph.rectangle(sz,sz))\n",
" elapsed.append(time.perf_counter()-tic)\n",
"\n",
"print(elapsed)"
Expand All @@ -392,7 +392,7 @@
"elapsed = list()\n",
"for sz in [3, 11, 31]:\n",
" tic=time.perf_counter()\n",
" a = morph.closing(text, selem=morph.disk(sz))\n",
" a = morph.closing(text, footprint=morph.disk(sz))\n",
" elapsed.append(time.perf_counter()-tic)\n",
"\n",
"print(elapsed)\n",
Expand Down
2 changes: 1 addition & 1 deletion lectures/6_watershed_tricks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"peak_mask = np.zeros_like(smoothed, dtype=bool)\n",
"peak_mask[tuple(peak_idx.T)] = True\n",
"# dilate them and label\n",
"peak_mask = skimage.morphology.dilation(peak_mask, selem=skimage.morphology.square(11))\n",
"peak_mask = skimage.morphology.dilation(peak_mask, footprint=skimage.morphology.square(11))\n",
"# display\n",
"peak_overlay = skimage.color.label2rgb(peak_mask, image=smoothed, bg_label=0)\n",
"a=image_show(peak_overlay)"
Expand Down
29 changes: 19 additions & 10 deletions lectures/skdemo/_skdemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,39 @@ def imshow_rgb_shifted(rgb_image, shift=100, ax=None):
ax.set_axis_off()


def imshow_all(*images, **kwargs):
def imshow_all(
*images, limits='image', titles=None, shape=None, size=5, **kwargs
):
""" Plot a series of images side-by-side.
Convert all images to float so that images have a common intensity range.
Parameters
----------
limits : str
images : tuple
The images to plot.
limits : 'image' or 'dtype', optional
Control the intensity limits. By default, 'image' is used set the
min/max intensities to the min/max of all images. Setting `limits` to
'dtype' can also be used if you want to preserve the image exposure.
titles : list of str
Titles for subplots. If the length of titles is less than the number
of images, empty strings are appended.
shape : tuple, optional
A two-element tuple that defines the shape of the subfigure grid as
(rows, columns). If not given, all `ìmages` are shown in a single row.
size : int, optional
Width and height of each subplot in inches.
kwargs : dict
Additional keyword-arguments passed to `imshow`.
"""
images = [img_as_float(img) for img in images]

titles = kwargs.pop('titles', [])
if titles is None:
titles = []
if len(titles) != len(images):
titles = list(titles) + [''] * (len(images) - len(titles))

limits = kwargs.pop('limits', 'image')
if limits == 'image':
kwargs.setdefault('vmin', min(img.min() for img in images))
kwargs.setdefault('vmax', max(img.max() for img in images))
Expand All @@ -74,13 +83,13 @@ def imshow_all(*images, **kwargs):
kwargs.setdefault('vmin', vmin)
kwargs.setdefault('vmax', vmax)

nrows, ncols = kwargs.get('shape', (1, len(images)))
if shape is None:
shape = (1, len(images))
nrows, ncols = shape

size = nrows * kwargs.pop('size', 5)
width = size * len(images)
if nrows > 1:
width /= nrows * 1.33
fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(width, size))
height = nrows * size
width = ncols * size
fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(width, height))
for ax, img, label in zip(axes.ravel(), images, titles):
ax.imshow(img, **kwargs)
ax.set_title(label)
Expand Down
6 changes: 3 additions & 3 deletions lectures/solutions/00_images_are_arrays.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@
"green = np.zeros((300, 300))\n",
"blue = np.zeros((300, 300))\n",
"\n",
"r, c = draw.circle(100, 100, 100)\n",
"r, c = draw.disk(center=(100, 100), radius=100)\n",
"red[r, c] = 1\n",
"\n",
"r, c = draw.circle(100, 200, 100)\n",
"r, c = draw.disk(center=(100, 200), radius=100)\n",
"green[r, c] = 1\n",
"\n",
"r, c = draw.circle(200, 150, 100)\n",
"r, c = draw.disk(center=(200, 150), radius=100)\n",
"blue[r, c] = 1\n",
"\n",
"f, axes = plt.subplots(1, 3)\n",
Expand Down
2 changes: 1 addition & 1 deletion lectures/solutions/1_image_filters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2526,7 +2526,7 @@
"* [Rank filters example](http://scikit-image.org/docs/dev/auto_examples/applications/plot_rank_filters.html)\n",
"* [Restoration API](http://scikit-image.org/docs/stable/api/skimage.restoration.html)\n",
"\n",
"Take a look at this [neat feature](https://github.com/scikit-image/scikit-image/pull/2647) merged last year:\n",
"Take a look at this [neat feature](https://github.com/scikit-image/scikit-image/pull/2647):\n",
"\n",
"![cycle spinning](../images/cycle_spin.png)"
]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scikit-image[data] >= 0.18
scikit-image[data] >= 0.19
numpy >= 1.12
scipy >= 1.0
matplotlib >= 2.1
Expand Down

0 comments on commit e06284c

Please sign in to comment.