Skip to content

Instantly share code, notes, and snippets.

@Spacerat Spacerat/GLDM.ipynb
Created Feb 22, 2015

Embed
What would you like to do?
GLDM for texture classification
{
"metadata": {
"name": "",
"signature": "sha256:920f5ee2acb7b28b47d8f1887873fa7bca394ea3716286e9875891ede8564cd5"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Import libraries, load textures"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from scipy import ndimage\n",
"from scipy import misc\n",
"import matplotlib.cm as cm\n",
"import Image\n",
"from collections import namedtuple\n",
"import numpy as np\n",
"import pylab as plt\n",
"from sklearn import neighbors, datasets\n",
"from matplotlib.colors import ListedColormap\n",
"from sklearn import preprocessing\n",
"from sklearn import svm\n",
"from mpl_toolkits.mplot3d import Axes3D\n",
"from sklearn.cross_validation import train_test_split, cross_val_score\n",
"from sklearn.preprocessing import StandardScaler\n",
"from sklearn.pipeline import Pipeline\n",
"cols_light = ['#FFAAAA', '#AAFFAA', '#AAAAFF', '#FFFFAA', '#FFAAFF', '#AAFFFF']\n",
"cols_bold = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF', '#00FFFF']\n",
"cmap_light = ListedColormap(cols_light)\n",
"cmap_bold = ListedColormap(cols_bold)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 20
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Two kinds of wood, two kinds of bark, glass and marble\n",
"From the texture classification dataset at http://www-cvr.ai.uiuc.edu/ponce_grp/data/"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def load_textures():\n",
" tex = []\n",
" kinds = []\n",
" names = []\n",
" cls = 0\n",
" for T, name in [('T04','wood1'), ('T05', 'wood2'), ('T01','bark1'), ('T02', 'bark2'), ('T16', 'glass1'), ('T09', 'marble')]:\n",
" for n in range(1, 40):\n",
" tex.append(misc.imread('./{}_{}/{}_{:02}.jpg'.format(T, name, T, n)))\n",
" kinds.append(cls)\n",
" names.append(name)\n",
" cls += 1\n",
" return np.array(tex), np.array(kinds), names\n",
"\n",
"images, classes, names = load_textures()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"indexes = [1, 40,160, 90, 120, 210]\n",
"\n",
"for n, i in enumerate(indexes):\n",
" plt.subplot(2, 3, n+1)\n",
" plt.imshow(images[i], cmap=cm.Greys_r)\n",
" plt.title(names[classes[i]])\n",
"\n",
"plt.gcf().set_size_inches(14, 8)\n",
"plt.tight_layout()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.