In [1]:
import numpy as np
from scipy.cluster.vq import kmeans2
from scipy import ndimage as ndi
import matplotlib.pyplot as plt
from skimage import data
from skimage import color
from skimage.util.shape import view_as_windows
from skimage.util.montage import montage2d
Bad key "axes.spines.right" on line 210 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.flierprops.linewidth" on line 321 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "contour.corner_mask" on line 306 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.vertical" on line 339 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.meanprops.color" on line 327 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.bootstrap" on line 312 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "ytick.minor.visible" on line 230 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.capprops.linestyle" on line 317 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "legend.facecolor" on line 266 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.grid.axis" on line 173 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.patchartist" on line 334 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
C:\Anaconda\lib\site-packages\matplotlib\__init__.py:1039: UserWarning: Bad val "None" on line #264
"legend.framealpha : None # opacity of of legend frame
"
in file "C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle"
Key legend.framealpha: Could not convert "None" to float
(val, error_details, msg))
Bad key "boxplot.meanline" on line 326 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.flierprops.color" on line 319 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.spines.left" on line 209 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.whiskerprops.linestyle" on line 341 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.capprops.color" on line 316 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.medianprops.linestyle" on line 331 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.flierprops.markeredgecolor" on line 323 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.spines.top" on line 211 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "legend.edgecolor" on line 267 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.spines.bottom" on line 208 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.prop_cycle" on line 201 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.whiskerprops.linewidth" on line 342 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.medianprops.linewidth" on line 332 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.showmeans" on line 338 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.meanprops.linestyle" on line 328 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.capprops.linewidth" on line 318 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.boxprops.linewidth" on line 315 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "animation.html" on line 492 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.showcaps" on line 336 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.meanprops.linewidth" on line 329 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "figure.titlesize" on line 273 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "xtick.minor.visible" on line 219 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.boxprops.color" on line 313 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.flierprops.markerfacecolor" on line 324 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.notch" on line 333 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.boxprops.linestyle" on line 314 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "figure.titleweight" on line 274 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "markers.fillstyle" on line 20 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.labelpad" on line 177 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.flierprops.marker" on line 322 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.medianprops.color" on line 330 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.showfliers" on line 337 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.flierprops.markersize" on line 325 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.whiskerprops.color" on line 340 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.flierprops.linestyle" on line 320 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.whiskers" on line 343 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "errorbar.capsize" on line 309 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "image.composite_image" on line 302 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "boxplot.showbox" on line 335 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\classic.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.prop_cycle" on line 2 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\seaborn-bright.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.prop_cycle" on line 2 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\seaborn-colorblind.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.prop_cycle" on line 2 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\seaborn-dark-palette.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.prop_cycle" on line 2 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\seaborn-deep.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.prop_cycle" on line 2 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\seaborn-muted.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
Bad key "axes.prop_cycle" on line 2 in
C:\Anaconda\lib\site-packages\matplotlib\mpl-data\stylelib\seaborn-pastel.mplstyle.
You probably need to get an updated matplotlibrc file from
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution
In [2]:
%matplotlib inline
In [3]:
np.random.seed(42)
patch_shape = 8, 8
n_filters = 49
astro = color.rgb2gray(data.astronaut())
# -- filterbank1 on original image
patches1 = view_as_windows(astro, patch_shape)
patches1 = patches1.reshape(-1, patch_shape[0] * patch_shape[1])[::8]
fb1, _ = kmeans2(patches1, n_filters, minit='points')
fb1 = fb1.reshape((-1,) + patch_shape)
fb1_montage = montage2d(fb1, rescale_intensity=True)
# -- filterbank2 LGN-like image
astro_dog = ndi.gaussian_filter(astro, .5) - ndi.gaussian_filter(astro, 1)
patches2 = view_as_windows(astro_dog, patch_shape)
patches2 = patches2.reshape(-1, patch_shape[0] * patch_shape[1])[::8]
fb2, _ = kmeans2(patches2, n_filters, minit='points')
fb2 = fb2.reshape((-1,) + patch_shape)
fb2_montage = montage2d(fb2, rescale_intensity=True)
# --
fig, axes = plt.subplots(2, 2, figsize=(7, 6))
ax = axes.ravel()
ax[0].imshow(astro, cmap=plt.cm.gray)
ax[0].set_title("Image (original)")
ax[1].imshow(fb1_montage, cmap=plt.cm.gray, interpolation='nearest')
ax[1].set_title("K-means filterbank (codebook)\non original image")
ax[2].imshow(astro_dog, cmap=plt.cm.gray)
ax[2].set_title("Image (LGN-like DoG)")
ax[3].imshow(fb2_montage, cmap=plt.cm.gray, interpolation='nearest')
ax[3].set_title("K-means filterbank (codebook)\non LGN-like DoG image")
for a in ax.ravel():
a.axis('off')
fig.tight_layout()
plt.show()
C:\Anaconda\lib\site-packages\skimage\util\shape.py:237: RuntimeWarning: Cannot provide views on a non-contiguous input array without copying.
warn(RuntimeWarning("Cannot provide views on a non-contiguous input "
C:\Anaconda\lib\site-packages\scipy\cluster\vq.py:648: UserWarning: One of the clusters is empty. Re-run kmean with a different initialization.
warnings.warn("One of the clusters is empty. "
In [8]:
plt.imshow(astro,cmap=plt.cm.gray)
Out[8]:
<matplotlib.image.AxesImage at 0x1931eb70>
In [15]:
view_as_windows(astro, patch_shape).shape
Out[15]:
(505L, 505L, 8L, 8L)
In [16]:
astro.shape
Out[16]:
(512L, 512L)
In [20]:
patch_shape+(-1,)
Out[20]:
(8, 8, -1)
In [25]:
fb1.shape
Out[25]:
(49L, 8L, 8L)
In [ ]:
Content source: wasit7/algae2
Similar notebooks: