-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.py
More file actions
54 lines (34 loc) · 1.4 KB
/
Copy pathImage.py
File metadata and controls
54 lines (34 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from scipy.misc import imread
from skimage.exposure import histogram
from sklearn import preprocessing
from pyemd import emd
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
#img = io.imread("..\\Data\\Train\\10.jpg")
#imgComposed = np.zeros((img.shape[0], img.shape[1]), dtype=int32)
#for i in range(img.shape[0]):
# for j in range(img.shape[1]):
# imgComposed[i, j] = 0x10000*img[i,j,0] + 0x100*img[i,j,1] + 0x10000*img[i,j,2]
#imgNorm = preprocessing.minmax_scale(imgComposed.astype(float))
#np.histogram(imgNorm)
def convColors(a):
return 0x10000*a[0] + 0x100*a[1] + 0x10000*a[2]
def calcImageHist(imagePath, nbins):
img = io.imread(imagePath)
imgComposed = np.apply_along_axis(convColors, 2, img)
imgNorm = preprocessing.minmax_scale(imgComposed.astype(float))[0]
return np.histogram(imgNorm, bins=nbins)
def calcImageHistFast(imagePath, nbins):
img = imread(imagePath, mode="F")
return np.histogram(preprocessing.minmax_scale(img), bins=nbins)[0]
def chiSquareDistance(h1, h2):
return np.sum((h1-h2)**2/(h1+h2+1e-10))
def emdDistance(h1, h2):
return emd(h1, h2, np.ones((h1.shape[0], h1.shape[0]))/2)
#from sklearn.decomposition import PCA
#pca = PCA(n_components='mle', whiten=True)
#img = io.imread("..\\Data\\Train\\10.jpg", as_grey=True)
#xx = pca.fit_transform(img)