Skip to content

Commit f80ec44

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 7f0e433183dcfc0d6fb5bc5e18bd2bec39e48701
1 parent 52668f8 commit f80ec44

File tree

1,043 files changed

+3273
-3240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,043 files changed

+3273
-3240
lines changed
657 Bytes
Binary file not shown.
642 Bytes
Binary file not shown.

dev/_downloads/plot_face_segmentation.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\n# Author: Gael Varoquaux <[email protected]>, Brian Cheung\n# License: BSD 3 clause\n\nimport time\n\nimport numpy as np\nimport scipy as sp\nimport matplotlib.pyplot as plt\n\nfrom sklearn.feature_extraction import image\nfrom sklearn.cluster import spectral_clustering\nfrom sklearn.externals._pilutil import imresize\n\n\n# load the raccoon face as a numpy array\ntry: # SciPy >= 0.16 have face in misc\n from scipy.misc import face\n face = face(gray=True)\nexcept ImportError:\n face = sp.face(gray=True)\n\n# Resize it to 10% of the original size to speed up the processing\nface = imresize(face, 0.10) / 255.\n\n# Convert the image into a graph with the value of the gradient on the\n# edges.\ngraph = image.img_to_graph(face)\n\n# Take a decreasing function of the gradient: an exponential\n# The smaller beta is, the more independent the segmentation is of the\n# actual image. For beta=1, the segmentation is close to a voronoi\nbeta = 5\neps = 1e-6\ngraph.data = np.exp(-beta * graph.data / graph.data.std()) + eps\n\n# Apply spectral clustering (this step goes much faster if you have pyamg\n# installed)\nN_REGIONS = 25"
29+
"print(__doc__)\n\n# Author: Gael Varoquaux <[email protected]>, Brian Cheung\n# License: BSD 3 clause\n\nimport time\n\nimport numpy as np\nimport scipy as sp\nfrom scipy.ndimage.filters import gaussian_filter\nimport matplotlib.pyplot as plt\nfrom skimage import img_as_float\nfrom skimage.transform import rescale\n\nfrom sklearn.feature_extraction import image\nfrom sklearn.cluster import spectral_clustering\n\n\n# load the raccoon face as a numpy array\ntry: # SciPy >= 0.16 have face in misc\n from scipy.misc import face\n orig_face = img_as_float(face(gray=True))\nexcept ImportError:\n orig_face = img_as_float(sp.face(gray=True))\n\n# Resize it to 10% of the original size to speed up the processing\n# Applying a Gaussian filter for smoothing prior to down-scaling\n# reduces aliasing artifacts.\nsmoothened_face = gaussian_filter(orig_face, sigma=4.5)\nrescaled_face = rescale(smoothened_face, 0.1, mode=\"reflect\")\n\n# Convert the image into a graph with the value of the gradient on the\n# edges.\ngraph = image.img_to_graph(rescaled_face)\n\n# Take a decreasing function of the gradient: an exponential\n# The smaller beta is, the more independent the segmentation is of the\n# actual image. For beta=1, the segmentation is close to a voronoi\nbeta = 5\neps = 1e-6\ngraph.data = np.exp(-beta * graph.data / graph.data.std()) + eps\n\n# Apply spectral clustering (this step goes much faster if you have pyamg\n# installed)\nN_REGIONS = 25"
3030
]
3131
},
3232
{
@@ -44,7 +44,7 @@
4444
},
4545
"outputs": [],
4646
"source": [
47-
"for assign_labels in ('kmeans', 'discretize'):\n t0 = time.time()\n labels = spectral_clustering(graph, n_clusters=N_REGIONS,\n assign_labels=assign_labels, random_state=42)\n t1 = time.time()\n labels = labels.reshape(face.shape)\n\n plt.figure(figsize=(5, 5))\n plt.imshow(face, cmap=plt.cm.gray)\n for l in range(N_REGIONS):\n plt.contour(labels == l,\n colors=[plt.cm.spectral(l / float(N_REGIONS))])\n plt.xticks(())\n plt.yticks(())\n title = 'Spectral clustering: %s, %.2fs' % (assign_labels, (t1 - t0))\n print(title)\n plt.title(title)\nplt.show()"
47+
"for assign_labels in ('kmeans', 'discretize'):\n t0 = time.time()\n labels = spectral_clustering(graph, n_clusters=N_REGIONS,\n assign_labels=assign_labels, random_state=42)\n t1 = time.time()\n labels = labels.reshape(rescaled_face.shape)\n\n plt.figure(figsize=(5, 5))\n plt.imshow(rescaled_face, cmap=plt.cm.gray)\n for l in range(N_REGIONS):\n plt.contour(labels == l,\n colors=[plt.cm.spectral(l / float(N_REGIONS))])\n plt.xticks(())\n plt.yticks(())\n title = 'Spectral clustering: %s, %.2fs' % (assign_labels, (t1 - t0))\n print(title)\n plt.title(title)\nplt.show()"
4848
]
4949
}
5050
],

