Example #1
0
from PIL import Image
from numpy import *
from pylab import *
from imtools import pca, get_imlist


imlist = get_imlist('../data/a_thumbs')
print(imlist)

im = array(Image.open(imlist[0]))
m, n = im.shape[0:2]
imnbr = len(imlist)

immatrix = array([array(Image.open(im)).flatten() for im in imlist], 'f')

V, S, immean = pca(immatrix)
figure()
gray()
subplot(2, 4, 1)
imshow(immean.reshape(m, n))
for i in range(7):
    subplot(2, 4, i+2)
    imshow(V[i].reshape(m, n))

show()
Example #2
0
imshow(pil_img,cmap=cm.Greys_r)
subplot(222)
imshow(im5,cmap=cm.Greys_r)
subplot(223)
plot(cdf)
###########################################################
close("all")
# pca
imlist = imtools.get_imlist('gwb_cropped')
im = array(Image.open(imlist[0]))
m,n = im.shape[0:2]
imnbr = len(imlist)

immatrix = array([array(Image.open(im)).flatten() for im in imlist],'f')
# perform PCA
V,S,immean= imtools.pca(immatrix)


figure()

subplot(2,4,1)
imshow(immean.reshape(m,n))
for i in range(7):
    subplot(2,4,i+2)
    imshow(V[i].reshape(m,n))

show()

############################################################
#bluring image test
from scipy.ndimage import filters
Example #3
0
#im2,cdf = it.histeq(im)

## Test PCA
# put file names in list
font_list = it.get_imlist('../data/a_thumbs')
# open an image to get a size
im = np.array(Image.open(font_list[0]))
m,n = im.shape[0:2] # get size of the images
imnbr = len(font_list) # get the number of images

# create matrix to store all flattened images
immatrix = np.array([np.array(Image.open(im)).flatten()
            for im in font_list],'f')

# perform PCA
V,S, immean = it.pca(immatrix)

# show some images (mean and 7 first modes)
pl.figure()
pl.gray()
pl.subplot(2,4,1)
pl.imshow(immean.reshape(m,n))
for i in range(7):
    pl.subplot(2,4,i+2)
    pl.imshow(V[i].reshape(m,n))

pl.savefig('pca_dicking_around.png')

# Make 3x4 image
plt.figure()
plt.gray()
Example #4
0
"""

from PIL import Image
import numpy as np
import pylab as pl
import imtools

image_list = []
image = np.array(Image.open(image_list[0]))
m, n = image.shape[0:2]  # 画像のサイズ
image_num = len(image_list)  # 画像数

# 全ての平板化画像を格納する行列を作成
image_matrix = np.array(
    [np.array(Image.open(image)).flatten() for image in image_list], 'f')

# 主成分分析を実行
V, S, image_mean = imtools.pca(image_matrix)

# 画像を表示(平均と,最初の7つの主成分)
pl.figure()
pl.gray()
pl.subplot(2, 4, 1)
pl.imshow(image_mean.reshape(m, n))

for i in np.renge(7):
    pl.subplot(2, 4, i + 2)
    pl.imshow(V[i].reshape(m, n))

pl.show()
Example #5
0
digitdata = pd.read_csv('digits_train.csv')
labels = digitdata['label']
digitdata = digitdata.iloc[:, 1:]
len(digitdata.columns.values)
rows = 28
cols = 28
imshow(digitdata.iloc[3, :].reshape(cols, rows))

V = pca2(digitdata, 7)
V.shape
V[1].shape
subplot(2, 4, 1)
imshow(immean.reshape(cols, rows))
for i in range(7):
    subplot(2, 4, i + 2)
    imshow(V[i].reshape(cols, rows))
show()

V, S, immean = pca(digitdata)
# show some images (mean and 7 first modes)
figure()
gray()
subplot(2, 4, 1)
imshow(immean.reshape(cols, rows))
for i in range(7):
    subplot(2, 4, i + 2)
    imshow(V[i].reshape(cols, rows))
show()
all(V.flatten())