dev/_downloads/plot_face_segmentation.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,31 @@
2626

2727
import numpy as np
2828
import scipy as sp
29+
from scipy.ndimage.filters import gaussian_filter
2930
import matplotlib.pyplot as plt
31+
from skimage import img_as_float
32+
from skimage.transform import rescale
3033

3134
from sklearn.feature_extraction import image
3235
from sklearn.cluster import spectral_clustering
33-
from sklearn.externals._pilutil import imresize
3436

3537

3638
# load the raccoon face as a numpy array
3739
try: # SciPy >= 0.16 have face in misc
3840
from scipy.misc import face
39-
face = face(gray=True)
41+
orig_face = img_as_float(face(gray=True))
4042
except ImportError:
41-
face = sp.face(gray=True)
43+
orig_face = img_as_float(sp.face(gray=True))
4244

4345
# Resize it to 10% of the original size to speed up the processing
44-
face = imresize(face, 0.10) / 255.
46+
# Applying a Gaussian filter for smoothing prior to down-scaling
47+
# reduces aliasing artifacts.
48+
smoothened_face = gaussian_filter(orig_face, sigma=4.5)
49+
rescaled_face = rescale(smoothened_face, 0.1, mode="reflect")
4550

4651
# Convert the image into a graph with the value of the gradient on the
4752
# edges.
48-
graph = image.img_to_graph(face)
53+
graph = image.img_to_graph(rescaled_face)
4954

5055
# Take a decreasing function of the gradient: an exponential
5156
# The smaller beta is, the more independent the segmentation is of the
@@ -66,10 +71,10 @@
6671
labels = spectral_clustering(graph, n_clusters=N_REGIONS,
6772
assign_labels=assign_labels, random_state=42)
6873
t1 = time.time()
69-
labels = labels.reshape(face.shape)
74+
labels = labels.reshape(rescaled_face.shape)
7075

7176
plt.figure(figsize=(5, 5))
72-
plt.imshow(face, cmap=plt.cm.gray)
77+
plt.imshow(rescaled_face, cmap=plt.cm.gray)
7378
for l in range(N_REGIONS):
7479
plt.contour(labels == l,
7580
colors=[plt.cm.spectral(l / float(N_REGIONS))])

dev/_downloads/plot_face_ward_segmentation.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"# Author : Vincent Michel, 2010\n# Alexandre Gramfort, 2011\n# License: BSD 3 clause\n\nprint(__doc__)\n\nimport time as time\n\nimport numpy as np\nimport scipy as sp\n\nimport matplotlib.pyplot as plt\n\nfrom sklearn.feature_extraction.image import grid_to_graph\nfrom sklearn.cluster import AgglomerativeClustering\nfrom sklearn.externals._pilutil import imresize\n\n\n# #############################################################################\n# Generate data\ntry: # SciPy >= 0.16 have face in misc\n from scipy.misc import face\n face = face(gray=True)\nexcept ImportError:\n face = sp.face(gray=True)\n\n# Resize it to 10% of the original size to speed up the processing\nface = imresize(face, 0.10) / 255.\n\nX = np.reshape(face, (-1, 1))\n\n# #############################################################################\n# Define the structure A of the data. Pixels connected to their neighbors.\nconnectivity = grid_to_graph(*face.shape)\n\n# #############################################################################\n# Compute clustering\nprint(\"Compute structured hierarchical clustering...\")\nst = time.time()\nn_clusters = 15 # number of regions\nward = AgglomerativeClustering(n_clusters=n_clusters, linkage='ward',\n connectivity=connectivity)\nward.fit(X)\nlabel = np.reshape(ward.labels_, face.shape)\nprint(\"Elapsed time: \", time.time() - st)\nprint(\"Number of pixels: \", label.size)\nprint(\"Number of clusters: \", np.unique(label).size)\n\n# #############################################################################\n# Plot the results on an image\nplt.figure(figsize=(5, 5))\nplt.imshow(face, cmap=plt.cm.gray)\nfor l in range(n_clusters):\n plt.contour(label == l,\n colors=[plt.cm.spectral(l / float(n_clusters)), ])\nplt.xticks(())\nplt.yticks(())\nplt.show()"
29+
"# Author : Vincent Michel, 2010\n# Alexandre Gramfort, 2011\n# License: BSD 3 clause\n\nprint(__doc__)\n\nimport time as time\n\nimport numpy as np\nimport scipy as sp\nfrom scipy.ndimage.filters import gaussian_filter\n\nimport matplotlib.pyplot as plt\n\nfrom skimage import img_as_float\nfrom skimage.transform import rescale\n\nfrom sklearn.feature_extraction.image import grid_to_graph\nfrom sklearn.cluster import AgglomerativeClustering\n\n\n# #############################################################################\n# Generate data\ntry: # SciPy >= 0.16 have face in misc\n from scipy.misc import face\n orig_face = img_as_float(face(gray=True))\nexcept ImportError:\n orig_face = img_as_float(sp.face(gray=True))\n\n# Resize it to 10% of the original size to speed up the processing\n# Applying a Gaussian filter for smoothing prior to down-scaling\n# reduces aliasing artifacts.\nsmoothened_face = gaussian_filter(orig_face, sigma=4.5)\nrescaled_face = rescale(smoothened_face, 0.1, mode=\"reflect\")\n\nX = np.reshape(rescaled_face, (-1, 1))\n\n# #############################################################################\n# Define the structure A of the data. Pixels connected to their neighbors.\nconnectivity = grid_to_graph(*rescaled_face.shape)\n\n# #############################################################################\n# Compute clustering\nprint(\"Compute structured hierarchical clustering...\")\nst = time.time()\nn_clusters = 15 # number of regions\nward = AgglomerativeClustering(n_clusters=n_clusters, linkage='ward',\n connectivity=connectivity)\nward.fit(X)\nlabel = np.reshape(ward.labels_, rescaled_face.shape)\nprint(\"Elapsed time: \", time.time() - st)\nprint(\"Number of pixels: \", label.size)\nprint(\"Number of clusters: \", np.unique(label).size)\n\n# #############################################################################\n# Plot the results on an image\nplt.figure(figsize=(5, 5))\nplt.imshow(rescaled_face, cmap=plt.cm.gray)\nfor l in range(n_clusters):\n plt.contour(label == l,\n colors=[plt.cm.spectral(l / float(n_clusters)), ])\nplt.xticks(())\nplt.yticks(())\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/plot_face_ward_segmentation.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,36 @@
1818

1919
import numpy as np
2020
import scipy as sp
21+
from scipy.ndimage.filters import gaussian_filter
2122

2223
import matplotlib.pyplot as plt
2324

25+
from skimage import img_as_float
26+
from skimage.transform import rescale
27+
2428
from sklearn.feature_extraction.image import grid_to_graph
2529
from sklearn.cluster import AgglomerativeClustering
26-
from sklearn.externals._pilutil import imresize
2730

2831

2932
# #############################################################################
3033
# Generate data
3134
try: # SciPy >= 0.16 have face in misc
3235
from scipy.misc import face
33-
face = face(gray=True)
36+
orig_face = img_as_float(face(gray=True))
3437
except ImportError:
35-
face = sp.face(gray=True)
38+
orig_face = img_as_float(sp.face(gray=True))
3639

3740
# Resize it to 10% of the original size to speed up the processing
38-
face = imresize(face, 0.10) / 255.
41+
# Applying a Gaussian filter for smoothing prior to down-scaling
42+
# reduces aliasing artifacts.
43+
smoothened_face = gaussian_filter(orig_face, sigma=4.5)
44+
rescaled_face = rescale(smoothened_face, 0.1, mode="reflect")
3945

40-
X = np.reshape(face, (-1, 1))
46+
X = np.reshape(rescaled_face, (-1, 1))
4147

4248
# #############################################################################
4349
# Define the structure A of the data. Pixels connected to their neighbors.
44-
connectivity = grid_to_graph(*face.shape)
50+
connectivity = grid_to_graph(*rescaled_face.shape)
4551

4652
# #############################################################################
4753
# Compute clustering
@@ -51,15 +57,15 @@
5157
ward = AgglomerativeClustering(n_clusters=n_clusters, linkage='ward',
5258
connectivity=connectivity)
5359
ward.fit(X)
54-
label = np.reshape(ward.labels_, face.shape)
60+
label = np.reshape(ward.labels_, rescaled_face.shape)
5561
print("Elapsed time: ", time.time() - st)
5662
print("Number of pixels: ", label.size)
5763
print("Number of clusters: ", np.unique(label).size)
5864

5965
# #############################################################################
6066
# Plot the results on an image
6167
plt.figure(figsize=(5, 5))
62-
plt.imshow(face, cmap=plt.cm.gray)
68+
plt.imshow(rescaled_face, cmap=plt.cm.gray)
6369
for l in range(n_clusters):
6470
plt.contour(label == l,
6571
colors=[plt.cm.spectral(l / float(n_clusters)), ])

dev/_downloads/scikit-learn-docs.pdf

4.46 KB
Binary file not shown.
229 Bytes
229 Bytes
322 Bytes

0 commit comments

Comments
 (0)