diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..f60b80c Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f46d7e --- /dev/null +++ b/.gitignore @@ -0,0 +1,108 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +.idea/ +*.py[cod] +*$py.class + +# Mac generated files +._* + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/1000_kmeans.model b/1000_kmeans.model new file mode 100644 index 0000000..124a337 Binary files /dev/null and b/1000_kmeans.model differ diff --git a/1000_patch_PCA_matrix.mat b/1000_patch_PCA_matrix.mat new file mode 100644 index 0000000..c0219f5 Binary files /dev/null and b/1000_patch_PCA_matrix.mat differ diff --git a/1000_patch_mean_matrix.mat b/1000_patch_mean_matrix.mat new file mode 100644 index 0000000..88e9f80 Binary files /dev/null and b/1000_patch_mean_matrix.mat differ diff --git a/15_2000_kmeans.model b/15_2000_kmeans.model new file mode 100644 index 0000000..b738819 Binary files /dev/null and b/15_2000_kmeans.model differ diff --git a/15_2000_patch_PCA_matrix.mat b/15_2000_patch_PCA_matrix.mat new file mode 100644 index 0000000..d90b6b2 Binary files /dev/null and b/15_2000_patch_PCA_matrix.mat differ diff --git a/15_2000_patch_mean_matrix.mat b/15_2000_patch_mean_matrix.mat new file mode 100644 index 0000000..92785b9 Binary files /dev/null and b/15_2000_patch_mean_matrix.mat differ diff --git a/1_2000_kmeans.model b/1_2000_kmeans.model new file mode 100644 index 0000000..925c3e6 Binary files /dev/null and b/1_2000_kmeans.model differ diff --git a/1_2000_patch_PCA_matrix.mat b/1_2000_patch_PCA_matrix.mat new file mode 100644 index 0000000..40ccd37 Binary files /dev/null and b/1_2000_patch_PCA_matrix.mat differ diff --git a/1_2000_patch_mean_matrix.mat b/1_2000_patch_mean_matrix.mat new file mode 100644 index 0000000..f64d817 Binary files /dev/null and b/1_2000_patch_mean_matrix.mat differ diff --git a/2000_kmeans.model b/2000_kmeans.model new file mode 100644 index 0000000..dc04817 Binary files /dev/null and b/2000_kmeans.model differ diff --git a/2000_patch_PCA_matrix.mat b/2000_patch_PCA_matrix.mat new file mode 100644 index 0000000..58261c1 Binary files /dev/null and b/2000_patch_PCA_matrix.mat differ diff --git a/2000_patch_mean_matrix.mat b/2000_patch_mean_matrix.mat new file mode 100644 index 0000000..b4b2bbf Binary files /dev/null and b/2000_patch_mean_matrix.mat differ diff --git a/2_2000_kmeans.model b/2_2000_kmeans.model new file mode 100644 index 0000000..5d97f5f Binary files /dev/null and b/2_2000_kmeans.model differ diff --git a/2_2000_patch_PCA_matrix.mat b/2_2000_patch_PCA_matrix.mat new file mode 100644 index 0000000..a60a184 Binary files /dev/null and b/2_2000_patch_PCA_matrix.mat differ diff --git a/2_2000_patch_mean_matrix.mat b/2_2000_patch_mean_matrix.mat new file mode 100644 index 0000000..c1e03cf Binary files /dev/null and b/2_2000_patch_mean_matrix.mat differ diff --git a/3_2000_kmeans.model b/3_2000_kmeans.model new file mode 100644 index 0000000..e2c2576 Binary files /dev/null and b/3_2000_kmeans.model differ diff --git a/3_2000_patch_PCA_matrix.mat b/3_2000_patch_PCA_matrix.mat new file mode 100644 index 0000000..79ffce6 Binary files /dev/null and b/3_2000_patch_PCA_matrix.mat differ diff --git a/3_2000_patch_mean_matrix.mat b/3_2000_patch_mean_matrix.mat new file mode 100644 index 0000000..6ec7989 Binary files /dev/null and b/3_2000_patch_mean_matrix.mat differ diff --git a/Comparison_Result.pdf b/Comparison_Result.pdf new file mode 100644 index 0000000..73f861e Binary files /dev/null and b/Comparison_Result.pdf differ diff --git a/Comparison_result.png b/Comparison_result.png new file mode 100644 index 0000000..53bed73 Binary files /dev/null and b/Comparison_result.png differ diff --git a/Filters/8x_Qfactor_coh2 b/Filters/8x_Qfactor_coh2 new file mode 100644 index 0000000..70f67b8 Binary files /dev/null and b/Filters/8x_Qfactor_coh2 differ diff --git a/Filters/8x_Qfactor_coh3 b/Filters/8x_Qfactor_coh3 new file mode 100644 index 0000000..1695fc5 Binary files /dev/null and b/Filters/8x_Qfactor_coh3 differ diff --git a/Filters/8x_Qfactor_str2 b/Filters/8x_Qfactor_str2 new file mode 100644 index 0000000..78f64dd Binary files /dev/null and b/Filters/8x_Qfactor_str2 differ diff --git a/Filters/8x_Qfactor_str3 b/Filters/8x_Qfactor_str3 new file mode 100644 index 0000000..5966b2b Binary files /dev/null and b/Filters/8x_Qfactor_str3 differ diff --git a/Filters/8x_filter2 b/Filters/8x_filter2 new file mode 100644 index 0000000..4c055b0 Binary files /dev/null and b/Filters/8x_filter2 differ diff --git a/Filters/8x_filter3 b/Filters/8x_filter3 new file mode 100644 index 0000000..183f67c Binary files /dev/null and b/Filters/8x_filter3 differ diff --git a/Filters/Ckmeans_Qfactor_coh2 b/Filters/Ckmeans_Qfactor_coh2 new file mode 100644 index 0000000..70f67b8 Binary files /dev/null and b/Filters/Ckmeans_Qfactor_coh2 differ diff --git a/Filters/Ckmeans_Qfactor_coh3 b/Filters/Ckmeans_Qfactor_coh3 new file mode 100644 index 0000000..1695fc5 Binary files /dev/null and b/Filters/Ckmeans_Qfactor_coh3 differ diff --git a/Filters/Ckmeans_Qfactor_str2 b/Filters/Ckmeans_Qfactor_str2 new file mode 100644 index 0000000..78f64dd Binary files /dev/null and b/Filters/Ckmeans_Qfactor_str2 differ diff --git a/Filters/Ckmeans_Qfactor_str3 b/Filters/Ckmeans_Qfactor_str3 new file mode 100644 index 0000000..5966b2b Binary files /dev/null and b/Filters/Ckmeans_Qfactor_str3 differ diff --git a/Filters/Ckmeans_filter2 b/Filters/Ckmeans_filter2 new file mode 100644 index 0000000..72cb6c7 Binary files /dev/null and b/Filters/Ckmeans_filter2 differ diff --git a/Filters/Ckmeans_filter3 b/Filters/Ckmeans_filter3 new file mode 100644 index 0000000..e8adc63 Binary files /dev/null and b/Filters/Ckmeans_filter3 differ diff --git a/Filters/Qfactor_coh2 b/Filters/Qfactor_coh2 new file mode 100755 index 0000000..4ca7df2 Binary files /dev/null and b/Filters/Qfactor_coh2 differ diff --git a/Filters/Qfactor_coh3 b/Filters/Qfactor_coh3 new file mode 100755 index 0000000..95deaeb Binary files /dev/null and b/Filters/Qfactor_coh3 differ diff --git a/Filters/Qfactor_coh4 b/Filters/Qfactor_coh4 new file mode 100755 index 0000000..f95fe13 Binary files /dev/null and b/Filters/Qfactor_coh4 differ diff --git a/Filters/Qfactor_str2 b/Filters/Qfactor_str2 new file mode 100755 index 0000000..f4fa893 Binary files /dev/null and b/Filters/Qfactor_str2 differ diff --git a/Filters/Qfactor_str3 b/Filters/Qfactor_str3 new file mode 100755 index 0000000..d1666de Binary files /dev/null and b/Filters/Qfactor_str3 differ diff --git a/Filters/Qfactor_str4 b/Filters/Qfactor_str4 new file mode 100755 index 0000000..613d29d Binary files /dev/null and b/Filters/Qfactor_str4 differ diff --git a/Filters/filter2 b/Filters/filter2 new file mode 100755 index 0000000..954ad10 Binary files /dev/null and b/Filters/filter2 differ diff --git a/Filters/filter3 b/Filters/filter3 new file mode 100755 index 0000000..ae0155c Binary files /dev/null and b/Filters/filter3 differ diff --git a/Filters/filter4 b/Filters/filter4 new file mode 100755 index 0000000..e137a10 Binary files /dev/null and b/Filters/filter4 differ diff --git a/Filters/kmeans_Qfactor_coh2 b/Filters/kmeans_Qfactor_coh2 new file mode 100644 index 0000000..70f67b8 Binary files /dev/null and b/Filters/kmeans_Qfactor_coh2 differ diff --git a/Filters/kmeans_Qfactor_str2 b/Filters/kmeans_Qfactor_str2 new file mode 100644 index 0000000..78f64dd Binary files /dev/null and b/Filters/kmeans_Qfactor_str2 differ diff --git a/Filters/kmeans_filter2 b/Filters/kmeans_filter2 new file mode 100644 index 0000000..38fbf88 Binary files /dev/null and b/Filters/kmeans_filter2 differ diff --git a/Filters/no8x_Qfactor_coh2 b/Filters/no8x_Qfactor_coh2 new file mode 100644 index 0000000..70f67b8 Binary files /dev/null and b/Filters/no8x_Qfactor_coh2 differ diff --git a/Filters/no8x_Qfactor_coh3 b/Filters/no8x_Qfactor_coh3 new file mode 100644 index 0000000..1695fc5 Binary files /dev/null and b/Filters/no8x_Qfactor_coh3 differ diff --git a/Filters/no8x_Qfactor_str2 b/Filters/no8x_Qfactor_str2 new file mode 100644 index 0000000..78f64dd Binary files /dev/null and b/Filters/no8x_Qfactor_str2 differ diff --git a/Filters/no8x_Qfactor_str3 b/Filters/no8x_Qfactor_str3 new file mode 100644 index 0000000..5966b2b Binary files /dev/null and b/Filters/no8x_Qfactor_str3 differ diff --git a/Filters/no8x_filter2 b/Filters/no8x_filter2 new file mode 100644 index 0000000..a9d44ca Binary files /dev/null and b/Filters/no8x_filter2 differ diff --git a/Filters/no8x_filter3 b/Filters/no8x_filter3 new file mode 100644 index 0000000..183f67c Binary files /dev/null and b/Filters/no8x_filter3 differ diff --git a/Functions.py b/Functions.py new file mode 100644 index 0000000..6bd1ba0 --- /dev/null +++ b/Functions.py @@ -0,0 +1,425 @@ +import cv2 +from scipy.misc import imresize +from scipy.signal import convolve2d +import scipy.io as io +import numpy as np +from sklearn.cluster import KMeans +from sklearn.externals import joblib +from math import atan2, floor, pi, ceil, isnan +import numba as nb +import os + +IMG_EXTENSIONS = ['.jpg', '.JPG', '.jpeg', '.JPEG', + '.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',] + +kmeans = joblib.load('x3_1_3000_kmeans.model') +pca_matrix = io.loadmat('x3_1_3000_patch_PCA_matrix.mat')['p'] +mean = io.loadmat('x3_1_3000_patch_mean_matrix.mat')['m'] + +def is_image_file(filename): + return any(filename.endswith(extension) for extension in IMG_EXTENSIONS) + +def make_dataset(dir): + images = [] + assert os.path.isdir(dir), '%s is not a valid directory' % dir + for root, _, fnames in sorted(os.walk(dir)): + for fname in fnames: + if is_image_file(fname): + path = os.path.join(root, fname) + images.append(path) + return images + +# Python opencv library (cv2) cv2.COLOR_BGR2YCrCb has different parameters with MATLAB color convertion. +# In order to have a fair comparison with the benchmark, we wrote these functions by ourselves. +def BGR2YCbCr(im): + mat = np.array([[24.966, 128.553, 65.481],[112, -74.203, -37.797], [-18.214, -93.786, 112]]) + mat = mat.T + offset = np.array([[[16, 128, 128]]]) + if im.dtype == 'uint8': + mat = mat/255 + out = np.dot(im,mat) + offset + out = np.clip(out, 0, 255) + out = np.rint(out).astype('uint8') + elif im.dtype == 'float': + mat = mat/255 + offset = offset/255 + out = np.dot(im, mat) + offset + out = np.clip(out, 0, 1) + else: + assert False + return out + +def YCbCr2BGR(im): + mat = np.array([[24.966, 128.553, 65.481],[112, -74.203, -37.797], [-18.214, -93.786, 112]]) + mat = mat.T + mat = np.linalg.inv(mat) + offset = np.array([[[16, 128, 128]]]) + if im.dtype == 'uint8': + mat = mat * 255 + out = np.dot((im - offset),mat) + out = np.clip(out, 0, 255) + out = np.rint(out).astype('uint8') + elif im.dtype == 'float': + mat = mat * 255 + offset = offset/255 + out = np.dot((im - offset),mat) + out = np.clip(out, 0, 1) + else: + assert False + return out + +def im2double(im): + if im.dtype == 'uint8': + out = im.astype('float') / 255 + elif im.dtype == 'uint16': + out = im.astype('float') / 65535 + elif im.dtype == 'float': + out = im + else: + assert False + out = np.clip(out, 0, 1) + return out + +def Gaussian2d(shape=(3,3),sigma=0.5): + """ + 2D gaussian mask - should give the same result as MATLAB's + fspecial('gaussian',[shape],[sigma]) + from https://stackoverflow.com/questions/17190649/how-to-obtain-a-gaussian-filter-in-python + + """ + m,n = [(ss-1.)/2. for ss in shape] + y,x = np.ogrid[-m:m+1,-n:n+1] + h = np.exp( -(x*x + y*y) / (2.*sigma*sigma) ) + h[ h < np.finfo(h.dtype).eps*h.max() ] = 0 + sumh = h.sum() + if sumh != 0: + h /= sumh + return h + +def modcrop(im,modulo): + shape = im.shape + size0 = shape[0] - shape[0] % modulo + size1 = shape[1] - shape[1] % modulo + if len(im.shape) == 2: + out = im[0:size0, 0:size1] + else: + out = im[0:size0, 0:size1, :] + return out + +def Prepare(im, patchSize, R): + patchMargin = floor(patchSize/2) + H, W = im.shape + imL = imresize(im, 1 / R, interp='bicubic') + # cv2.imwrite('Compressed.jpg', imL, [int(cv2.IMWRITE_JPEG_QUALITY), 85]) + # imL = cv2.imread('Compressed.jpg') + # imL = imL[:,:,0] # Optional: Compress the image + imL = imresize(imL, (H, W), interp='bicubic') + imL = im2double(imL) + im_LR = imL + return im_LR + +def is_greyimage(im): + x = abs(im[:,:,0]-im[:,:,1]) + y = np.linalg.norm(x) + if y==0: + return True + else: + return False + +@nb.jit(nopython=True, parallel=True) +def Grad(patchX,patchY,weight): + gx = patchX.ravel() + gy = patchY.ravel() + G = np.vstack((gx,gy)).T + x0 = np.dot(G.T,weight) + x = np.dot(x0, G) + w,v = np.linalg.eig(x) + index= w.argsort()[::-1] + w = w[index] + v = v[:,index] + lamda = w[0] + u = (np.sqrt(w[0]) - np.sqrt(w[1]))/(np.sqrt(w[0]) + np.sqrt(w[1]) + 0.00000000000000001) + return lamda,u + +@nb.jit(nopython=True, parallel=True) +def HashTable(patchX,patchY,weight, Qangle,Qstrength,Qcoherence,stre,cohe): + assert (len(stre)== Qstrength-1) and (len(cohe)==Qcoherence-1),"Quantization number should be equal" + gx = patchX.ravel() + gy = patchY.ravel() + G = np.vstack((gx,gy)).T + x0 = np.dot(G.T,weight) + x = np.dot(x0, G) + w,v = np.linalg.eig(x) + index= w.argsort()[::-1] + w = w[index] + v = v[:,index] + theta = atan2(v[1,0], v[0,0]) + if theta<0: + theta = theta+pi + theta = floor(theta/(pi/Qangle)) + lamda = w[0] + u = (np.sqrt(w[0]) - np.sqrt(w[1]))/(np.sqrt(w[0]) + np.sqrt(w[1]) + 0.00000000000000001) + if isnan(u): + u=1 + if theta>Qangle-1: + theta = Qangle-1 + if theta<0: + theta = 0 + lamda = np.searchsorted(stre,lamda) + u = np.searchsorted(cohe,u) + return theta,lamda,u + +@nb.jit(nopython=True, parallel=True) +def Gaussian_Mul(x,y,wGaussian): + result = np.zeros((x.shape[0], x.shape[1], y.shape[2])) + for i in range(x.shape[0]): + # inter = np.matmul(x[i], wGaussian) + # result[i] = np.matmul(inter,y[i]) + inter = np.dot(x[i], wGaussian) + result[i] = np.dot(inter, y[i]) + return result + +def CT_descriptor(im): + H, W = im.shape + windowSize = 3 + Census = np.zeros((H, W)) + CT = np.zeros((H, W, windowSize, windowSize)) + C = np.int((windowSize-1)/2) + for i in range(C,H-C): + for j in range(C, W-C): + cen = 0 + for a in range(-C, C+1): + for b in range(-C, C+1): + if not (a==0 and b==0): + if im[i+a, j+b] < im[i, j]: + cen += 1 + CT[i, j, a+C,b+C] = 1 + Census[i, j] = cen + Census = Census/8 + return Census, CT + +def Blending1(LR, HR): + H,W = LR.shape + H1,W1 = HR.shape + assert H1==H and W1==W + Census,CT = CT_descriptor(LR) + blending1 = Census*HR + (1 - Census)*LR + return blending1 + +def Blending2(LR, HR): + H,W = LR.shape + H1,W1 = HR.shape + assert H1==H and W1==W + Census1, CT1 = CT_descriptor(LR) + Census2, CT2 = CT_descriptor(HR) + weight = np.zeros((H, W)) + x = np.zeros(( 3, 3)) + for i in range(H): + for j in range(W): + x = np.absolute(CT1[i,j]-CT2[i,j]) + weight[i, j] = x.sum() + weight = weight/weight.max() + blending2 = weight * LR + (1 - weight) * HR + return blending2 + +def Backprojection(LR, HR, maxIter): + H, W = LR.shape + H1, W1 = HR.shape + w = Gaussian2d((5,5), 10) + w = w**2 + w = w/sum(np.ravel(w)) + for i in range(maxIter): + im_L = imresize(HR, (H, W), interp='bicubic', mode='F') + imd = LR - im_L + im_d = imresize(imd, (H1, W1), interp='bicubic', mode='F') + HR = HR + convolve2d(im_d, w, 'same') + return HR + +def createFolder(directory): + try: + if not os.path.exists(directory): + os.makedirs(directory) + except OSError: + print ('Error: Creating directory. ' + directory) + +def Dog1(im): + sigma = 0.85 + alpha = 1.414 + r = 15 + ksize = (3, 3) + G1 = cv2.GaussianBlur(im, ksize, sigma) + Ga1 = cv2.GaussianBlur(im, ksize, sigma*alpha) + D1 = cv2.addWeighted(G1, 1+r, Ga1, -r, 0) + + G2 = cv2.GaussianBlur(Ga1, ksize, sigma) + Ga2 = cv2.GaussianBlur(Ga1, ksize, sigma*alpha) + D2 = cv2.addWeighted(G2, 1+r, Ga2, -r, 0) + + G3 = cv2.GaussianBlur(Ga2, ksize, sigma) + Ga3 = cv2.GaussianBlur(Ga2, ksize, sigma * alpha) + D3 = cv2.addWeighted(G3, 1+r, Ga3, -r, 0) + + B1 = Blending1(im, D3) + B1 = Blending1(im, B1) + B2 = Blending1(B1, D2) + B2 = Blending1(im, B2) + B3 = Blending1(B2, D1) + B3 = Blending1(im, B3) + + output = B3 + + return output + +def Getfromsymmetry1(V, patchSize, t1, t2): + V_sym = np.zeros((patchSize*patchSize,patchSize*patchSize)) + for i in range(1, patchSize*patchSize+1): + for j in range(1, patchSize*patchSize+1): + y1 = ceil(i/patchSize) + x1 = i-(y1-1)*patchSize + y2 = ceil(j/patchSize) + x2 = j-(y2-1)*patchSize + if (t1 == 1) and (t2 == 0): + ig = patchSize * x1 + 1 - y1 + jg = patchSize * x2 + 1 - y2 + V_sym[ig - 1, jg - 1] = V[i - 1, j - 1] + elif (t1 == 2) and (t2 == 0): + x = patchSize + 1 - x1 + y = patchSize + 1 - y1 + ig = (y - 1) * patchSize + x + x = patchSize + 1 - x2 + y = patchSize + 1 - y2 + jg = (y - 1) * patchSize + x + V_sym[ig - 1, jg - 1] = V[i - 1, j - 1] + elif (t1 == 3) and (t2 == 0): + x = y1 + y = patchSize + 1 - x1 + ig =(y - 1) * patchSize + x + x = y2 + y = patchSize + 1 - x2 + jg = (y - 1) * patchSize + x + V_sym[ig - 1, jg - 1] = V[i - 1, j - 1] + elif (t1 == 0) and (t2 == 1): + x = patchSize + 1 - x1 + y = y1 + ig =(y - 1) * patchSize + x + x = patchSize + 1 - x2 + y = y2 + jg = (y - 1) * patchSize + x + V_sym[ig - 1, jg - 1] = V[i - 1, j - 1] + elif (t1 == 1) and (t2 == 1): + x0 = patchSize + 1 - x1 + y0 = y1 + x = patchSize + 1 - y0 + y = x0 + ig =(y - 1) * patchSize + x + x0 = patchSize + 1 - x2 + y0 = y2 + x = patchSize + 1 - y0 + y = x0 + jg = (y - 1) * patchSize + x + V_sym[ig - 1, jg - 1] = V[i - 1, j - 1] + elif (t1 == 2) and (t2 == 1): + x0 = patchSize + 1 - x1 + y0 = y1 + x = patchSize + 1 - x0 + y = patchSize + 1 - y0 + ig =(y - 1) * patchSize + x + x0 = patchSize + 1 - x2 + y0 = y2 + x = patchSize + 1 - x0 + y = patchSize + 1 - y0 + jg = (y - 1) * patchSize + x + V_sym[ig - 1, jg - 1] = V[i - 1, j - 1] + elif (t1 == 3) and (t2 == 1): + x0 = patchSize + 1 - x1 + y0 = y1 + x = y0 + y = patchSize + 1 - x0 + ig =(y - 1) * patchSize + x + x0 = patchSize + 1 - x2 + y0 = y2 + x = y0 + y = patchSize + 1 - x0 + jg = (y - 1) * patchSize + x + V_sym[ig - 1, jg - 1] = V[i - 1, j - 1] + else: + assert False + return V_sym + +def Getfromsymmetry2(V, patchSize, t1, t2): + Vp = np.reshape(V, (patchSize, patchSize)) + V1 = np.rot90(Vp, t1) + if t2 == 1: + V1 = np.flip(V1, 1) + V_sym = np.ravel(V1) + return V_sym + +# Quantization procedure to get the optimized strength and coherence boundaries +#@nb.jit(nopython=True, parallel=True) +def QuantizationProcess (im_GX, im_GY,patchSize, patchNumber,w , quantization): + H, W = im_GX.shape + for i1 in range(H-2*floor(patchSize/2)): + for j1 in range(W-2*floor(patchSize/2)): + idx = (slice(i1,(i1+2*floor(patchSize/2)+1)),slice(j1,(j1+2*floor(patchSize/2)+1))) + patchX = im_GX[idx] + patchY = im_GY[idx] + strength, coherence = Grad(patchX, patchY, w) + quantization[patchNumber, 0] = strength + quantization[patchNumber, 1] = coherence + patchNumber += 1 + return quantization, patchNumber + +# Training procedure for each image (use numba.jit to speed up) +@nb.jit(nopython=True, parallel=True) +def TrainProcess (im_LR, im_HR, im_GX, im_GY,patchSize, w, Qangle, Qstrength,Qcoherence, stre, cohe, R, Q, V, mark): + H, W = im_HR.shape + for i1 in range(H-2*floor(patchSize/2)): + for j1 in range(W-2*floor(patchSize/2)): + idx1 = (slice(i1,(i1+2*floor(patchSize/2)+1)),slice(j1,(j1+2*floor(patchSize/2)+1))) + patch = im_LR[idx1] + patchX = im_GX[idx1] + patchY = im_GY[idx1] + theta,lamda,u=HashTable(patchX, patchY, w, Qangle, Qstrength,Qcoherence, stre, cohe) + patch1 = patch.ravel() + patchL = patch1.reshape((1,patch1.size)) + t = (i1 % R) * R +(j1 % R) + j = theta * Qstrength * Qcoherence + lamda * Qcoherence + u + tx = np.int(t) + jx = np.int(j) + A = np.dot(patchL.T, patchL) + Q[tx,jx] += A + b1=patchL.T * im_HR[i1+floor(patchSize/2),j1+floor(patchSize/2)] + b = b1.reshape((b1.size)) + V[tx,jx] += b + mark[tx,jx] = mark[tx,jx]+1 + return Q,V,mark + + +# Training procedure for each image (use numba.jit to speed up) +#@nb.jit(nopython=True, parallel=True) +def TrainProcessSMC (im_LR, im_HR, im_GX, im_GY,patchSize, w, Qangle, Qstrength,Qcoherence, stre, cohe, R, Q, V, mark): + H, W = im_HR.shape + for i1 in range(H-2*floor(patchSize/2)): + for j1 in range(W-2*floor(patchSize/2)): + idx1 = (slice(i1,(i1+2*floor(patchSize/2)+1)),slice(j1,(j1+2*floor(patchSize/2)+1))) + patch = im_LR[idx1] + patchX = im_GX[idx1] + patchY = im_GY[idx1] + theta,lamda,u=HashTable(patchX, patchY, w, Qangle, Qstrength,Qcoherence, stre, cohe) + patch1 = patch.ravel() + patchSubMean = patch1 - mean.reshape(1, -1) + patch_reduced = np.dot(pca_matrix, patchSubMean.reshape(-1, 1)) + t = kmeans.predict(patch_reduced) + patchL = patch1.reshape((1,patch1.size)) + #t = (i1 % R) * R +(j1 % R) + j = theta * Qstrength * Qcoherence + lamda * Qcoherence + u + tx = np.int(t) + jx = np.int(j) + A = np.dot(patchL.T, patchL) + Q[tx,jx] += A + b1=patchL.T * im_HR[i1+floor(patchSize/2),j1+floor(patchSize/2)] + b = b1.reshape((b1.size)) + V[tx,jx] += b + mark[tx,jx] = mark[tx,jx]+1 + return Q,V,mark + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..69e160e --- /dev/null +++ b/README.md @@ -0,0 +1,86 @@ +# Jalali-Lab Implementation of RAISR Algorithm + +## Contents +1. [Introduction](#introduction) +2. [Dependencies](#dependencies) +3. [Training](#training) +4. [Testing](#testing) +5. [Quantitative Comparison](#quantitative-comparison) +6. [Sample Result](#sample-result) +7. [Citations](#citations) +8. [Acknowledgments](#acknowledgments) +9. [License](#license) + +## Introduction +[RAISR](http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7744595) (Rapid and Accurate Image Super Resolution) is an image processing algorithm published by Google Research in 2016. With sufficient training data, consisting of low and high resolution image pairs, RAISR algorithm tries to learn a set of filters which can be applied to an input image that is not in the training set, to produce a higher resolution version of it. The source code released here is the [Jalali-Lab](http://photonics.ucla.edu/index.html) implementation of the RAISR algorithm written in Python 3.x by [Sifeng He](https://www.linkedin.com/in/sifeng-he-969230134/), under the guidance of [Prof. Bahram Jalali](http://photonics.ucla.edu/bahram_jalali.html). The implementation presented here achieved performance results that are comparable to that presented in Google's research paper (with less than ± 0.1 dB in PSNR). +Just-in-time (JIT) compilation employing JIT numba is used to speed up the Python code. A very parallelized Python code employing multi-processing capabilities is used to speed up the testing process. The code has been tested on **GNU/Linux** and **Mac OS X 10.13.2** platforms. + +## Dependencies +All the dependent Python modules needed for the using our RAISR implementation can be installed using pip package manager and are the following: + +* NumPy +* Numba +* Python Imaging Library (PIL) +* scipy +* os +* pickle +* skimage + +Additionally, a requirements.txt file is provided for installing all the dependencies by running the following command in a shell: +``` +pip install -U -r requirements.txt +``` + +## Training +All the training images are to be stored in the **trainingData** directory, before executing the **Train.py** script. In the training script, modify the upscaling factor, R, appropriately. The training outputs three files, **filter**, **Qfactor_str**, and **Qfactor_coh**, which are needed in the testing phase. The training data used in this implementation is the **BSD 200** ([Martin et al. ICCV 2001](https://www.eecs.berkeley.edu/Research/Projects/CS/vision/bsds/)). A pre-trained filter with upscaling factors x2, x3, and x4 are available for testing in the **Filter** directory. To execute training, simply run the following command in your shell: +``` +python Train.py +``` + +## Testing +All the test images are to be stored in the **testData** directory, before executing the **Test.py** script. In the test script, change the upscaling factor, R, and filters. The result image will be saved in **results** directory. The test data used for the development of the algorithm were **Set 5** ([Bevilacqua et al. BMVC 2012](http://people.rennes.inria.fr/Aline.Roumy/results/SR_BMVC12.html)) and **Set 14** ([Zeyde et al. LNCS 2010](https://sites.google.com/site/romanzeyde/research-interests)). To execute testing, simply run the following command in your shell: +``` +python Test.py +``` + +## Quantitative Comparison +| Upscale Factor | Google RAISR | Our implementation trained
on BSD 200 images | Our implementation trained
on COCO (500 images) | +|:-------------: |:---------------:| :-------------:| :-------------:| +| 2x | 35.913 | 35.855| 35.878 | +| 3x | 32.061 | 31.981| 32.019 | +| 4x | 29.689 | 29.717| 29.801 | +##### Table 1. Comparison of Results on [Set 5](http://people.rennes.inria.fr/Aline.Roumy/results/SR_BMVC12.html) Images +| Upscale Factor | Google RAISR | Our implementation trained
on BSD 200 images | Our implementation trained
on COCO (500 images) | +|:-------------: |:---------------:| :-------------:| :-------------:| +| 2x | 31.980 | 31.790| 31.816 | +| 3x | 28.764 | 31.714| 28.729 | +| 4x | 26.912 | 26.901| 26.935 | +##### Table 2. Comparison of Results Results on [Set 14](https://sites.google.com/site/romanzeyde/research-interests) Images + +Google's RAISR implementation was trained on 10000 advertising banner images. Our implementation of RAISR was trained on [BSD 200](https://www.eecs.berkeley.edu/Research/Projects/CS/vision/bsds/) (200 images) and on 500 images from [COCO](http://mscoco.org/) dataset. The training time for our implementation on a 3.4 GHz 6-core Xeon desktop computer is about 20 minutes for BSD 200 dataset and an hour for the 500 images from COCO dataset. The average test time for one single image in test dataset ([Set 5](http://people.rennes.inria.fr/Aline.Roumy/results/SR_BMVC12.html) and [Set 14](https://sites.google.com/site/romanzeyde/research-interests)) is less than 1 second. + +## Sample Result +

+ +

+A high resolution image after downscaling it by 2 was used as the input low resolution image to both bicubic interpolation and our implementation of RAISR algorithm. A comparison of the resulted output image for this testcase with bicubic interpolation and our implementation of RAISR is shown in the figure above. + +## Citations +Please cite the following publications if you plan to use the code or the results for your research: +1. Sifeng He, Bahram Jalali. "Brain MRI Image Super Resolution using Phase Stretch Transform and Transfer Learning", *arXiv preprint arXiv:1807.11643*, (2018). [URL](https://arxiv.org/abs/1807.11643) + +Bibtex: +``` +@article{he2018brain, + title={Brain MRI Image Super Resolution using Phase Stretch Transform and Transfer Learning}, + author={He, Sifeng and Jalali, Bahram}, + journal={arXiv preprint arXiv:1807.11643}, + year={2018} +} +``` + +## Acknowledgments +Special thanks to [Dr. Cejo Konuparamban Lonappan](https://www.linkedin.com/in/cejokl/) for his support and guidance. + +## License +The code is released under GNU General Public License 3.0. Please refer to the LICENSE file for details. diff --git a/Test.py b/Test.py new file mode 100644 index 0000000..c597e4a --- /dev/null +++ b/Test.py @@ -0,0 +1,210 @@ +#!/usr/bin/env python3 + +""" +Implementation of RAISR in Python by Jalali-Lab + +[RAISR](http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7744595) (Rapid and Accurate Image Super +Resolution) is an image processing algorithm published by Google Research in 2016. With sufficient +trainingData, consisting of low and high resolution image pairs, RAISR algorithm tries to learn +a set of filters which can be applied to an input image that is not in the training set, +to produce a higher resolution version of it. The source code released here is the Jalali-Lab +implementation of the RAISR algorithm in Python 3.x. The implementation presented here achieved +performance results that are comparable to that presented in Google's research paper +(with ± 0.1 dB in PSNR). + +Just-in-time (JIT) compilation employing JIT numba is used to speed up the Python code. A very +parallelized Python code employing multi-processing capabilities is used to speed up the testing +process. The code has been tested on GNU/Linux and Mac OS X 10.13.2 platforms. + +Author: Sifeng He, Jalali-Lab, Department of Electrical and Computer Engineering, UCLA + +Copyright +--------- +RAISR is developed in Jalali Lab at University of California, Los Angeles (UCLA). +More information about the technique can be found in our group website: http://www.photonics.ucla.edu + + +""" + +import numpy as np +import numba as nb +import os +import cv2 +import warnings +import pickle +import time +from math import floor +from skimage.measure import compare_psnr +from scipy.misc import imresize +from Functions import * +import matplotlib.image as mpimg +from multiprocessing import Pool + +warnings.filterwarnings('ignore') + +testPath = 'set 14' + +R = 2 # Upscaling factor=2 R = [ 2 3 4 ] +patchSize = 11 # Pacth Size=11 +gradientSize = 9 +Qangle = 24 # Quantization factor of angle =24 +Qstrength = 3 # Quantization factor of strength =3 +Qcoherence = 3 # Quantization factor of coherence =3 + +with open("Filters/8x_filter"+str(R), "rb") as fp: + h = pickle.load(fp) + +with open("Filters/8x_Qfactor_str"+str(R), "rb") as sp: + stre = pickle.load(sp) + +with open("Filters/8x_Qfactor_coh"+str(R), "rb") as cp: + cohe = pickle.load(cp) + +filelist = make_dataset(testPath) + +wGaussian = Gaussian2d([patchSize, patchSize], 2) +wGaussian = wGaussian/wGaussian.max() +wGaussian = np.diag(wGaussian.ravel()) +imagecount = 1 +patchMargin = floor(patchSize/2) +psnrRAISR = [] +psnrBicubic = [] +psnrBlending = [] + +def TestProcess(i): + if (i < iteration - 1): + offset_i = offset[i * batch:i * batch + batch] + offset2_i = offset2[i * batch:i * batch + batch] + grid = np.tile(gridon[..., None], [1, 1, batch]) + np.tile(offset_i, [patchSize, patchSize, 1]) + else: + offset_i = offset[i * batch:im.size] + offset2_i = offset2[i * batch:im.size] + grid = np.tile(gridon[..., None], [1, 1, im.size - (iteration - 1) * batch]) + np.tile(offset_i,[patchSize, patchSize,1]) + f = im_LR.ravel()[grid] + gx = im_GX.ravel()[grid] + gy = im_GY.ravel()[grid] + gx = gx.reshape((1, patchSize * patchSize, gx.shape[2])) + gy = gy.reshape((1, patchSize * patchSize, gy.shape[2])) + G = np.vstack((gx, gy)) + g1 = np.transpose(G, (2, 0, 1)) + g2 = np.transpose(G, (2, 1, 0)) + x = Gaussian_Mul(g1, g2, wGaussian) + w, v = np.linalg.eig(x) + idx = (-w).argsort() + w = w[np.arange(np.shape(w)[0])[:, np.newaxis], idx] + v = v[np.arange(np.shape(v)[0])[:, np.newaxis, np.newaxis], np.arange(np.shape(v)[1])[np.newaxis, :, np.newaxis], idx[:,np.newaxis,:]] + thelta = np.arctan(v[:, 1, 0] / v[:, 0, 0]) + thelta[thelta < 0] = thelta[thelta < 0] + pi + thelta = np.floor(thelta / (pi / Qangle)) + thelta[thelta > Qangle - 1] = Qangle - 1 + thelta[thelta < 0] = 0 + lamda = w[:, 0] + u = (np.sqrt(w[:, 0]) - np.sqrt(w[:, 1])) / (np.sqrt(w[:, 0]) + np.sqrt(w[:, 1]) + 0.00000000000000001) + lamda = np.searchsorted(stre, lamda) + u = np.searchsorted(cohe, u) + j = thelta * Qstrength * Qcoherence + lamda * Qcoherence + u + j = j.astype('int') + offset2_i = np.unravel_index(offset2_i, (H, W)) + t = ((offset2_i[0] - patchMargin) % R) * R + ((offset2_i[1] - patchMargin) % R) + filtertj = h[t, j] + filtertj = filtertj[:, :, np.newaxis] + patch = f.reshape((1, patchSize * patchSize, gx.shape[2])) + patch = np.transpose(patch, (2, 0, 1)) + result = np.matmul(patch, filtertj) + return result + + +print('Begin to process images:') +for image in filelist: + print('\r', end='') + print('' * 60, end='') + print('\r Processing ' + str(imagecount) + '/' + str(len(filelist)) + ' image (' + image + ')') + im_uint8 = cv2.imread(image) + im_mp = mpimg.imread(image) + if len(im_mp.shape) == 2: + im_uint8 = im_uint8[:,:,0] + im_uint8 = modcrop(im_uint8, R) + if len(im_uint8.shape) > 2: + im_ycbcr = BGR2YCbCr(im_uint8) + im = im_ycbcr[:, :, 0] + else: + im = im_uint8 + im_double = im2double(im) + H, W = im.shape + region = (slice(patchMargin, H - patchMargin), slice(patchMargin, W - patchMargin)) + start = time.time() + imL = imresize(im_double, 1 / R, interp='bicubic', mode='F') + im_bicubic = imresize(imL, (H, W), interp='bicubic', mode='F') + im_bicubic = im_bicubic.astype('float64') + im_bicubic = np.clip(im_bicubic, 0, 1) + im_LR = np.zeros((H+patchSize-1,W+patchSize-1)) + im_LR[(patchMargin):(H+patchMargin),(patchMargin):(W+patchMargin)] = im_bicubic + im_result = np.zeros((H, W)) + im_GX, im_GY = np.gradient(im_LR) + index = np.array(range(im_LR.size)).reshape(im_LR.shape) + offset = np.array(index[0:H, 0:W].ravel()) + offset2 = np.array(range(im.size)) + gridon = index[0:patchSize, 0:patchSize] + batch = 2000 + iteration = ceil(im.size / batch + 0.000000000000001) + + im_result = np.array([]) + + i = range(iteration) + p = Pool() + im_in = p.map(TestProcess, i) + + for i in range(iteration): + im_result = np.append(im_result, im_in[i]) + + im_result = im_result.reshape(H, W) + im_result = np.clip(im_result, 0, 1) + + end = time.time() + print(end - start) + + im_blending = Blending2(im_bicubic, im_result) + # im_blending = Backprojection(imL, im_blending, 50) #Optional: Backprojection, which can slightly improve PSNR, especilly for large upscaling factor. + im_blending = np.clip(im_blending, 0, 1) + + if len(im_uint8.shape) > 2: + result_ycbcr = np.zeros((H, W, 3)) + result_ycbcr[:, :, 0] = im_blending * 255 + result_ycbcr[:, :, 1] = Prepare(im_ycbcr[:, :, 1], patchSize, R) * 255 + result_ycbcr[:, :, 2] = Prepare(im_ycbcr[:, :, 2], patchSize, R) * 255 + result_ycbcr = result_ycbcr[region].astype('uint8') + result_RAISR = YCbCr2BGR(result_ycbcr) + else: + result_RAISR = im_result[region] * 255 + result_RAISR = result_RAISR.astype('uint8') + + im_result = im_result*255 + im_result = np.rint(im_result).astype('uint8') + im_bicubic = im_bicubic*255 + im_bicubic = np.rint(im_bicubic).astype('uint8') + im_blending = im_blending * 255 + im_blending = np.rint(im_blending).astype('uint8') + + PSNR_bicubic = compare_psnr(im[region], im_bicubic[region]) + PSNR_result = compare_psnr(im[region], im_result[region]) + PSNR_blending = compare_psnr(im[region], im_blending[region]) + PSNR_blending = max(PSNR_result, PSNR_blending) + + createFolder('./results/') + cv2.imwrite('results/' + os.path.splitext(os.path.basename(image))[0] + '_result.bmp', result_RAISR) + psnrRAISR.append(PSNR_result) + psnrBicubic.append(PSNR_bicubic) + psnrBlending.append(PSNR_blending) + + imagecount += 1 + + +RAISR_psnrmean = np.array(psnrBlending).mean() +Bicubic_psnrmean = np.array(psnrBicubic).mean() + + +print('\r', end='') +print('' * 60, end='') +print('\r RAISR PSNR of '+ testPath +' is ' + str(RAISR_psnrmean)) +print('\r Bicubic PSNR of '+ testPath +' is ' + str(Bicubic_psnrmean)) + diff --git a/Train.py b/Train.py new file mode 100644 index 0000000..cef570e --- /dev/null +++ b/Train.py @@ -0,0 +1,176 @@ +#!/usr/bin/env python3 + +""" +Implementation of RAISR in Python by Jalali-Lab + +[RAISR](http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7744595) (Rapid and Accurate Image Super +Resolution) is an image processing algorithm published by Google Research in 2016. With sufficient +trainingData, consisting of low and high resolution image pairs, RAISR algorithm tries to learn +a set of filters which can be applied to an input image that is not in the training set, +to produce a higher resolution version of it. The source code released here is the Jalali-Lab +implementation of the RAISR algorithm in Python 3.x. The implementation presented here achieved +performance results that are comparable to that presented in Google's research paper +(with ± 0.1 dB in PSNR). + +Just-in-time (JIT) compilation employing JIT numba is used to speed up the Python code. A very +parallelized Python code employing multi-processing capabilities is used to speed up the testing +process. The code has been tested on GNU/Linux and Mac OS X 10.13.2 platforms. + +Author: Sifeng He, Jalali-Lab, Department of Electrical and Computer Engineering, UCLA + +Dependencies +All the dependent Python modules needed for the using our RAISR implementation can be installed +using pip package manager and are the following: + +* NumPy +* Numba +* Python Imaging Library (PIL) +* scipy +* os +* pickle +* skimage + +Training +All the training images are to be stored in the **trainingData** directory, before executing the +Train.py script. In the training script, modify the upscaling factor, R, appropriately. The training +outputs three files, **filter.txt**, **Qfactor_str.txt**, and **Qfactor_coh.txt**, which are needed in +the testing phase. The trainingData used in this implementation is the **BSD 200** ([Martin et al. ICCV 2001](https://www.eecs.berkeley.edu/Research/Projects/CS/vision/bsds/)). A pre-trained filter with upscaling factors x2, x3, and x4 are available for testing in the **Filter** directory. + +Copyright +--------- +RAISR is developed in Jalali Lab at University of California, Los Angeles (UCLA). +More information about the technique can be found in our group website: http://www.photonics.ucla.edu + +""" + +import numpy as np +import numba as nb +import os +import cv2 +import pickle +import time +from math import floor +from Functions import * + +trainPath = 'trainingData' + +R = 2 # Upscaling factor=2 +patchSize = 11 # Pacth Size=11 +gradientSize = 9 # Gradient Size = 9 +Qangle = 24 # Quantization factor of angle =24 +Qstrength = 3 # Quantization factor of strength =3 +Qcoherence = 3 # Quantization factor of coherence =3 +stre = np.zeros((Qstrength-1)) # Strength boundary +cohe = np.zeros((Qcoherence-1)) # Coherence boundary + +Q = np.zeros((R*R, Qangle*Qstrength*Qcoherence, patchSize*patchSize, patchSize*patchSize)) # Eq.4 +V = np.zeros((R*R, Qangle*Qstrength*Qcoherence, patchSize*patchSize)) # Eq.5 +h = np.zeros((R*R, Qangle*Qstrength*Qcoherence, patchSize*patchSize)) +mark = np.zeros((R*R, Qangle*Qstrength*Qcoherence)) # statical distribution of patch numbers in each bucket +w = Gaussian2d([patchSize, patchSize], 2) +w = w/w.max() +w = np.diag(w.ravel()) # Diagnal weighting matrix Wk in Algorithm 1 + +filelist = make_dataset(trainPath) + +instance = 20000000 # use 20000000 patches to get the Strength and coherence boundary +patchNumber = 0 # patch number has been used +quantization = np.zeros((instance,2)) # quantization boundary +for image in filelist: + print('\r', end='') + print('' * 60, end='') + print('\r Quantization: Processing '+ str(instance/2) + ' patches (' + str(200*patchNumber/instance) + '%)') + im_uint8 = cv2.imread(image) + if is_greyimage(im_uint8): + im_uint8 = im_uint8[:,:,0] + if len(im_uint8.shape)>2: + im_ycbcr = BGR2YCbCr(im_uint8) + im = im_ycbcr[:,:,0] + else: + im = im_uint8 + im = modcrop(im,R) + im_LR = Prepare(im,patchSize,R) # Prepare the cheap-upscaling images (optional: JPEG compression) + im_GX,im_GY = np.gradient(im_LR) # Calculate the gradient images + quantization, patchNumber = QuantizationProcess (im_GX, im_GY,patchSize, patchNumber, w, quantization) # get the strength and coherence of each patch + if (patchNumber > instance/2): + break + +# uniform quantization of patches, get the optimized strength and coherence boundaries +quantization = quantization [0:patchNumber,:] +quantization = np.sort(quantization,axis=0) +for i in range(Qstrength-1): + stre[i] = quantization[floor((i+1)*patchNumber/Qstrength),0] +for i in range(Qcoherence-1): + cohe[i] = quantization[floor((i+1)*patchNumber/Qcoherence),1] + +print('Begin to process images:') +imagecount = 1 +for image in filelist: + print('\r', end='') + print('' * 60, end='') + print('\r Processing ' + str(imagecount) +'/' + str(len(filelist))+ ' image (' + image + ')') + im_uint8 = cv2.imread(image) + if is_greyimage(im_uint8): + im_uint8 = im_uint8[:,:,0] + if len(im_uint8.shape)>2: + im_ycbcr = BGR2YCbCr(im_uint8) + im = im_ycbcr[:,:,0] + else: + im = im_uint8 + im = modcrop(im,R) + im_LR = Prepare(im,patchSize,R) + im_HR = im2double(im) + #im_HR = Dog1(im_HR) # optional: sharpen the image + im_GX,im_GY = np.gradient(im_LR) + Q, V, mark = TrainProcess(im_LR, im_HR, im_GX, im_GY,patchSize, w, Qangle, Qstrength,Qcoherence, stre, cohe, R, Q, V, mark) # get Q, V of each patch + imagecount += 1 + +# optional: Using patch symmetry for nearly 8* more learning examples +# print('\r', end='') +# print(' ' * 60, end='') +# print('\r Using patch symmetry for nearly 8* more learning examples:') +# for i in range(Qangle): +# for j in range(Qstrength*Qcoherence): +# for r in range(R*R): +# for t in range(1,8): +# t1 = t % 4 +# t2 = floor(t / 4) +# Q1 = Getfromsymmetry1(Q[r, i * Qstrength * Qcoherence + j], patchSize, t1, t2) # Rotate 90*t1 degree or flip t2 +# V1 = Getfromsymmetry2(V[r, i * Qstrength * Qcoherence + j], patchSize, t1, t2) +# i1 = Qangle*t1/2 + i +# i1 = np.int(i1) +# if t2 == 1: +# i1 = Qangle -1 - i1 +# while i1 >= Qangle: +# i1 = i1 - Qangle +# while i1 < 0: +# i1 = i1 + Qangle +# Q[r, i1 * Qstrength * Qcoherence + j] += Q1 +# V[r, i1 * Qstrength * Qcoherence + j] += V1 + + +print('Get the filter of RAISR:') +for t in range(R*R): + for j in range(Qangle*Qstrength*Qcoherence): + while(True): + if(Q[t,j].sum()<100): + break + if(np.linalg.det(Q[t,j])<1): + Q[t,j] = Q[t,j] + np.eye(patchSize*patchSize)* Q[t,j].sum()*0.000000005 + else: + h[t,j] = np.linalg.inv(Q[t,j]).dot(V[t,j]) # Eq.2 + break + +with open("no8x_filter"+str(R), "wb") as fp: + pickle.dump(h, fp) + +with open("no8x_Qfactor_str"+str(R), "wb") as sp: + pickle.dump(stre, sp) + +with open("no8x_Qfactor_coh"+str(R), "wb") as cp: + pickle.dump(cohe, cp) + + +print('\r', end='') +print(' ' * 60, end='') +print('\rFinished.') diff --git a/kmeans.ipynb b/kmeans.ipynb new file mode 100644 index 0000000..d3b176f --- /dev/null +++ b/kmeans.ipynb @@ -0,0 +1,556 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/anaconda3/lib/python3.7/site-packages/sklearn/externals/joblib/__init__.py:15: DeprecationWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.\n", + " warnings.warn(msg, category=DeprecationWarning)\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "import cv2\n", + "from math import floor\n", + "from Functions import *\n", + "import matplotlib.image as mpimg\n", + "import time\n", + "from scipy.misc import imresize\n", + "import scipy.io as io\n", + "#from multiprocessing import Pool, Lock\n", + "from sklearn.cluster import KMeans\n", + "from sklearn.externals import joblib\n", + "\n", + "np.set_printoptions(suppress=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "R = 4\n", + "patchSize = 11\n", + "patchMargin = floor(patchSize/2)\n", + "dim_pca = 1\n", + "patchNum = 3000\n", + "\n", + "testPath = 'trainingData'\n", + "pcaSavePath = 'x'+str(R)+'_'+str(dim_pca)+'_'+str(patchNum)+'_patch_PCA_matrix.mat'\n", + "meanSavePath = 'x'+str(R)+'_'+str(dim_pca)+'_'+str(patchNum)+'_patch_mean_matrix.mat'\n", + "kmeansSavePath = 'x'+str(R)+'_'+str(dim_pca)+'_'+str(patchNum)+'_kmeans.model'\n", + "filelist = make_dataset(testPath)\n", + "\n", + "\n", + "sample = None\n", + "kmeans = KMeans(n_clusters=R*R, random_state=None)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Processing 1/200 image (trainingData/157036.jpg)\n", + " Processing 2/200 image (trainingData/187029.jpg)\n", + " Processing 3/200 image (trainingData/71046.jpg)\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:20: DeprecationWarning: `imresize` is deprecated!\n", + "`imresize` is deprecated in SciPy 1.0.0, and will be removed in 1.3.0.\n", + "Use Pillow instead: ``numpy.array(Image.fromarray(arr).resize())``.\n", + "/usr/local/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:21: DeprecationWarning: `imresize` is deprecated!\n", + "`imresize` is deprecated in SciPy 1.0.0, and will be removed in 1.3.0.\n", + "Use Pillow instead: ``numpy.array(Image.fromarray(arr).resize())``.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Processing 4/200 image (trainingData/299091.jpg)\n", + " Processing 5/200 image (trainingData/242078.jpg)\n", + " Processing 6/200 image (trainingData/232038.jpg)\n", + " Processing 7/200 image (trainingData/173036.jpg)\n", + " Processing 8/200 image (trainingData/198054.jpg)\n", + " Processing 9/200 image (trainingData/388016.jpg)\n", + " Processing 10/200 image (trainingData/292066.jpg)\n", + " Processing 11/200 image (trainingData/189011.jpg)\n", + " Processing 12/200 image (trainingData/59078.jpg)\n", + " Processing 13/200 image (trainingData/108041.jpg)\n", + " Processing 14/200 image (trainingData/66075.jpg)\n", + " Processing 15/200 image (trainingData/20008.jpg)\n", + " Processing 16/200 image (trainingData/370036.jpg)\n", + " Processing 17/200 image (trainingData/41025.jpg)\n", + " Processing 18/200 image (trainingData/207056.jpg)\n", + " Processing 19/200 image (trainingData/314016.jpg)\n", + " Processing 20/200 image (trainingData/188091.jpg)\n", + " Processing 21/200 image (trainingData/56028.jpg)\n", + " Processing 22/200 image (trainingData/134008.jpg)\n", + " Processing 23/200 image (trainingData/153093.jpg)\n", + " Processing 24/200 image (trainingData/54005.jpg)\n", + " Processing 25/200 image (trainingData/65019.jpg)\n", + " Processing 26/200 image (trainingData/176039.jpg)\n", + " Processing 27/200 image (trainingData/187003.jpg)\n", + " Processing 28/200 image (trainingData/61086.jpg)\n", + " Processing 29/200 image (trainingData/147021.jpg)\n", + " Processing 30/200 image (trainingData/353013.jpg)\n", + " Processing 31/200 image (trainingData/317080.jpg)\n", + " Processing 32/200 image (trainingData/28096.jpg)\n", + " Processing 33/200 image (trainingData/35010.jpg)\n", + " Processing 34/200 image (trainingData/151087.jpg)\n", + " Processing 35/200 image (trainingData/254033.jpg)\n", + " Processing 36/200 image (trainingData/189003.jpg)\n", + " Processing 37/200 image (trainingData/144067.jpg)\n", + " Processing 38/200 image (trainingData/33066.jpg)\n", + " Processing 39/200 image (trainingData/138032.jpg)\n", + " Processing 40/200 image (trainingData/15088.jpg)\n", + " Processing 41/200 image (trainingData/249061.jpg)\n", + " Processing 42/200 image (trainingData/68077.jpg)\n", + " Processing 43/200 image (trainingData/368078.jpg)\n", + " Processing 44/200 image (trainingData/187039.jpg)\n", + " Processing 45/200 image (trainingData/87065.jpg)\n", + " Processing 46/200 image (trainingData/216066.jpg)\n", + " Processing 47/200 image (trainingData/43083.jpg)\n", + " Processing 48/200 image (trainingData/372047.jpg)\n", + " Processing 49/200 image (trainingData/227046.jpg)\n", + " Processing 50/200 image (trainingData/15004.jpg)\n", + " Processing 51/200 image (trainingData/236017.jpg)\n", + " Processing 52/200 image (trainingData/310007.jpg)\n", + " Processing 53/200 image (trainingData/198023.jpg)\n", + " Processing 54/200 image (trainingData/22093.jpg)\n", + " Processing 55/200 image (trainingData/106025.jpg)\n", + " Processing 56/200 image (trainingData/202012.jpg)\n", + " Processing 57/200 image (trainingData/159045.jpg)\n", + " Processing 58/200 image (trainingData/376020.jpg)\n", + " Processing 59/200 image (trainingData/124084.jpg)\n", + " Processing 60/200 image (trainingData/254054.jpg)\n", + " Processing 61/200 image (trainingData/25098.jpg)\n", + " Processing 62/200 image (trainingData/8049.jpg)\n", + " Processing 63/200 image (trainingData/104022.jpg)\n", + " Processing 64/200 image (trainingData/238011.jpg)\n", + " Processing 65/200 image (trainingData/285036.jpg)\n", + " Processing 66/200 image (trainingData/65132.jpg)\n", + " Processing 67/200 image (trainingData/326038.jpg)\n", + " Processing 68/200 image (trainingData/22090.jpg)\n", + " Processing 69/200 image (trainingData/159091.jpg)\n", + " Processing 70/200 image (trainingData/76002.jpg)\n", + " Processing 71/200 image (trainingData/227040.jpg)\n", + " Processing 72/200 image (trainingData/145053.jpg)\n", + " Processing 73/200 image (trainingData/374020.jpg)\n", + " Processing 74/200 image (trainingData/46076.jpg)\n", + " Processing 75/200 image (trainingData/100080.jpg)\n", + " Processing 76/200 image (trainingData/113016.jpg)\n", + " Processing 77/200 image (trainingData/134052.jpg)\n", + " Processing 78/200 image (trainingData/311068.jpg)\n", + " Processing 79/200 image (trainingData/239096.jpg)\n", + " Processing 80/200 image (trainingData/187071.jpg)\n", + " Processing 81/200 image (trainingData/16052.jpg)\n", + " Processing 82/200 image (trainingData/94079.jpg)\n", + " Processing 83/200 image (trainingData/311081.jpg)\n", + " Processing 84/200 image (trainingData/118035.jpg)\n", + " Processing 85/200 image (trainingData/130034.jpg)\n", + " Processing 86/200 image (trainingData/138078.jpg)\n", + " Processing 87/200 image (trainingData/35070.jpg)\n", + " Processing 88/200 image (trainingData/35058.jpg)\n", + " Processing 89/200 image (trainingData/260081.jpg)\n", + " Processing 90/200 image (trainingData/246053.jpg)\n", + " Processing 91/200 image (trainingData/26031.jpg)\n", + " Processing 92/200 image (trainingData/67079.jpg)\n", + " Processing 93/200 image (trainingData/164074.jpg)\n", + " Processing 94/200 image (trainingData/95006.jpg)\n", + " Processing 95/200 image (trainingData/27059.jpg)\n", + " Processing 96/200 image (trainingData/66039.jpg)\n", + " Processing 97/200 image (trainingData/112082.jpg)\n", + " Processing 98/200 image (trainingData/140075.jpg)\n", + " Processing 99/200 image (trainingData/106020.jpg)\n", + " Processing 100/200 image (trainingData/97017.jpg)\n", + " Processing 101/200 image (trainingData/302003.jpg)\n", + " Processing 102/200 image (trainingData/118020.jpg)\n", + " Processing 103/200 image (trainingData/365073.jpg)\n", + " Processing 104/200 image (trainingData/178054.jpg)\n", + " Processing 105/200 image (trainingData/216053.jpg)\n", + " Processing 106/200 image (trainingData/268002.jpg)\n", + " Processing 107/200 image (trainingData/368016.jpg)\n", + " Processing 108/200 image (trainingData/117054.jpg)\n", + " Processing 109/200 image (trainingData/277095.jpg)\n", + " Processing 110/200 image (trainingData/274007.jpg)\n", + " Processing 111/200 image (trainingData/385028.jpg)\n", + " Processing 112/200 image (trainingData/48055.jpg)\n", + " Processing 113/200 image (trainingData/286092.jpg)\n", + " Processing 114/200 image (trainingData/23025.jpg)\n", + " Processing 115/200 image (trainingData/24004.jpg)\n", + " Processing 116/200 image (trainingData/323016.jpg)\n", + " Processing 117/200 image (trainingData/271008.jpg)\n", + " Processing 118/200 image (trainingData/376001.jpg)\n", + " Processing 119/200 image (trainingData/187083.jpg)\n", + " Processing 120/200 image (trainingData/161062.jpg)\n", + " Processing 121/200 image (trainingData/188005.jpg)\n", + " Processing 122/200 image (trainingData/100098.jpg)\n", + " Processing 123/200 image (trainingData/135037.jpg)\n", + " Processing 124/200 image (trainingData/309004.jpg)\n", + " Processing 125/200 image (trainingData/169012.jpg)\n", + " Processing 126/200 image (trainingData/231015.jpg)\n", + " Processing 127/200 image (trainingData/166081.jpg)\n", + " Processing 128/200 image (trainingData/271031.jpg)\n", + " Processing 129/200 image (trainingData/216041.jpg)\n", + " Processing 130/200 image (trainingData/181018.jpg)\n", + " Processing 131/200 image (trainingData/163062.jpg)\n", + " Processing 132/200 image (trainingData/35091.jpg)\n", + " Processing 133/200 image (trainingData/198004.jpg)\n", + " Processing 134/200 image (trainingData/196015.jpg)\n", + " Processing 135/200 image (trainingData/172032.jpg)\n", + " Processing 136/200 image (trainingData/12003.jpg)\n", + " Processing 137/200 image (trainingData/147062.jpg)\n", + " Processing 138/200 image (trainingData/105053.jpg)\n", + " Processing 139/200 image (trainingData/43070.jpg)\n", + " Processing 140/200 image (trainingData/65074.jpg)\n", + " Processing 141/200 image (trainingData/78019.jpg)\n", + " Processing 142/200 image (trainingData/140055.jpg)\n", + " Processing 143/200 image (trainingData/100075.jpg)\n", + " Processing 144/200 image (trainingData/113009.jpg)\n", + " Processing 145/200 image (trainingData/155060.jpg)\n", + " Processing 146/200 image (trainingData/60079.jpg)\n", + " Processing 147/200 image (trainingData/23084.jpg)\n", + " Processing 148/200 image (trainingData/249087.jpg)\n", + " Processing 149/200 image (trainingData/183087.jpg)\n", + " Processing 150/200 image (trainingData/45077.jpg)\n", + " Processing 151/200 image (trainingData/22013.jpg)\n", + " Processing 152/200 image (trainingData/209070.jpg)\n", + " Processing 153/200 image (trainingData/55067.jpg)\n", + " Processing 154/200 image (trainingData/245051.jpg)\n", + " Processing 155/200 image (trainingData/239007.jpg)\n", + " Processing 156/200 image (trainingData/176019.jpg)\n", + " Processing 157/200 image (trainingData/8143.jpg)\n", + " Processing 158/200 image (trainingData/103041.jpg)\n", + " Processing 159/200 image (trainingData/145014.jpg)\n", + " Processing 160/200 image (trainingData/113044.jpg)\n", + " Processing 161/200 image (trainingData/374067.jpg)\n", + " Processing 162/200 image (trainingData/41004.jpg)\n", + " Processing 163/200 image (trainingData/109034.jpg)\n", + " Processing 164/200 image (trainingData/35008.jpg)\n", + " Processing 165/200 image (trainingData/246016.jpg)\n", + " Processing 166/200 image (trainingData/135069.jpg)\n", + " Processing 167/200 image (trainingData/225017.jpg)\n", + " Processing 168/200 image (trainingData/361084.jpg)\n", + " Processing 169/200 image (trainingData/61060.jpg)\n", + " Processing 170/200 image (trainingData/253036.jpg)\n", + " Processing 171/200 image (trainingData/65010.jpg)\n", + " Processing 172/200 image (trainingData/105019.jpg)\n", + " Processing 173/200 image (trainingData/90076.jpg)\n", + " Processing 174/200 image (trainingData/42078.jpg)\n", + " Processing 175/200 image (trainingData/42044.jpg)\n", + " Processing 176/200 image (trainingData/156079.jpg)\n", + " Processing 177/200 image (trainingData/188063.jpg)\n", + " Processing 178/200 image (trainingData/126039.jpg)\n", + " Processing 179/200 image (trainingData/28075.jpg)\n", + " Processing 180/200 image (trainingData/55075.jpg)\n", + " Processing 181/200 image (trainingData/122048.jpg)\n", + " Processing 182/200 image (trainingData/163014.jpg)\n", + " Processing 183/200 image (trainingData/181091.jpg)\n", + " Processing 184/200 image (trainingData/170054.jpg)\n", + " Processing 185/200 image (trainingData/301007.jpg)\n", + " Processing 186/200 image (trainingData/12074.jpg)\n", + " Processing 187/200 image (trainingData/247085.jpg)\n", + " Processing 188/200 image (trainingData/293029.jpg)\n", + " Processing 189/200 image (trainingData/176035.jpg)\n", + " Processing 190/200 image (trainingData/80099.jpg)\n", + " Processing 191/200 image (trainingData/159029.jpg)\n", + " Processing 192/200 image (trainingData/24063.jpg)\n", + " Processing 193/200 image (trainingData/183055.jpg)\n", + " Processing 194/200 image (trainingData/2092.jpg)\n", + " Processing 195/200 image (trainingData/181079.jpg)\n", + " Processing 196/200 image (trainingData/92059.jpg)\n", + " Processing 197/200 image (trainingData/108073.jpg)\n", + " Processing 198/200 image (trainingData/153077.jpg)\n", + " Processing 199/200 image (trainingData/23080.jpg)\n", + " Processing 200/200 image (trainingData/365025.jpg)\n", + "(121, 600000)\n", + "(600000, 1)\n", + "PCA matrix saved\n", + "\n", + "kmeans model saved\n" + ] + } + ], + "source": [ + "imagecount = 1\n", + "for image in filelist:\n", + " print('\\r', end='')\n", + " print('' * 60, end='')\n", + " print('\\r Processing ' + str(imagecount) + '/' + str(len(filelist)) + ' image (' + image + ')')\n", + " im_uint8 = cv2.imread(image)\n", + " im_mp = mpimg.imread(image)\n", + " if len(im_mp.shape) == 2:\n", + " im_uint8 = im_uint8[:,:,0]\n", + " im_uint8 = modcrop(im_uint8, R)\n", + " if len(im_uint8.shape) > 2:\n", + " im_ycbcr = BGR2YCbCr(im_uint8)\n", + " im = im_ycbcr[:, :, 0]\n", + " else:\n", + " im = im_uint8\n", + " im_double = im2double(im)\n", + " H, W = im.shape\n", + " region = (slice(patchMargin, H - patchMargin), slice(patchMargin, W - patchMargin))\n", + " #start = time.time()\n", + " imL = imresize(im_double, 1 / R, interp='bicubic', mode='F')\n", + " im_bicubic = imresize(imL, (H, W), interp='bicubic', mode='F')\n", + " im_bicubic = im_bicubic.astype('float64')\n", + " im_bicubic = np.clip(im_bicubic, 0, 1)\n", + " im_LR = np.zeros((H+patchSize-1,W+patchSize-1))\n", + " im_LR[(patchMargin):(H+patchMargin),(patchMargin):(W+patchMargin)] = im_bicubic\n", + " im_result = np.zeros((H, W))\n", + " #im_GX, im_GY = np.gradient(im_LR)\n", + " index = np.array(range(im_LR.size)).reshape(im_LR.shape)\n", + " offset = np.array(index[0:H, 0:W].ravel())\n", + " rand = np.random.randint(0, offset.size, patchNum)\n", + " gridon = index[0:patchSize, 0:patchSize]\n", + " grid = np.tile(gridon[..., None], [1, 1, patchNum]) + np.tile(rand, [patchSize, patchSize, 1])\n", + " if imagecount == 1:\n", + " sample = im_LR.ravel()[grid]\n", + " else:\n", + " sample = np.concatenate((sample, im_LR.ravel()[grid]), axis=2)\n", + "\n", + " imagecount += 1\n", + " \n", + "sample = sample.reshape(patchSize*patchSize, -1)\n", + "print(sample.shape)\n", + "\n", + "# PCA\n", + "mean = np.mean(sample, axis=1).reshape(-1,1)\n", + "sample -= mean\n", + "ssT = np.dot(sample, sample.T) / sample.shape[1]\n", + "U, S, V = np.linalg.svd(ssT)\n", + "pca_matrix = U[:, :dim_pca].T\n", + "sample_reduced = np.dot(pca_matrix, sample).reshape(-1, dim_pca)\n", + "print(sample_reduced.shape)\n", + "# Store the PCA\n", + "io.savemat(meanSavePath, {'m': mean})\n", + "io.savemat(pcaSavePath, {'p': pca_matrix})\n", + "print('PCA matrix saved\\n')\n", + "\n", + "# Clustering\n", + "kmeans = kmeans.fit(sample_reduced)\n", + "joblib.dump(kmeans, kmeansSavePath)\n", + "print('kmeans model saved\\r')\n", + "# print(kmeans.cluster_centers_)\n", + "\n", + "\n", + "\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Playground" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(121, 600000)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sample.shape" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "kmeans.cluster_centers_" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "340067" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.count_nonzero(kmeans.labels_)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "614" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.sum(kmeans.labels_==3)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([4.15005383, 0.25179007, 0.19843432, 0.06874853, 0.05521984,\n", + " 0.03884089, 0.02875973, 0.02323614, 0.01864805, 0.01738227,\n", + " 0.01355224, 0.0096365 , 0.00923075, 0.00827282, 0.00754641,\n", + " 0.00749147, 0.00498264, 0.00470902, 0.00449849, 0.00443665,\n", + " 0.00375496, 0.0033786 , 0.00306299, 0.00298789, 0.00276854,\n", + " 0.00267204, 0.0024356 , 0.00225047, 0.00206228, 0.0020455 ,\n", + " 0.00189912, 0.00128627, 0.00126568, 0.00112841, 0.0010248 ,\n", + " 0.000984 , 0.00077913, 0.00074539, 0.00053144, 0.00047638,\n", + " 0.00046261, 0.00039562, 0.00037052, 0.00034805, 0.00032054,\n", + " 0.00031788, 0.00025687, 0.00024069, 0.00018133, 0.00017973,\n", + " 0.00016796, 0.00016049, 0.00015801, 0.00015672, 0.00011388,\n", + " 0.00010976, 0.00008082, 0.00007999, 0.00007875, 0.00007712,\n", + " 0.00006935, 0.00006722, 0.00006524, 0.00004899, 0.00004523,\n", + " 0.00003846, 0.00003653, 0.00003451, 0.0000337 , 0.00003192,\n", + " 0.00003024, 0.00003022, 0.00002386, 0.00002267, 0.00001697,\n", + " 0.000016 , 0.00001497, 0.00001448, 0.00001433, 0.00001335,\n", + " 0.00001104, 0.0000097 , 0.00000872, 0.00000759, 0.0000065 ,\n", + " 0.00000629, 0.00000623, 0.00000562, 0.000005 , 0.00000452,\n", + " 0.00000375, 0.00000331, 0.0000031 , 0.00000273, 0.00000247,\n", + " 0.00000199, 0.00000192, 0.00000163, 0.00000146, 0.00000132,\n", + " 0.00000125, 0.00000088, 0.0000008 , 0.00000072, 0.00000067,\n", + " 0.00000055, 0.00000046, 0.00000039, 0.00000036, 0.0000003 ,\n", + " 0.00000022, 0.00000021, 0.0000002 , 0.00000016, 0.00000013,\n", + " 0.00000011, 0.00000009, 0.00000007, 0.00000005, 0.00000002,\n", + " 0.00000001])" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "S" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(1, 121)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pca_matrix = io.loadmat('2000_patch_PCA_matrix.mat')['p']\n", + "pca_matrix.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "134849" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kmeans = joblib.load('1_2000_kmeans.model')\n", + "np.sum(kmeans.labels_==0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b17abeb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +# +# To install the dependencies run in your shell the following command: +# pip install -U -r requirements.txt +# +numpy==1.14.0 +numba==0.37.0 +opencv-python==3.3.0.10 +scipy==1.1.0 +scikit-learn==0.19.1 +scikit-image==0.13.1 +Pillow==5.0.0 + diff --git a/results/.DS_Store b/results/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/results/.DS_Store differ diff --git a/results/baboon_result.bmp b/results/baboon_result.bmp new file mode 100644 index 0000000..e199878 Binary files /dev/null and b/results/baboon_result.bmp differ diff --git a/results/barbara_result.bmp b/results/barbara_result.bmp new file mode 100644 index 0000000..a6bf17d Binary files /dev/null and b/results/barbara_result.bmp differ diff --git a/results/bridge_result.bmp b/results/bridge_result.bmp new file mode 100644 index 0000000..080b342 Binary files /dev/null and b/results/bridge_result.bmp differ diff --git a/results/coastguard_result.bmp b/results/coastguard_result.bmp new file mode 100644 index 0000000..22d8ae2 Binary files /dev/null and b/results/coastguard_result.bmp differ diff --git a/results/comic_result.bmp b/results/comic_result.bmp new file mode 100644 index 0000000..c3337a0 Binary files /dev/null and b/results/comic_result.bmp differ diff --git a/results/face_result.bmp b/results/face_result.bmp new file mode 100644 index 0000000..29abc59 Binary files /dev/null and b/results/face_result.bmp differ diff --git a/results/flowers_result.bmp b/results/flowers_result.bmp new file mode 100644 index 0000000..aa189ea Binary files /dev/null and b/results/flowers_result.bmp differ diff --git a/results/foreman_result.bmp b/results/foreman_result.bmp new file mode 100644 index 0000000..a82c0db Binary files /dev/null and b/results/foreman_result.bmp differ diff --git a/results/img_001_SRF_2_HR_result.bmp b/results/img_001_SRF_2_HR_result.bmp new file mode 100644 index 0000000..fb34dbe Binary files /dev/null and b/results/img_001_SRF_2_HR_result.bmp differ diff --git a/results/img_002_SRF_2_HR_result.bmp b/results/img_002_SRF_2_HR_result.bmp new file mode 100644 index 0000000..497677d Binary files /dev/null and b/results/img_002_SRF_2_HR_result.bmp differ diff --git a/results/img_003_SRF_2_HR_result.bmp b/results/img_003_SRF_2_HR_result.bmp new file mode 100644 index 0000000..5940bac Binary files /dev/null and b/results/img_003_SRF_2_HR_result.bmp differ diff --git a/results/img_004_SRF_2_HR_result.bmp b/results/img_004_SRF_2_HR_result.bmp new file mode 100644 index 0000000..76ccb2e Binary files /dev/null and b/results/img_004_SRF_2_HR_result.bmp differ diff --git a/results/img_005_SRF_2_HR_result.bmp b/results/img_005_SRF_2_HR_result.bmp new file mode 100644 index 0000000..e2045bb Binary files /dev/null and b/results/img_005_SRF_2_HR_result.bmp differ diff --git a/results/lenna_result.bmp b/results/lenna_result.bmp new file mode 100644 index 0000000..a32ad0f Binary files /dev/null and b/results/lenna_result.bmp differ diff --git a/results/man_result.bmp b/results/man_result.bmp new file mode 100644 index 0000000..86bc87b Binary files /dev/null and b/results/man_result.bmp differ diff --git a/results/monarch_result.bmp b/results/monarch_result.bmp new file mode 100644 index 0000000..40f1473 Binary files /dev/null and b/results/monarch_result.bmp differ diff --git a/results/pepper_result.bmp b/results/pepper_result.bmp new file mode 100644 index 0000000..c5dab94 Binary files /dev/null and b/results/pepper_result.bmp differ diff --git a/results/ppt3_result.bmp b/results/ppt3_result.bmp new file mode 100644 index 0000000..624fd7c Binary files /dev/null and b/results/ppt3_result.bmp differ diff --git a/results/zebra_result.bmp b/results/zebra_result.bmp new file mode 100644 index 0000000..40bb4e0 Binary files /dev/null and b/results/zebra_result.bmp differ diff --git a/set 14/.DS_Store b/set 14/.DS_Store new file mode 100644 index 0000000..64d9913 Binary files /dev/null and b/set 14/.DS_Store differ diff --git a/set 14/baboon.bmp b/set 14/baboon.bmp new file mode 100644 index 0000000..2aef6c9 Binary files /dev/null and b/set 14/baboon.bmp differ diff --git a/set 14/barbara.bmp b/set 14/barbara.bmp new file mode 100644 index 0000000..bea744e Binary files /dev/null and b/set 14/barbara.bmp differ diff --git a/set 14/bridge.bmp b/set 14/bridge.bmp new file mode 100644 index 0000000..53f5059 Binary files /dev/null and b/set 14/bridge.bmp differ diff --git a/set 14/coastguard.bmp b/set 14/coastguard.bmp new file mode 100644 index 0000000..ae05ac8 Binary files /dev/null and b/set 14/coastguard.bmp differ diff --git a/set 14/comic.bmp b/set 14/comic.bmp new file mode 100644 index 0000000..ff00ff7 Binary files /dev/null and b/set 14/comic.bmp differ diff --git a/set 14/face.bmp b/set 14/face.bmp new file mode 100644 index 0000000..f8f9c4b Binary files /dev/null and b/set 14/face.bmp differ diff --git a/set 14/flowers.bmp b/set 14/flowers.bmp new file mode 100644 index 0000000..3e40906 Binary files /dev/null and b/set 14/flowers.bmp differ diff --git a/set 14/foreman.bmp b/set 14/foreman.bmp new file mode 100644 index 0000000..837063b Binary files /dev/null and b/set 14/foreman.bmp differ diff --git a/set 14/lenna.bmp b/set 14/lenna.bmp new file mode 100644 index 0000000..d78becd Binary files /dev/null and b/set 14/lenna.bmp differ diff --git a/set 14/man.bmp b/set 14/man.bmp new file mode 100644 index 0000000..9fb2193 Binary files /dev/null and b/set 14/man.bmp differ diff --git a/set 14/monarch.bmp b/set 14/monarch.bmp new file mode 100644 index 0000000..85b01ef Binary files /dev/null and b/set 14/monarch.bmp differ diff --git a/set 14/pepper.bmp b/set 14/pepper.bmp new file mode 100644 index 0000000..1032e6f Binary files /dev/null and b/set 14/pepper.bmp differ diff --git a/set 14/ppt3.bmp b/set 14/ppt3.bmp new file mode 100644 index 0000000..4b17682 Binary files /dev/null and b/set 14/ppt3.bmp differ diff --git a/set 14/zebra.bmp b/set 14/zebra.bmp new file mode 100644 index 0000000..ddcdabe Binary files /dev/null and b/set 14/zebra.bmp differ diff --git a/test.ipynb b/test.ipynb new file mode 100644 index 0000000..b895955 --- /dev/null +++ b/test.ipynb @@ -0,0 +1,465 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/anaconda3/lib/python3.7/site-packages/sklearn/externals/joblib/__init__.py:15: DeprecationWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.\n", + " warnings.warn(msg, category=DeprecationWarning)\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "import numba as nb\n", + "import os\n", + "import cv2\n", + "import warnings\n", + "import pickle\n", + "import time\n", + "from math import floor\n", + "from skimage.measure import compare_psnr\n", + "from scipy.misc import imresize\n", + "from Functions import *\n", + "import matplotlib.image as mpimg\n", + "from multiprocessing import Pool\n", + "\n", + "warnings.filterwarnings('ignore')" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "testPath = 'set 14'\n", + "isKmeans = True\n", + "\n", + "R = 3 # Upscaling factor=2 R = [ 2 3 4 ]\n", + "patchSize = 11 # Pacth Size=11\n", + "gradientSize = 9\n", + "Qangle = 24 # Quantization factor of angle =24\n", + "Qstrength = 3 # Quantization factor of strength =3\n", + "Qcoherence = 3 # Quantization factor of coherence =3\n", + "\n", + "if isKmeans:\n", + " # Kmeans-RAISR\n", + " with open(\"Filters/Ckmeans_filter\"+str(R), \"rb\") as fp:\n", + " h = pickle.load(fp)\n", + "\n", + " with open(\"Filters/Ckmeans_Qfactor_str\"+str(R), \"rb\") as sp:\n", + " stre = pickle.load(sp)\n", + "\n", + " with open(\"Filters/Ckmeans_Qfactor_coh\"+str(R), \"rb\") as cp:\n", + " cohe = pickle.load(cp)\n", + "else: \n", + " # RAISR \n", + " with open(\"Filters/8x_filter\"+str(R), \"rb\") as fp:\n", + " h = pickle.load(fp)\n", + "\n", + " with open(\"Filters/8x_Qfactor_str\"+str(R), \"rb\") as sp:\n", + " stre = pickle.load(sp)\n", + "\n", + " with open(\"Filters/8x_Qfactor_coh\"+str(R), \"rb\") as cp:\n", + " cohe = pickle.load(cp)\n", + "\n", + "kmeans = joblib.load('x'+str(R)+'_'+'1_3000_kmeans.model')\n", + "pca_matrix = io.loadmat('x'+str(R)+'_'+'1_3000_patch_PCA_matrix.mat')['p']\n", + "mean = io.loadmat('x'+str(R)+'_'+'1_3000_patch_mean_matrix.mat')['m']\n", + "\n", + "\n", + "filelist = make_dataset(testPath)\n", + "\n", + "wGaussian = Gaussian2d([patchSize, patchSize], 2)\n", + "wGaussian = wGaussian/wGaussian.max()\n", + "wGaussian = np.diag(wGaussian.ravel())\n", + "imagecount = 1\n", + "patchMargin = floor(patchSize/2)\n", + "psnrRAISR = []\n", + "psnrBicubic = []\n", + "psnrBlending = []" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def TestProcess(i):\n", + " if (i < iteration - 1):\n", + " offset_i = offset[i * batch:i * batch + batch]\n", + " offset2_i = offset2[i * batch:i * batch + batch]\n", + " grid = np.tile(gridon[..., None], [1, 1, batch]) + np.tile(offset_i, [patchSize, patchSize, 1])\n", + " else:\n", + " offset_i = offset[i * batch:im.size]\n", + " offset2_i = offset2[i * batch:im.size]\n", + " grid = np.tile(gridon[..., None], [1, 1, im.size - (iteration - 1) * batch]) + np.tile(offset_i,[patchSize, patchSize,1])\n", + " f = im_LR.ravel()[grid]\n", + " gx = im_GX.ravel()[grid]\n", + " gy = im_GY.ravel()[grid]\n", + " gx = gx.reshape((1, patchSize * patchSize, gx.shape[2]))\n", + " gy = gy.reshape((1, patchSize * patchSize, gy.shape[2]))\n", + " G = np.vstack((gx, gy))\n", + " g1 = np.transpose(G, (2, 0, 1))\n", + " g2 = np.transpose(G, (2, 1, 0))\n", + " x = Gaussian_Mul(g1, g2, wGaussian)\n", + " w, v = np.linalg.eig(x)\n", + " idx = (-w).argsort()\n", + " w = w[np.arange(np.shape(w)[0])[:, np.newaxis], idx]\n", + " v = v[np.arange(np.shape(v)[0])[:, np.newaxis, np.newaxis], np.arange(np.shape(v)[1])[np.newaxis, :, np.newaxis], idx[:,np.newaxis,:]]\n", + " thelta = np.arctan(v[:, 1, 0] / v[:, 0, 0])\n", + " thelta[thelta < 0] = thelta[thelta < 0] + pi\n", + " thelta = np.floor(thelta / (pi / Qangle))\n", + " thelta[thelta > Qangle - 1] = Qangle - 1\n", + " thelta[thelta < 0] = 0\n", + " lamda = w[:, 0]\n", + " u = (np.sqrt(w[:, 0]) - np.sqrt(w[:, 1])) / (np.sqrt(w[:, 0]) + np.sqrt(w[:, 1]) + 0.00000000000000001)\n", + " lamda = np.searchsorted(stre, lamda)\n", + " u = np.searchsorted(cohe, u)\n", + " j = thelta * Qstrength * Qcoherence + lamda * Qcoherence + u\n", + " j = j.astype('int')\n", + " offset2_i = np.unravel_index(offset2_i, (H, W))\n", + " \n", + " if isKmeans:\n", + " f_vec = np.reshape(f, (patchSize * patchSize, -1)) - mean\n", + " f_vec_reduced = np.dot(pca_matrix, f_vec)\n", + " t = kmeans.predict(f_vec_reduced.reshape(-1, 1))\n", + " if i ==10:\n", + " print(np.sum(t==0)/t.shape[0])\n", + " print(np.sum(t==1)/t.shape[0])\n", + " print(np.sum(t==2)/t.shape[0])\n", + " print(np.sum(t==3)/t.shape[0])\n", + " else:\n", + " t = ((offset2_i[0] - patchMargin) % R) * R + ((offset2_i[1] - patchMargin) % R)\n", + " if i ==10:\n", + " print(np.sum(t==0)/t.shape[0])\n", + " print(np.sum(t==1)/t.shape[0])\n", + " print(np.sum(t==2)/t.shape[0])\n", + " print(np.sum(t==3)/t.shape[0])\n", + " \n", + " filtertj = h[t, j]\n", + " filtertj = filtertj[:, :, np.newaxis]\n", + " patch = f.reshape((1, patchSize * patchSize, gx.shape[2]))\n", + " patch = np.transpose(patch, (2, 0, 1))\n", + " result = np.matmul(patch, filtertj)\n", + " return result" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Begin to process images:\n", + " Processing 1/14 image (set 14/foreman.bmp)\n", + "0.007\n", + "0.103\n", + "0.003\n", + "0.026\n", + "1.831017017364502\n", + " Processing 2/14 image (set 14/man.bmp)\n", + "0.201\n", + "0.0\n", + "0.1285\n", + "0.1545\n", + "2.272819995880127\n", + " Processing 3/14 image (set 14/pepper.bmp)\n", + "0.0795\n", + "0.199\n", + "0.0105\n", + "0.098\n", + "2.2575268745422363\n", + " Processing 4/14 image (set 14/comic.bmp)\n", + "0.1235\n", + "0.1765\n", + "0.0075\n", + "0.144\n", + "1.6734352111816406\n", + " Processing 5/14 image (set 14/coastguard.bmp)\n", + "0.002\n", + "0.0\n", + "0.396\n", + "0.0\n", + "1.744534969329834\n", + " Processing 6/14 image (set 14/baboon.bmp)\n", + "0.262\n", + "0.0\n", + "0.178\n", + "0.07\n", + "2.1803929805755615\n", + " Processing 7/14 image (set 14/monarch.bmp)\n", + "0.2015\n", + "0.0425\n", + "0.002\n", + "0.092\n", + "2.756720781326294\n", + " Processing 8/14 image (set 14/flowers.bmp)\n", + "0.144\n", + "0.0305\n", + "0.0625\n", + "0.0625\n", + "1.9593002796173096\n", + " Processing 9/14 image (set 14/face.bmp)\n", + "0.0\n", + "0.0\n", + "0.2825\n", + "0.0\n", + "1.7156181335449219\n", + " Processing 10/14 image (set 14/ppt3.bmp)\n", + "0.002\n", + "0.442\n", + "0.0\n", + "0.006\n", + "2.7992820739746094\n", + " Processing 11/14 image (set 14/zebra.bmp)\n", + "0.0045\n", + "0.8675\n", + "0.0\n", + "0.1205\n", + "2.5149271488189697\n", + " Processing 12/14 image (set 14/bridge.bmp)\n", + "0.189\n", + "0.099\n", + "0.0005\n", + "0.1165\n", + "2.4983890056610107\n", + " Processing 13/14 image (set 14/barbara.bmp)\n", + "0.2255\n", + "0.128\n", + "0.0245\n", + "0.2385\n", + "3.076923131942749\n", + " Processing 14/14 image (set 14/lenna.bmp)\n", + "0.41\n", + "0.206\n", + "0.061\n", + "0.204\n", + "3.32521390914917\n", + " RAISR PSNR of set 14 is 28.63918137404164\n", + " Bicubic PSNR of set 14 is 27.550055549338857\n" + ] + } + ], + "source": [ + "print('Begin to process images:')\n", + "for image in filelist:\n", + " print('\\r', end='')\n", + " print('' * 60, end='')\n", + " print('\\r Processing ' + str(imagecount) + '/' + str(len(filelist)) + ' image (' + image + ')')\n", + " im_uint8 = cv2.imread(image)\n", + " im_mp = mpimg.imread(image)\n", + " if len(im_mp.shape) == 2:\n", + " im_uint8 = im_uint8[:,:,0]\n", + " im_uint8 = modcrop(im_uint8, R)\n", + " if len(im_uint8.shape) > 2:\n", + " im_ycbcr = BGR2YCbCr(im_uint8)\n", + " im = im_ycbcr[:, :, 0]\n", + " else:\n", + " im = im_uint8\n", + " im_double = im2double(im)\n", + " H, W = im.shape\n", + " region = (slice(patchMargin, H - patchMargin), slice(patchMargin, W - patchMargin))\n", + " start = time.time()\n", + " imL = imresize(im_double, 1 / R, interp='bicubic', mode='F')\n", + " im_bicubic = imresize(imL, (H, W), interp='bicubic', mode='F')\n", + " im_bicubic = im_bicubic.astype('float64')\n", + " im_bicubic = np.clip(im_bicubic, 0, 1)\n", + " im_LR = np.zeros((H+patchSize-1,W+patchSize-1))\n", + " im_LR[(patchMargin):(H+patchMargin),(patchMargin):(W+patchMargin)] = im_bicubic\n", + " im_result = np.zeros((H, W))\n", + " im_GX, im_GY = np.gradient(im_LR)\n", + " index = np.array(range(im_LR.size)).reshape(im_LR.shape)\n", + " offset = np.array(index[0:H, 0:W].ravel())\n", + " offset2 = np.array(range(im.size))\n", + " gridon = index[0:patchSize, 0:patchSize]\n", + " batch = 2000\n", + " iteration = ceil(im.size / batch + 0.000000000000001)\n", + "\n", + " im_result = np.array([])\n", + "\n", + " i = range(iteration)\n", + " p = Pool()\n", + " im_in = p.map(TestProcess, i)\n", + "\n", + " for i in range(iteration):\n", + " im_result = np.append(im_result, im_in[i])\n", + "\n", + " im_result = im_result.reshape(H, W)\n", + " im_result = np.clip(im_result, 0, 1)\n", + "\n", + " end = time.time()\n", + " print(end - start)\n", + "\n", + " im_blending = Blending2(im_bicubic, im_result)\n", + " im_blending = Backprojection(imL, im_blending, 1) #Optional: Backprojection, which can slightly improve PSNR, especilly for large upscaling factor.\n", + " im_blending = np.clip(im_blending, 0, 1)\n", + "\n", + " if len(im_uint8.shape) > 2:\n", + " result_ycbcr = np.zeros((H, W, 3))\n", + " result_ycbcr[:, :, 0] = im_blending * 255\n", + " result_ycbcr[:, :, 1] = Prepare(im_ycbcr[:, :, 1], patchSize, R) * 255\n", + " result_ycbcr[:, :, 2] = Prepare(im_ycbcr[:, :, 2], patchSize, R) * 255\n", + " result_ycbcr = result_ycbcr[region].astype('uint8')\n", + " result_RAISR = YCbCr2BGR(result_ycbcr)\n", + " else:\n", + " result_RAISR = im_result[region] * 255\n", + " result_RAISR = result_RAISR.astype('uint8')\n", + "\n", + " im_result = im_result*255\n", + " im_result = np.rint(im_result).astype('uint8')\n", + " im_bicubic = im_bicubic*255\n", + " im_bicubic = np.rint(im_bicubic).astype('uint8')\n", + " im_blending = im_blending * 255\n", + " im_blending = np.rint(im_blending).astype('uint8')\n", + "\n", + " PSNR_bicubic = compare_psnr(im[region], im_bicubic[region])\n", + " PSNR_result = compare_psnr(im[region], im_result[region])\n", + " PSNR_blending = compare_psnr(im[region], im_blending[region])\n", + " PSNR_blending = max(PSNR_result, PSNR_blending)\n", + "\n", + " createFolder('./results/')\n", + " cv2.imwrite('results/' + os.path.splitext(os.path.basename(image))[0] + '_result.bmp', result_RAISR)\n", + " psnrRAISR.append(PSNR_result)\n", + " psnrBicubic.append(PSNR_bicubic)\n", + " psnrBlending.append(PSNR_blending)\n", + "\n", + " imagecount += 1\n", + "\n", + "\n", + "RAISR_psnrmean = np.array(psnrBlending).mean()\n", + "Bicubic_psnrmean = np.array(psnrBicubic).mean()\n", + "\n", + "\n", + "print('\\r', end='')\n", + "print('' * 60, end='')\n", + "print('\\r RAISR PSNR of '+ testPath +' is ' + str(RAISR_psnrmean))\n", + "print('\\r Bicubic PSNR of '+ testPath +' is ' + str(Bicubic_psnrmean))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Playground" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[-3.44721766],\n", + " [ 2.60396842],\n", + " [-1.12103449],\n", + " [ 0.65496382]])" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kmeans.cluster_centers_" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.07130166666666667" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.sum(kmeans.labels_==8) / kmeans.labels_.shape[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/testData/.DS_Store b/testData/.DS_Store new file mode 100644 index 0000000..44404ec Binary files /dev/null and b/testData/.DS_Store differ diff --git a/testData/img_001_SRF_2_HR.png b/testData/img_001_SRF_2_HR.png new file mode 100644 index 0000000..ea3fccc Binary files /dev/null and b/testData/img_001_SRF_2_HR.png differ diff --git a/testData/img_002_SRF_2_HR.png b/testData/img_002_SRF_2_HR.png new file mode 100644 index 0000000..fd5acc0 Binary files /dev/null and b/testData/img_002_SRF_2_HR.png differ diff --git a/testData/img_003_SRF_2_HR.png b/testData/img_003_SRF_2_HR.png new file mode 100644 index 0000000..1a46f51 Binary files /dev/null and b/testData/img_003_SRF_2_HR.png differ diff --git a/testData/img_004_SRF_2_HR.png b/testData/img_004_SRF_2_HR.png new file mode 100644 index 0000000..aa282f6 Binary files /dev/null and b/testData/img_004_SRF_2_HR.png differ diff --git a/testData/img_005_SRF_2_HR.png b/testData/img_005_SRF_2_HR.png new file mode 100644 index 0000000..66ce243 Binary files /dev/null and b/testData/img_005_SRF_2_HR.png differ diff --git a/testDataSmall/img_003_SRF_2_HR.png b/testDataSmall/img_003_SRF_2_HR.png new file mode 100644 index 0000000..1a46f51 Binary files /dev/null and b/testDataSmall/img_003_SRF_2_HR.png differ diff --git a/train.ipynb b/train.ipynb new file mode 100644 index 0000000..ad75cf3 --- /dev/null +++ b/train.ipynb @@ -0,0 +1,1606 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/anaconda3/lib/python3.7/site-packages/sklearn/externals/joblib/__init__.py:15: DeprecationWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib. If this warning is raised when loading pickled models, you may need to re-serialize those models with scikit-learn 0.21+.\n", + " warnings.warn(msg, category=DeprecationWarning)\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "import numba as nb\n", + "import os\n", + "import cv2\n", + "import pickle\n", + "import time\n", + "from math import floor\n", + "from Functions import *\n", + "from multiprocessing import Pool\n", + "import numba as nb\n", + "import warnings" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "trainPath = 'trainingData'\n", + "\n", + "R = 2 # Upscaling factor=2\n", + "patchSize = 11 # Pacth Size=11\n", + "gradientSize = 9 # Gradient Size = 9\n", + "Qangle = 24 # Quantization factor of angle =24\n", + "Qstrength = 3 # Quantization factor of strength =3\n", + "Qcoherence = 3 # Quantization factor of coherence =3\n", + "stre = np.zeros((Qstrength-1)) # Strength boundary\n", + "cohe = np.zeros((Qcoherence-1)) # Coherence boundary\n", + "\n", + "Q = np.zeros((R*R, Qangle*Qstrength*Qcoherence, patchSize*patchSize, patchSize*patchSize)) # Eq.4\n", + "V = np.zeros((R*R, Qangle*Qstrength*Qcoherence, patchSize*patchSize)) # Eq.5\n", + "h = np.zeros((R*R, Qangle*Qstrength*Qcoherence, patchSize*patchSize))\n", + "mark = np.zeros((R*R, Qangle*Qstrength*Qcoherence)) # statical distribution of patch numbers in each bucket\n", + "w = Gaussian2d([patchSize, patchSize], 2)\n", + "w = w/w.max()\n", + "w = np.diag(w.ravel()) # Diagnal weighting matrix Wk in Algorithm 1\n", + "\n", + "filelist = make_dataset(trainPath)\n", + "\n", + "instance = 20000000 # use 20000000 patches to get the Strength and coherence boundary\n", + "\n", + "patchNumber = 0 # patch number has been used\n", + "quantization = np.zeros((instance,2)) # quantization boundary" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Quantization: Processing 10000000.0 patches (0.0%)\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/anaconda3/lib/python3.7/site-packages/numba/compiler.py:588: NumbaPerformanceWarning: \u001b[1m\n", + "The keyword argument 'parallel=True' was specified but no transformation for parallel execution was possible.\n", + "\n", + "To find out why, try turning on parallel diagnostics, see http://numba.pydata.org/numba-doc/latest/user/parallel.html#diagnostics for help.\n", + "\u001b[1m\n", + "File \"Functions.py\", line 130:\u001b[0m\n", + "\u001b[1m@nb.jit(nopython=True, parallel=True)\n", + "\u001b[1mdef Grad(patchX,patchY,weight):\n", + "\u001b[0m\u001b[1m^\u001b[0m\u001b[0m\n", + "\u001b[0m\n", + " self.func_ir.loc))\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Quantization: Processing 10000000.0 patches (1.4617%)\n", + " Quantization: Processing 10000000.0 patches (2.9234%)\n", + " Quantization: Processing 10000000.0 patches (4.3851%)\n", + " Quantization: Processing 10000000.0 patches (5.8468%)\n", + " Quantization: Processing 10000000.0 patches (7.3085%)\n", + " Quantization: Processing 10000000.0 patches (8.7702%)\n", + " Quantization: Processing 10000000.0 patches (10.2319%)\n", + " Quantization: Processing 10000000.0 patches (11.6936%)\n", + " Quantization: Processing 10000000.0 patches (13.1553%)\n", + " Quantization: Processing 10000000.0 patches (14.617%)\n", + " Quantization: Processing 10000000.0 patches (16.0787%)\n", + " Quantization: Processing 10000000.0 patches (17.5404%)\n", + " Quantization: Processing 10000000.0 patches (19.0021%)\n", + " Quantization: Processing 10000000.0 patches (20.4638%)\n", + " Quantization: Processing 10000000.0 patches (21.9255%)\n", + " Quantization: Processing 10000000.0 patches (23.3872%)\n", + " Quantization: Processing 10000000.0 patches (24.8489%)\n", + " Quantization: Processing 10000000.0 patches (26.3106%)\n", + " Quantization: Processing 10000000.0 patches (27.7723%)\n", + " Quantization: Processing 10000000.0 patches (29.234%)\n", + " Quantization: Processing 10000000.0 patches (30.6957%)\n", + " Quantization: Processing 10000000.0 patches (32.1574%)\n", + " Quantization: Processing 10000000.0 patches (33.6191%)\n", + " Quantization: Processing 10000000.0 patches (35.0808%)\n", + " Quantization: Processing 10000000.0 patches (36.5425%)\n", + " Quantization: Processing 10000000.0 patches (38.0042%)\n", + " Quantization: Processing 10000000.0 patches (39.4659%)\n", + " Quantization: Processing 10000000.0 patches (40.9276%)\n", + " Quantization: Processing 10000000.0 patches (42.3893%)\n", + " Quantization: Processing 10000000.0 patches (43.851%)\n", + " Quantization: Processing 10000000.0 patches (45.3127%)\n", + " Quantization: Processing 10000000.0 patches (46.7744%)\n", + " Quantization: Processing 10000000.0 patches (48.2361%)\n", + " Quantization: Processing 10000000.0 patches (49.6978%)\n", + " Quantization: Processing 10000000.0 patches (51.1595%)\n", + " Quantization: Processing 10000000.0 patches (52.6212%)\n", + " Quantization: Processing 10000000.0 patches (54.0829%)\n", + " Quantization: Processing 10000000.0 patches (55.5446%)\n", + " Quantization: Processing 10000000.0 patches (57.0063%)\n", + " Quantization: Processing 10000000.0 patches (58.468%)\n", + " Quantization: Processing 10000000.0 patches (59.9297%)\n", + " Quantization: Processing 10000000.0 patches (61.3914%)\n", + " Quantization: Processing 10000000.0 patches (62.8531%)\n", + " Quantization: Processing 10000000.0 patches (64.3148%)\n", + " Quantization: Processing 10000000.0 patches (65.7765%)\n", + " Quantization: Processing 10000000.0 patches (67.2382%)\n", + " Quantization: Processing 10000000.0 patches (68.6999%)\n", + " Quantization: Processing 10000000.0 patches (70.1616%)\n", + " Quantization: Processing 10000000.0 patches (71.6233%)\n", + " Quantization: Processing 10000000.0 patches (73.085%)\n", + " Quantization: Processing 10000000.0 patches (74.5467%)\n", + " Quantization: Processing 10000000.0 patches (76.0084%)\n", + " Quantization: Processing 10000000.0 patches (77.4701%)\n", + " Quantization: Processing 10000000.0 patches (78.9318%)\n", + " Quantization: Processing 10000000.0 patches (80.3935%)\n", + " Quantization: Processing 10000000.0 patches (81.8552%)\n", + " Quantization: Processing 10000000.0 patches (83.3169%)\n", + " Quantization: Processing 10000000.0 patches (84.7786%)\n", + " Quantization: Processing 10000000.0 patches (86.2403%)\n", + " Quantization: Processing 10000000.0 patches (87.702%)\n", + " Quantization: Processing 10000000.0 patches (89.1637%)\n", + " Quantization: Processing 10000000.0 patches (90.6254%)\n", + " Quantization: Processing 10000000.0 patches (92.0871%)\n", + " Quantization: Processing 10000000.0 patches (93.5488%)\n", + " Quantization: Processing 10000000.0 patches (95.0105%)\n", + " Quantization: Processing 10000000.0 patches (96.4722%)\n", + " Quantization: Processing 10000000.0 patches (97.9339%)\n", + " Quantization: Processing 10000000.0 patches (99.3956%)\n", + " done\n" + ] + } + ], + "source": [ + "for image in filelist:\n", + " print('\\r', end='')\n", + " print('' * 60, end='')\n", + " print('\\r Quantization: Processing '+ str(instance/2) + ' patches (' + str(200*patchNumber/instance) + '%)')\n", + " im_uint8 = cv2.imread(image)\n", + " if is_greyimage(im_uint8):\n", + " im_uint8 = im_uint8[:,:,0]\n", + " if len(im_uint8.shape)>2:\n", + " im_ycbcr = BGR2YCbCr(im_uint8)\n", + " im = im_ycbcr[:,:,0]\n", + " else:\n", + " im = im_uint8\n", + " im = modcrop(im,R)\n", + " im_LR = Prepare(im,patchSize,R) # Prepare the cheap-upscaling images (optional: JPEG compression)\n", + " im_GX,im_GY = np.gradient(im_LR) # Calculate the gradient images\n", + " quantization, patchNumber = QuantizationProcess (im_GX, im_GY,patchSize, patchNumber, w, quantization) # get the strength and coherence of each patch\n", + " if (patchNumber > instance/2):\n", + " break\n", + "print('\\r done')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "# uniform quantization of patches, get the optimized strength and coherence boundaries\n", + "quantization = quantization [0:patchNumber,:]\n", + "quantization = np.sort(quantization,axis=0)\n", + "for i in range(Qstrength-1):\n", + " stre[i] = quantization[floor((i+1)*patchNumber/Qstrength),0]\n", + "for i in range(Qcoherence-1):\n", + " cohe[i] = quantization[floor((i+1)*patchNumber/Qcoherence),1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Begin to process images:\n", + " Processing 1/200 image (trainingData/157036.jpg)\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/anaconda3/lib/python3.7/site-packages/numba/compiler.py:588: NumbaPerformanceWarning: \u001b[1m\n", + "The keyword argument 'parallel=True' was specified but no transformation for parallel execution was possible.\n", + "\n", + "To find out why, try turning on parallel diagnostics, see http://numba.pydata.org/numba-doc/latest/user/parallel.html#diagnostics for help.\n", + "\u001b[1m\n", + "File \"Functions.py\", line 145:\u001b[0m\n", + "\u001b[1m@nb.jit(nopython=True, parallel=True)\n", + "\u001b[1mdef HashTable(patchX,patchY,weight, Qangle,Qstrength,Qcoherence,stre,cohe):\n", + "\u001b[0m\u001b[1m^\u001b[0m\u001b[0m\n", + "\u001b[0m\n", + " self.func_ir.loc))\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Processing 2/200 image (trainingData/187029.jpg)\n", + " Processing 3/200 image (trainingData/71046.jpg)\n", + " Processing 4/200 image (trainingData/299091.jpg)\n", + " Processing 5/200 image (trainingData/242078.jpg)\n", + " Processing 6/200 image (trainingData/232038.jpg)\n", + " Processing 7/200 image (trainingData/173036.jpg)\n", + " Processing 8/200 image (trainingData/198054.jpg)\n", + " Processing 9/200 image (trainingData/388016.jpg)\n", + " Processing 10/200 image (trainingData/292066.jpg)\n", + " Processing 11/200 image (trainingData/189011.jpg)\n", + " Processing 12/200 image (trainingData/59078.jpg)\n", + " Processing 13/200 image (trainingData/108041.jpg)\n", + " Processing 14/200 image (trainingData/66075.jpg)\n", + " Processing 15/200 image (trainingData/20008.jpg)\n", + " Processing 16/200 image (trainingData/370036.jpg)\n", + " Processing 17/200 image (trainingData/41025.jpg)\n", + " Processing 18/200 image (trainingData/207056.jpg)\n", + " Processing 19/200 image (trainingData/314016.jpg)\n", + " Processing 20/200 image (trainingData/188091.jpg)\n", + " Processing 21/200 image (trainingData/56028.jpg)\n", + " Processing 22/200 image (trainingData/134008.jpg)\n", + " Processing 23/200 image (trainingData/153093.jpg)\n", + " Processing 24/200 image (trainingData/54005.jpg)\n", + " Processing 25/200 image (trainingData/65019.jpg)\n", + " Processing 26/200 image (trainingData/176039.jpg)\n", + " Processing 27/200 image (trainingData/187003.jpg)\n", + " Processing 28/200 image (trainingData/61086.jpg)\n", + " Processing 29/200 image (trainingData/147021.jpg)\n", + " Processing 30/200 image (trainingData/353013.jpg)\n", + " Processing 31/200 image (trainingData/317080.jpg)\n", + " Processing 32/200 image (trainingData/28096.jpg)\n", + " Processing 33/200 image (trainingData/35010.jpg)\n", + " Processing 34/200 image (trainingData/151087.jpg)\n", + " Processing 35/200 image (trainingData/254033.jpg)\n", + " Processing 36/200 image (trainingData/189003.jpg)\n", + " Processing 37/200 image (trainingData/144067.jpg)\n", + " Processing 38/200 image (trainingData/33066.jpg)\n", + " Processing 39/200 image (trainingData/138032.jpg)\n", + " Processing 40/200 image (trainingData/15088.jpg)\n", + " Processing 41/200 image (trainingData/249061.jpg)\n", + " Processing 42/200 image (trainingData/68077.jpg)\n", + " Processing 43/200 image (trainingData/368078.jpg)\n", + " Processing 44/200 image (trainingData/187039.jpg)\n", + " Processing 45/200 image (trainingData/87065.jpg)\n", + " Processing 46/200 image (trainingData/216066.jpg)\n", + " Processing 47/200 image (trainingData/43083.jpg)\n", + " Processing 48/200 image (trainingData/372047.jpg)\n", + " Processing 49/200 image (trainingData/227046.jpg)\n", + " Processing 50/200 image (trainingData/15004.jpg)\n", + " Processing 51/200 image (trainingData/236017.jpg)\n", + " Processing 52/200 image (trainingData/310007.jpg)\n", + " Processing 53/200 image (trainingData/198023.jpg)\n", + " Processing 54/200 image (trainingData/22093.jpg)\n", + " Processing 55/200 image (trainingData/106025.jpg)\n", + " Processing 56/200 image (trainingData/202012.jpg)\n", + " Processing 57/200 image (trainingData/159045.jpg)\n", + " Processing 58/200 image (trainingData/376020.jpg)\n", + " Processing 59/200 image (trainingData/124084.jpg)\n", + " Processing 60/200 image (trainingData/254054.jpg)\n", + " Processing 61/200 image (trainingData/25098.jpg)\n", + " Processing 62/200 image (trainingData/8049.jpg)\n", + " Processing 63/200 image (trainingData/104022.jpg)\n", + " Processing 64/200 image (trainingData/238011.jpg)\n", + " Processing 65/200 image (trainingData/285036.jpg)\n", + " Processing 66/200 image (trainingData/65132.jpg)\n", + " Processing 67/200 image (trainingData/326038.jpg)\n", + " Processing 68/200 image (trainingData/22090.jpg)\n", + " Processing 69/200 image (trainingData/159091.jpg)\n", + " Processing 70/200 image (trainingData/76002.jpg)\n", + " Processing 71/200 image (trainingData/227040.jpg)\n", + " Processing 72/200 image (trainingData/145053.jpg)\n", + " Processing 73/200 image (trainingData/374020.jpg)\n", + " Processing 74/200 image (trainingData/46076.jpg)\n", + " Processing 75/200 image (trainingData/100080.jpg)\n", + " Processing 76/200 image (trainingData/113016.jpg)\n", + " Processing 77/200 image (trainingData/134052.jpg)\n", + " Processing 78/200 image (trainingData/311068.jpg)\n", + " Processing 79/200 image (trainingData/239096.jpg)\n", + " Processing 80/200 image (trainingData/187071.jpg)\n", + " Processing 81/200 image (trainingData/16052.jpg)\n", + " Processing 82/200 image (trainingData/94079.jpg)\n", + " Processing 83/200 image (trainingData/311081.jpg)\n", + " Processing 84/200 image (trainingData/118035.jpg)\n", + " Processing 85/200 image (trainingData/130034.jpg)\n", + " Processing 86/200 image (trainingData/138078.jpg)\n", + " Processing 87/200 image (trainingData/35070.jpg)\n", + " Processing 88/200 image (trainingData/35058.jpg)\n", + " Processing 89/200 image (trainingData/260081.jpg)\n", + " Processing 90/200 image (trainingData/246053.jpg)\n", + " Processing 91/200 image (trainingData/26031.jpg)\n", + " Processing 92/200 image (trainingData/67079.jpg)\n", + " Processing 93/200 image (trainingData/164074.jpg)\n", + " Processing 94/200 image (trainingData/95006.jpg)\n", + " Processing 95/200 image (trainingData/27059.jpg)\n", + " Processing 96/200 image (trainingData/66039.jpg)\n", + " Processing 97/200 image (trainingData/112082.jpg)\n", + " Processing 98/200 image (trainingData/140075.jpg)\n", + " Processing 99/200 image (trainingData/106020.jpg)\n", + " Processing 100/200 image (trainingData/97017.jpg)\n", + " Processing 101/200 image (trainingData/302003.jpg)\n", + " Processing 102/200 image (trainingData/118020.jpg)\n", + " Processing 103/200 image (trainingData/365073.jpg)\n", + " Processing 104/200 image (trainingData/178054.jpg)\n", + " Processing 105/200 image (trainingData/216053.jpg)\n", + " Processing 106/200 image (trainingData/268002.jpg)\n", + " Processing 107/200 image (trainingData/368016.jpg)\n", + " Processing 108/200 image (trainingData/117054.jpg)\n", + " Processing 109/200 image (trainingData/277095.jpg)\n", + " Processing 110/200 image (trainingData/274007.jpg)\n", + " Processing 111/200 image (trainingData/385028.jpg)\n", + " Processing 112/200 image (trainingData/48055.jpg)\n", + " Processing 113/200 image (trainingData/286092.jpg)\n", + " Processing 114/200 image (trainingData/23025.jpg)\n", + " Processing 115/200 image (trainingData/24004.jpg)\n", + " Processing 116/200 image (trainingData/323016.jpg)\n", + " Processing 117/200 image (trainingData/271008.jpg)\n", + " Processing 118/200 image (trainingData/376001.jpg)\n", + " Processing 119/200 image (trainingData/187083.jpg)\n", + " Processing 120/200 image (trainingData/161062.jpg)\n", + " Processing 121/200 image (trainingData/188005.jpg)\n", + " Processing 122/200 image (trainingData/100098.jpg)\n", + " Processing 123/200 image (trainingData/135037.jpg)\n", + " Processing 124/200 image (trainingData/309004.jpg)\n", + " Processing 125/200 image (trainingData/169012.jpg)\n", + " Processing 126/200 image (trainingData/231015.jpg)\n", + " Processing 127/200 image (trainingData/166081.jpg)\n", + " Processing 128/200 image (trainingData/271031.jpg)\n", + " Processing 129/200 image (trainingData/216041.jpg)\n", + " Processing 130/200 image (trainingData/181018.jpg)\n", + " Processing 131/200 image (trainingData/163062.jpg)\n", + " Processing 132/200 image (trainingData/35091.jpg)\n", + " Processing 133/200 image (trainingData/198004.jpg)\n", + " Processing 134/200 image (trainingData/196015.jpg)\n", + " Processing 135/200 image (trainingData/172032.jpg)\n", + " Processing 136/200 image (trainingData/12003.jpg)\n", + " Processing 137/200 image (trainingData/147062.jpg)\n", + " Processing 138/200 image (trainingData/105053.jpg)\n", + " Processing 139/200 image (trainingData/43070.jpg)\n", + " Processing 140/200 image (trainingData/65074.jpg)\n", + " Processing 141/200 image (trainingData/78019.jpg)\n", + " Processing 142/200 image (trainingData/140055.jpg)\n", + " Processing 143/200 image (trainingData/100075.jpg)\n", + " Processing 144/200 image (trainingData/113009.jpg)\n", + " Processing 145/200 image (trainingData/155060.jpg)\n", + " Processing 146/200 image (trainingData/60079.jpg)\n", + " Processing 147/200 image (trainingData/23084.jpg)\n", + " Processing 148/200 image (trainingData/249087.jpg)\n", + " Processing 149/200 image (trainingData/183087.jpg)\n", + " Processing 150/200 image (trainingData/45077.jpg)\n", + " Processing 151/200 image (trainingData/22013.jpg)\n", + " Processing 152/200 image (trainingData/209070.jpg)\n", + " Processing 153/200 image (trainingData/55067.jpg)\n", + " Processing 154/200 image (trainingData/245051.jpg)\n", + " Processing 155/200 image (trainingData/239007.jpg)\n", + " Processing 156/200 image (trainingData/176019.jpg)\n", + " Processing 157/200 image (trainingData/8143.jpg)\n", + " Processing 158/200 image (trainingData/103041.jpg)\n", + " Processing 159/200 image (trainingData/145014.jpg)\n", + " Processing 160/200 image (trainingData/113044.jpg)\n", + " Processing 161/200 image (trainingData/374067.jpg)\n", + " Processing 162/200 image (trainingData/41004.jpg)\n", + " Processing 163/200 image (trainingData/109034.jpg)\n", + " Processing 164/200 image (trainingData/35008.jpg)\n", + " Processing 165/200 image (trainingData/246016.jpg)\n", + " Processing 166/200 image (trainingData/135069.jpg)\n", + " Processing 167/200 image (trainingData/225017.jpg)\n", + " Processing 168/200 image (trainingData/361084.jpg)\n", + " Processing 169/200 image (trainingData/61060.jpg)\n", + " Processing 170/200 image (trainingData/253036.jpg)\n", + " Processing 171/200 image (trainingData/65010.jpg)\n", + " Processing 172/200 image (trainingData/105019.jpg)\n", + " Processing 173/200 image (trainingData/90076.jpg)\n", + " Processing 174/200 image (trainingData/42078.jpg)\n", + " Processing 175/200 image (trainingData/42044.jpg)\n", + " Processing 176/200 image (trainingData/156079.jpg)\n", + " Processing 177/200 image (trainingData/188063.jpg)\n", + " Processing 178/200 image (trainingData/126039.jpg)\n", + " Processing 179/200 image (trainingData/28075.jpg)\n", + " Processing 180/200 image (trainingData/55075.jpg)\n", + " Processing 181/200 image (trainingData/122048.jpg)\n", + " Processing 182/200 image (trainingData/163014.jpg)\n", + " Processing 183/200 image (trainingData/181091.jpg)\n", + " Processing 184/200 image (trainingData/170054.jpg)\n", + " Processing 185/200 image (trainingData/301007.jpg)\n", + " Processing 186/200 image (trainingData/12074.jpg)\n", + " Processing 187/200 image (trainingData/247085.jpg)\n", + " Processing 188/200 image (trainingData/293029.jpg)\n", + " Processing 189/200 image (trainingData/176035.jpg)\n", + " Processing 190/200 image (trainingData/80099.jpg)\n", + " Processing 191/200 image (trainingData/159029.jpg)\n", + " Processing 192/200 image (trainingData/24063.jpg)\n", + " Processing 193/200 image (trainingData/183055.jpg)\n", + " Processing 194/200 image (trainingData/2092.jpg)\n", + " Processing 195/200 image (trainingData/181079.jpg)\n", + " Processing 196/200 image (trainingData/92059.jpg)\n", + " Processing 197/200 image (trainingData/108073.jpg)\n", + " Processing 198/200 image (trainingData/153077.jpg)\n", + " Processing 199/200 image (trainingData/23080.jpg)\n", + " Processing 200/200 image (trainingData/365025.jpg)\n", + "9785.323970079422\n" + ] + } + ], + "source": [ + "print('Begin to process images:')\n", + "start = time.time()\n", + "imagecount = 1\n", + "for image in filelist:\n", + " print('\\r', end='')\n", + " print('' * 60, end='')\n", + " print('\\r Processing ' + str(imagecount) +'/' + str(len(filelist))+ ' image (' + image + ')')\n", + " \n", + " im_uint8 = cv2.imread(image)\n", + " if is_greyimage(im_uint8):\n", + " im_uint8 = im_uint8[:,:,0]\n", + " if len(im_uint8.shape)>2:\n", + " im_ycbcr = BGR2YCbCr(im_uint8)\n", + " im = im_ycbcr[:,:,0]\n", + " else:\n", + " im = im_uint8\n", + " im = modcrop(im,R)\n", + " im_LR = Prepare(im,patchSize,R)\n", + " im_HR = im2double(im)\n", + " #im_HR = Dog1(im_HR) # optional: sharpen the image\n", + " im_GX,im_GY = np.gradient(im_LR)\n", + " Q, V, mark = TrainProcessSMC(im_LR, im_HR, im_GX, im_GY,patchSize, w, Qangle, Qstrength,Qcoherence, stre, cohe, R, Q, V, mark) # get Q, V of each patch\n", + " imagecount += 1\n", + "end = time.time()\n", + "print(end - start)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Using patch symmetry for nearly 8* more learning examples: \n" + ] + } + ], + "source": [ + "# optional: Using patch symmetry for nearly 8* more learning examples\n", + "print('\\r', end='')\n", + "print(' ' * 60, end='')\n", + "print('\\r Using patch symmetry for nearly 8* more learning examples:')\n", + "for i in range(Qangle):\n", + " for j in range(Qstrength*Qcoherence):\n", + " for r in range(R*R):\n", + " for t in range(1,8):\n", + " t1 = t % 4\n", + " t2 = floor(t / 4)\n", + " Q1 = Getfromsymmetry1(Q[r, i * Qstrength * Qcoherence + j], patchSize, t1, t2) # Rotate 90*t1 degree or flip t2\n", + " V1 = Getfromsymmetry2(V[r, i * Qstrength * Qcoherence + j], patchSize, t1, t2)\n", + " i1 = Qangle*t1/2 + i\n", + " i1 = np.int(i1)\n", + " if t2 == 1:\n", + " i1 = Qangle -1 - i1\n", + " while i1 >= Qangle:\n", + " i1 = i1 - Qangle\n", + " while i1 < 0:\n", + " i1 = i1 + Qangle\n", + " Q[r, i1 * Qstrength * Qcoherence + j] += Q1\n", + " V[r, i1 * Qstrength * Qcoherence + j] += V1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Concurrent trainning mode" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "def ConcurenrtTrainprocessSMC(i):\n", + " if (i < iteration - 1):\n", + " offset_i = offset[i * batch:i * batch + batch]\n", + " offset2_i = offset2[i * batch:i * batch + batch]\n", + " grid = np.tile(gridon[..., None], [1, 1, batch]) + np.tile(offset_i, [patchSize, patchSize, 1])\n", + " else:\n", + " offset_i = offset[i * batch:im.size]\n", + " offset2_i = offset2[i * batch:im.size]\n", + " grid = np.tile(gridon[..., None], [1, 1, im.size - (iteration - 1) * batch]) + np.tile(offset_i,[patchSize, patchSize,1])\n", + " f = im_LR.ravel()[grid]\n", + " gx = im_GX.ravel()[grid]\n", + " gy = im_GY.ravel()[grid]\n", + " gx = gx.reshape((1, patchSize * patchSize, gx.shape[2]))\n", + " gy = gy.reshape((1, patchSize * patchSize, gy.shape[2]))\n", + " G = np.vstack((gx, gy))\n", + " g1 = np.transpose(G, (2, 0, 1))\n", + " g2 = np.transpose(G, (2, 1, 0))\n", + " x = Gaussian_Mul(g1, g2, wGaussian)\n", + " w, v = np.linalg.eig(x)\n", + " idx = (-w).argsort()\n", + " w = w[np.arange(np.shape(w)[0])[:, np.newaxis], idx]\n", + " v = v[np.arange(np.shape(v)[0])[:, np.newaxis, np.newaxis], np.arange(np.shape(v)[1])[np.newaxis, :, np.newaxis], idx[:,np.newaxis,:]]\n", + " thelta = np.arctan(v[:, 1, 0] / v[:, 0, 0])\n", + " thelta[thelta < 0] = thelta[thelta < 0] + pi\n", + " thelta = np.floor(thelta / (pi / Qangle))\n", + " thelta[thelta > Qangle - 1] = Qangle - 1\n", + " thelta[thelta < 0] = 0\n", + " lamda = w[:, 0]\n", + " u = (np.sqrt(w[:, 0]) - np.sqrt(w[:, 1])) / (np.sqrt(w[:, 0]) + np.sqrt(w[:, 1]) + 0.00000000000000001)\n", + " lamda = np.searchsorted(stre, lamda)\n", + " u = np.searchsorted(cohe, u)\n", + " j = thelta * Qstrength * Qcoherence + lamda * Qcoherence + u\n", + " j = j.astype('int')\n", + " \n", + " f_vec = np.reshape(f, (patchSize * patchSize, -1)) - mean\n", + " f_vec_reduced = np.dot(pca_matrix, f_vec)\n", + " t = kmeans.predict(f_vec_reduced.reshape(-1, 1))\n", + " \n", + " f = f.reshape(-1, patchSize*patchSize)\n", + " A = np.dot(f.T, f)\n", + " \n", + " Ql = np.zeros((R*R, Qangle*Qstrength*Qcoherence, patchSize*patchSize, patchSize*patchSize)) # Eq.4\n", + " Vl = np.zeros((R*R, Qangle*Qstrength*Qcoherence, patchSize*patchSize)) # Eq.5\n", + " \n", + " Ql[t,j] += A\n", + " im_HR_f = im_HR.ravel()[grid].reshape(patchSize*patchSize, -1)\n", + " b1 = f.T * im_HR_f\n", + " b = b1.reshape(-1, patchSize*patchSize)\n", + " Vl[t,j] += b\n", + "# mark[t,j] = mark[t,j]+1\n", + " \n", + " return Ql, Vl" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Begin to process images:\n", + " Processing 1/4 image (trainingDataSmall/153093.jpg)\n", + "Con out\n", + "29.007375955581665\n", + " Processing 2/4 image (trainingDataSmall/169012.jpg)\n", + "Con out\n", + "48.211426734924316\n", + " Processing 3/4 image (trainingDataSmall/176019.jpg)\n", + "Con out\n", + "44.54947304725647\n", + " Processing 4/4 image (trainingDataSmall/181079.jpg)\n", + "Con out\n", + "39.375470876693726\n" + ] + } + ], + "source": [ + "# 并发方式\n", + "warnings.filterwarnings('ignore')\n", + "print('Begin to process images:')\n", + "imagecount = 1\n", + "wGaussian = Gaussian2d([patchSize, patchSize], 2)\n", + "wGaussian = wGaussian/wGaussian.max()\n", + "wGaussian = np.diag(wGaussian.ravel())\n", + "for image in filelist:\n", + " print('\\r', end='')\n", + " print('' * 60, end='')\n", + " print('\\r Processing ' + str(imagecount) +'/' + str(len(filelist))+ ' image (' + image + ')')\n", + " start = time.time()\n", + " im_uint8 = cv2.imread(image)\n", + " if is_greyimage(im_uint8):\n", + " im_uint8 = im_uint8[:,:,0]\n", + " if len(im_uint8.shape)>2:\n", + " im_ycbcr = BGR2YCbCr(im_uint8)\n", + " im = im_ycbcr[:,:,0]\n", + " else:\n", + " im = im_uint8\n", + " im = modcrop(im,R)\n", + " H, W = im.shape\n", + " im_LR = Prepare(im,patchSize,R)\n", + " im_HR = im2double(im)\n", + " #im_HR = Dog1(im_HR) # optional: sharpen the image\n", + " im_GX,im_GY = np.gradient(im_LR)\n", + " index = np.array(range(im_LR.size)).reshape(im_LR.shape)\n", + " offset = np.array(index[0:H, 0:W].ravel())\n", + " offset2 = np.array(range(im.size))\n", + " gridon = index[0:patchSize, 0:patchSize]\n", + " batch = 2000\n", + " iteration = ceil(im.size / batch + 0.000000000000001)\n", + " i = range(iteration - 5)\n", + " p = Pool()\n", + " ret = p.map(ConcurenrtTrainprocessSMC, i)\n", + " print('Con out')\n", + " \n", + " for i in range(iteration - 5):\n", + " Q += np.array(ret[i][0])\n", + " V += np.array(ret[i][1])\n", + " end = time.time()\n", + " print(end - start)\n", + " \n", + "# Q, V, mark = TrainProcessSMC(im_LR, im_HR, im_GX, im_GY,patchSize, w, Qangle, Qstrength,Qcoherence, stre, cohe, R, Q, V, mark) # get Q, V of each patch\n", + " imagecount += 1" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(4, 216, 121)" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# np.sum(kmeans.labels_==0)/kmeans.labels_.shape[0]\n", + "array = np.array(ret[5][1])\n", + "array.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Get the filter of RAISR:\n", + "Type: 0\n", + "Type: 1\n", + "Type: 2\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/anaconda3/lib/python3.7/site-packages/numpy/linalg/linalg.py:2093: RuntimeWarning: overflow encountered in det\n", + " r = _umath_linalg.det(a, signature=signature)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Type: 3\n", + "Type: 4\n", + "Type: 5\n", + "Type: 6\n", + "Type: 7\n", + "Type: 8\n", + "Saving...\n", + "Finished. \n" + ] + } + ], + "source": [ + "print('Get the filter of RAISR:')\n", + "for t in range(R*R):\n", + " print('\\rType: '+str(t))\n", + " for j in range(Qangle*Qstrength*Qcoherence):\n", + " while(True):\n", + " if(Q[t,j].sum()<100):\n", + " break\n", + " if(np.linalg.det(Q[t,j])<1):\n", + " Q[t,j] = Q[t,j] + np.eye(patchSize*patchSize)* Q[t,j].sum()*0.000000005\n", + " else:\n", + " h[t,j] = np.linalg.inv(Q[t,j]).dot(V[t,j]) # Eq.2\n", + " break\n", + "\n", + " \n", + "print('Saving...')\n", + "with open(\"Filters/Ckmeans_filter\"+str(R), \"wb\") as fp:\n", + " pickle.dump(h, fp)\n", + "\n", + "with open(\"Filters/Ckmeans_Qfactor_str\"+str(R), \"wb\") as sp:\n", + " pickle.dump(stre, sp)\n", + "\n", + "with open(\"Filters/Ckmeans_Qfactor_coh\"+str(R), \"wb\") as cp:\n", + " pickle.dump(cohe, cp)\n", + "\n", + "\n", + "print('\\r', end='')\n", + "print(' ' * 60, end='')\n", + "print('\\rFinished.')" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[[ 5648835.38434242 5645236.33128634 5641376.31066372 ...\n", + " 5629358.96675032 5630151.76793448 5631359.79393983]\n", + " [ 5645236.33128634 5644013.02109747 5641364.44573461 ...\n", + " 5628141.33210211 5628947.74678882 5630149.81537777]\n", + " [ 5641376.31066372 5641364.44573461 5640792.19197018 ...\n", + " 5627323.07909169 5628139.89117938 5629355.54729626]\n", + " ...\n", + " [ 5629358.96675032 5628141.33210211 5627323.07909169 ...\n", + " 5640839.31861377 5641410.05646895 5641419.83261681]\n", + " [ 5630151.76793448 5628947.74678882 5628139.89117938 ...\n", + " 5641410.05646895 5644056.86643388 5645277.84693416]\n", + " [ 5631359.79393983 5630149.81537777 5629355.54729626 ...\n", + " 5641419.83261681 5645277.84693416 5648873.91452312]]\n", + "\n", + " [[ 6749254.57499163 6744915.3770526 6740762.77107051 ...\n", + " 6716581.3056967 6717849.39753831 6719915.38772665]\n", + " [ 6744915.3770526 6742929.31942837 6739987.28468809 ...\n", + " 6714546.41379353 6715804.60273629 6717847.42343604]\n", + " [ 6740762.77107051 6739987.28468809 6739067.2193592 ...\n", + " 6713288.71449331 6714542.38254401 6716575.29533145]\n", + " ...\n", + " [ 6716581.3056967 6714546.41379353 6713288.71449331 ...\n", + " 6739102.7197975 6740018.90168156 6740792.63581484]\n", + " [ 6717849.39753831 6715804.60273629 6714542.38254401 ...\n", + " 6740018.90168156 6742956.75639876 6744940.87063199]\n", + " [ 6719915.38772665 6717847.42343604 6716575.29533145 ...\n", + " 6740792.63581484 6744940.87063199 6749277.65405353]]\n", + "\n", + " [[ 4946738.40964097 4943946.5177996 4941527.37620801 ...\n", + " 4899971.64716614 4900970.40836569 4902536.68811961]\n", + " [ 4943946.5177996 4942257.00110581 4940363.12462773 ...\n", + " 4898407.659669 4899403.76916535 4900967.93963828]\n", + " [ 4941527.37620801 4940363.12462773 4939387.31289355 ...\n", + " 4897407.55552443 4898406.62020725 4899968.15553985]\n", + " ...\n", + " [ 4899971.64716614 4898407.659669 4897407.55552443 ...\n", + " 4939174.88868747 4940149.82214407 4941311.78597348]\n", + " [ 4900970.40836569 4899403.76916535 4898406.62020725 ...\n", + " 4940149.82214407 4942042.61832996 4943729.65010256]\n", + " [ 4902536.68811961 4900967.93963828 4899968.15553985 ...\n", + " 4941311.78597348 4943729.65010256 4946518.6744622 ]]\n", + "\n", + " ...\n", + "\n", + " [[ 1073381.25204147 1058976.87301806 1035595.6502422 ...\n", + " 954280.028589 959273.90920415 964451.26437524]\n", + " [ 1058976.87301806 1061132.44521332 1047570.09504035 ...\n", + " 952213.49865436 955501.19329488 959273.90920415]\n", + " [ 1035595.6502422 1047570.09504035 1050500.28482885 ...\n", + " 949300.94892733 952213.49865436 954280.028589 ]\n", + " ...\n", + " [ 954280.028589 952213.49865436 949300.94892733 ...\n", + " 1050500.28482885 1047570.09504035 1035595.6502422 ]\n", + " [ 959273.90920415 955501.19329488 952213.49865436 ...\n", + " 1047570.09504035 1061132.44521332 1058976.87301806]\n", + " [ 964451.26437524 959273.90920415 954280.028589 ...\n", + " 1035595.6502422 1058976.87301806 1073381.25204147]]\n", + "\n", + " [[ 1999359.91737001 1987816.4159476 1970377.03240285 ...\n", + " 1780358.5968781 1776816.59212607 1779329.50843517]\n", + " [ 1987816.4159476 1997043.91776988 1992945.08249124 ...\n", + " 1777330.89185694 1773910.65836213 1776816.59212607]\n", + " [ 1970377.03240285 1992945.08249124 2009554.24481332 ...\n", + " 1780689.66403686 1777330.89185694 1780358.5968781 ]\n", + " ...\n", + " [ 1780358.5968781 1777330.89185694 1780689.66403686 ...\n", + " 2009554.24481332 1992945.08249124 1970377.03240285]\n", + " [ 1776816.59212607 1773910.65836213 1777330.89185694 ...\n", + " 1992945.08249124 1997043.91776988 1987816.4159476 ]\n", + " [ 1779329.50843517 1776816.59212607 1780358.5968781 ...\n", + " 1970377.03240285 1987816.4159476 1999359.91737001]]\n", + "\n", + " [[ 5597134.22154396 5601397.06217617 5597423.56553633 ...\n", + " 4614980.17373315 4607172.87806221 4604668.19223371]\n", + " [ 5601397.06217617 5630280.2556385 5642192.52792011 ...\n", + " 4617124.15304889 4609404.44355245 4607172.87806221]\n", + " [ 5597423.56553633 5642192.52792011 5676589.4693255 ...\n", + " 4624848.48347559 4617124.15304889 4614980.17373315]\n", + " ...\n", + " [ 4614980.17373315 4617124.15304889 4624848.48347559 ...\n", + " 5676589.4693255 5642192.52792011 5597423.56553633]\n", + " [ 4607172.87806221 4609404.44355245 4617124.15304889 ...\n", + " 5642192.52792011 5630280.2556385 5601397.06217617]\n", + " [ 4604668.19223371 4607172.87806221 4614980.17373315 ...\n", + " 5597423.56553633 5601397.06217617 5597134.22154396]]]\n", + "\n", + "\n", + " [[[13735047.88842616 13736969.44698069 13736927.02314381 ...\n", + " 13726172.51118699 13723624.5321328 13719598.16982594]\n", + " [13736969.44698069 13741074.40258229 13742055.59052548 ...\n", + " 13730223.92868797 13727667.85616194 13723624.60196747]\n", + " [13736927.02314381 13742055.59052548 13744844.32641154 ...\n", + " 13732797.04939535 13730223.76658109 13726172.42225197]\n", + " ...\n", + " [13726172.51118699 13730223.92868797 13732797.04939535 ...\n", + " 13744724.1323631 13741935.04988726 13736806.7308716 ]\n", + " [13723624.5321328 13727667.85616194 13730223.76658109 ...\n", + " 13741935.04988726 13740953.10468148 13736848.12196723]\n", + " [13719598.16982594 13723624.60196747 13726172.42225197 ...\n", + " 13736806.7308716 13736848.12196723 13734925.93097902]]\n", + "\n", + " [[15618034.95784331 15620350.05509955 15620582.50895622 ...\n", + " 15598513.09105592 15595916.7786068 15591636.41360863]\n", + " [15620350.05509955 15624633.4490852 15625802.6210357 ...\n", + " 15602800.10071388 15600210.54926449 15595920.42758797]\n", + " [15620582.50895622 15625802.6210357 15628665.52973107 ...\n", + " 15605387.74860319 15602803.11843015 15598519.76967184]\n", + " ...\n", + " [15598513.09105592 15602800.10071388 15605387.74860319 ...\n", + " 15628475.35939658 15625615.26122024 15620399.04908694]\n", + " [15595916.7786068 15600210.54926449 15602803.11843015 ...\n", + " 15625615.26122024 15624448.09754349 15620167.99739867]\n", + " [15591636.41360863 15595920.42758797 15598519.76967184 ...\n", + " 15620399.04908694 15620167.99739867 15617855.03393712]]\n", + "\n", + " [[11295099.526227 11296585.50240576 11297279.82589691 ...\n", + " 11254697.69279476 11252722.22658947 11250103.56086085]\n", + " [11296585.50240576 11299039.14137498 11300167.31813808 ...\n", + " 11257329.12945758 11255353.49210274 11252727.73957679]\n", + " [11297279.82589691 11300167.31813808 11302109.49568477 ...\n", + " 11259310.35337134 11257333.36119922 11254707.44633571]\n", + " ...\n", + " [11254697.69279476 11257329.12945758 11259310.35337134 ...\n", + " 11302290.16551945 11300352.41656176 11297470.70397457]\n", + " [11252722.22658947 11255353.49210274 11257333.36119922 ...\n", + " 11300352.41656176 11299228.22958721 11296780.01694632]\n", + " [11250103.56086085 11252727.73957679 11254707.44633571 ...\n", + " 11297470.70397457 11296780.01694632 11295298.80787252]]\n", + "\n", + " ...\n", + "\n", + " [[ 1983586.69191855 1978635.41050362 1962621.87318722 ...\n", + " 1857101.14060745 1853696.79287965 1849760.07809303]\n", + " [ 1978635.41050362 1990172.66628225 1984389.05299497 ...\n", + " 1861030.53553248 1857606.78086888 1853696.79287965]\n", + " [ 1962621.87318722 1984389.05299497 1995317.63480206 ...\n", + " 1864397.97179546 1861030.53553248 1857101.14060745]\n", + " ...\n", + " [ 1857101.14060745 1861030.53553248 1864397.97179546 ...\n", + " 1995317.63480206 1984389.05299497 1962621.87318722]\n", + " [ 1853696.79287965 1857606.78086888 1861030.53553248 ...\n", + " 1984389.05299497 1990172.66628225 1978635.41050362]\n", + " [ 1849760.07809303 1853696.79287965 1857101.14060745 ...\n", + " 1962621.87318722 1978635.41050362 1983586.69191855]]\n", + "\n", + " [[ 4145552.20625889 4140933.95523242 4121715.61926943 ...\n", + " 3861102.20046133 3853274.65783923 3846127.85488652]\n", + " [ 4140933.95523242 4162287.7916645 4159620.5518337 ...\n", + " 3867291.39901573 3859858.11149554 3853274.65783923]\n", + " [ 4121715.61926943 4159620.5518337 4182785.60911929 ...\n", + " 3874541.2175317 3867291.39901573 3861102.20046133]\n", + " ...\n", + " [ 3861102.20046133 3867291.39901573 3874541.2175317 ...\n", + " 4182785.60911929 4159620.5518337 4121715.61926943]\n", + " [ 3853274.65783923 3859858.11149554 3867291.39901573 ...\n", + " 4159620.5518337 4162287.7916645 4140933.95523242]\n", + " [ 3846127.85488652 3853274.65783923 3861102.20046133 ...\n", + " 4121715.61926943 4140933.95523242 4145552.20625889]]\n", + "\n", + " [[12371248.56223731 12378991.74004081 12365524.7570029 ...\n", + " 11035492.29493285 11025672.6807691 11014462.38222232]\n", + " [12378991.74004081 12420159.57753924 12428008.05857988 ...\n", + " 11045526.90042296 11036273.95552499 11025672.6807691 ]\n", + " [12365524.7570029 12428008.05857988 12466145.59021132 ...\n", + " 11054521.18588263 11045526.90042296 11035492.29493285]\n", + " ...\n", + " [11035492.29493285 11045526.90042296 11054521.18588263 ...\n", + " 12466145.59021132 12428008.05857988 12365524.7570029 ]\n", + " [11025672.6807691 11036273.95552499 11045526.90042296 ...\n", + " 12428008.05857988 12420159.57753924 12378991.74004081]\n", + " [11014462.38222232 11025672.6807691 11035492.29493285 ...\n", + " 12365524.7570029 12378991.74004081 12371248.56223731]]]\n", + "\n", + "\n", + " [[[17087175.0150845 17093420.07052512 17096723.7824515 ...\n", + " 17091291.99509291 17086466.2268807 17078785.98784958]\n", + " [17093420.07052512 17100931.61562281 17104824.67090956 ...\n", + " 17098978.64504295 17094156.50077535 17086470.68538128]\n", + " [17096723.7824515 17104824.67090956 17109666.32056706 ...\n", + " 17103794.83149428 17098980.61576191 17091298.40212097]\n", + " ...\n", + " [17091291.99509291 17098978.64504295 17103794.83149428 ...\n", + " 17109620.01580735 17104780.22298953 17096683.65462374]\n", + " [17086466.2268807 17094156.50077535 17098980.61576191 ...\n", + " 17104780.22298953 17100888.58026718 17093381.04395073]\n", + " [17078785.98784958 17086470.68538128 17091298.40212097 ...\n", + " 17096683.65462374 17093381.04395073 17087139.4409361 ]]\n", + "\n", + " [[17990104.05140928 17996824.3328092 17999279.78262109 ...\n", + " 17986722.29659286 17982630.52854995 17974326.97413252]\n", + " [17996824.3328092 18004990.31340092 18008119.13485466 ...\n", + " 17995036.68507419 17990942.87806146 17982633.3198456 ]\n", + " [17999279.78262109 18008119.13485466 18012332.95441595 ...\n", + " 17999133.04539724 17995034.27257131 17986722.68387467]\n", + " ...\n", + " [17986722.29659286 17995036.68507419 17999133.04539724 ...\n", + " 18012366.02992538 18008149.79981429 17999313.2063658 ]\n", + " [17982630.52854995 17990942.87806146 17995034.27257131 ...\n", + " 18008149.79981429 18005017.93697646 17996854.3452967 ]\n", + " [17974326.97413252 17982633.3198456 17986722.68387467 ...\n", + " 17999313.2063658 17996854.3452967 17990135.57809902]]\n", + "\n", + " [[17964546.16761065 17969705.53253216 17972524.61522351 ...\n", + " 17941450.56698116 17937497.02002231 17931221.18694265]\n", + " [17969705.53253216 17975720.91603044 17978913.1756847 ...\n", + " 17947745.69902268 17943786.06683505 17937505.45942254]\n", + " [17972524.61522351 17978913.1756847 17982745.89425419 ...\n", + " 17951712.88364407 17947749.02895732 17941462.32592003]\n", + " ...\n", + " [17941450.56698116 17947745.69902268 17951712.88364407 ...\n", + " 17983561.03360059 17979731.6081799 17973351.30535807]\n", + " [17937497.02002231 17943786.06683505 17947749.02895732 ...\n", + " 17979731.6081799 17976542.35293932 17970534.98863366]\n", + " [17931221.18694265 17937505.45942254 17941462.32592003 ...\n", + " 17973351.30535807 17970534.98863366 17965383.09353144]]\n", + "\n", + " ...\n", + "\n", + " [[ 1507963.70674358 1513408.82688197 1511635.64267589 ...\n", + " 1464932.30277585 1458135.84452134 1448071.6721261 ]\n", + " [ 1513408.82688197 1526049.73811613 1528666.64836602 ...\n", + " 1474886.50363707 1468154.39298732 1458135.84452134]\n", + " [ 1511635.64267589 1528666.64836602 1538218.84636681 ...\n", + " 1481500.78655901 1474886.50363707 1464932.30277585]\n", + " ...\n", + " [ 1464932.30277585 1474886.50363707 1481500.78655901 ...\n", + " 1538218.84636681 1528666.64836602 1511635.64267589]\n", + " [ 1458135.84452134 1468154.39298732 1474886.50363707 ...\n", + " 1528666.64836602 1526049.73811613 1513408.82688197]\n", + " [ 1448071.6721261 1458135.84452134 1464932.30277585 ...\n", + " 1511635.64267589 1513408.82688197 1507963.70674358]]\n", + "\n", + " [[ 3010242.01608612 3012779.06071507 3002675.34156091 ...\n", + " 2886222.68075353 2883915.62821989 2875607.50363704]\n", + " [ 3012779.06071507 3026690.67186467 3023836.55083427 ...\n", + " 2894110.57148787 2892053.54755861 2883915.62821989]\n", + " [ 3002675.34156091 3023836.55083427 3032058.78265283 ...\n", + " 2895975.39903111 2894110.57148787 2886222.68075353]\n", + " ...\n", + " [ 2886222.68075353 2894110.57148787 2895975.39903111 ...\n", + " 3032058.78265283 3023836.55083427 3002675.34156091]\n", + " [ 2883915.62821989 2892053.54755861 2894110.57148787 ...\n", + " 3023836.55083427 3026690.67186467 3012779.06071507]\n", + " [ 2875607.50363704 2883915.62821989 2886222.68075353 ...\n", + " 3002675.34156091 3012779.06071507 3010242.01608612]]\n", + "\n", + " [[ 8057843.17679306 8054081.7581546 8033167.52270673 ...\n", + " 7434938.52550533 7447893.13276406 7451580.89870027]\n", + " [ 8054081.7581546 8065144.94940358 8053782.47232607 ...\n", + " 7430957.4172855 7444062.31169526 7447893.13276406]\n", + " [ 8033167.52270673 8053782.47232607 8055610.93660852 ...\n", + " 7417681.10000749 7430957.4172855 7434938.52550533]\n", + " ...\n", + " [ 7434938.52550533 7430957.4172855 7417681.10000749 ...\n", + " 8055610.93660852 8053782.47232607 8033167.52270673]\n", + " [ 7447893.13276406 7444062.31169526 7430957.4172855 ...\n", + " 8053782.47232607 8065144.94940358 8054081.7581546 ]\n", + " [ 7451580.89870027 7447893.13276406 7434938.52550533 ...\n", + " 8033167.52270673 8054081.7581546 8057843.17679306]]]\n", + "\n", + "\n", + " [[[ 1361288.3068818 1356308.48095335 1351904.69560929 ...\n", + " 1344403.55401763 1346413.04016911 1349430.58560549]\n", + " [ 1356308.48095335 1353229.39269494 1349762.85256426 ...\n", + " 1341433.46291419 1343427.34271428 1346414.68361394]\n", + " [ 1351904.69560929 1349762.85256426 1347871.38045348 ...\n", + " 1339449.80742784 1341434.3534486 1344406.0648673 ]\n", + " ...\n", + " [ 1344403.55401763 1341433.46291419 1339449.80742784 ...\n", + " 1347881.4137945 1349773.60641278 1351917.24229133]\n", + " [ 1346413.04016911 1343427.34271428 1341434.3534486 ...\n", + " 1349773.60641278 1353240.88911939 1356321.8405535 ]\n", + " [ 1349430.58560549 1346414.68361394 1344406.0648673 ...\n", + " 1351917.24229133 1356321.8405535 1361303.32993447]]\n", + "\n", + " [[ 1329092.4544252 1324341.0286351 1320452.97205686 ...\n", + " 1306671.79500185 1308281.96481346 1311066.53450206]\n", + " [ 1324341.0286351 1321443.93822372 1318522.14220677 ...\n", + " 1303936.92785846 1305525.96907337 1308282.20668966]\n", + " [ 1320452.97205686 1318522.14220677 1317161.2946712 ...\n", + " 1302354.46191459 1303938.01134942 1306673.13381 ]\n", + " ...\n", + " [ 1306671.79500185 1303936.92785846 1302354.46191459 ...\n", + " 1317180.05945397 1318541.81130327 1320472.59875428]\n", + " [ 1308281.96481346 1305525.96907337 1303938.01134942 ...\n", + " 1318541.81130327 1321464.21737789 1324360.99560165]\n", + " [ 1311066.53450206 1308282.20668966 1306673.13381 ...\n", + " 1320472.59875428 1324360.99560165 1329111.60882736]]\n", + "\n", + " [[ 1182715.17476341 1179632.65437899 1176958.88143014 ...\n", + " 1150464.45219531 1151752.83100346 1153572.62343714]\n", + " [ 1179632.65437899 1177558.23689336 1175410.11916945 ...\n", + " 1148651.30934257 1149937.17544022 1151750.95844675]\n", + " [ 1176958.88143014 1175410.11916945 1174085.0829987 ...\n", + " 1147364.71963092 1148649.87146483 1150461.12716648]\n", + " ...\n", + " [ 1150464.45219531 1148651.30934257 1147364.71963092 ...\n", + " 1174001.34997294 1175325.006136 1176872.00110719]\n", + " [ 1151752.83100346 1149937.17544022 1148649.87146483 ...\n", + " 1175325.006136 1177471.45459424 1179543.8814455 ]\n", + " [ 1153572.62343714 1151750.95844675 1150461.12716648 ...\n", + " 1176872.00110719 1179543.8814455 1182623.96039971]]\n", + "\n", + " ...\n", + "\n", + " [[ 80841.90165321 79092.90448289 76977.49579393 ...\n", + " 66569.29763937 66644.37928489 67317.93144175]\n", + " [ 79092.90448289 79155.58139177 78203.36090734 ...\n", + " 65888.95650903 65983.17656286 66644.37928489]\n", + " [ 76977.49579393 78203.36090734 79072.50426759 ...\n", + " 65768.81645521 65888.95650903 66569.29763937]\n", + " ...\n", + " [ 66569.29763937 65888.95650903 65768.81645521 ...\n", + " 79072.50426759 78203.36090734 76977.49579393]\n", + " [ 66644.37928489 65983.17656286 65888.95650903 ...\n", + " 78203.36090734 79155.58139177 79092.90448289]\n", + " [ 67317.93144175 66644.37928489 66569.29763937 ...\n", + " 76977.49579393 79092.90448289 80841.90165321]]\n", + "\n", + " [[ 190886.7701807 188474.55733949 185849.00364475 ...\n", + " 157048.20811995 156657.3051288 157723.8989927 ]\n", + " [ 188474.55733949 189381.64170703 188904.70266821 ...\n", + " 155923.9159554 155569.87306421 156657.3051288 ]\n", + " [ 185849.00364475 188904.70266821 191816.48079969 ...\n", + " 156278.12207612 155923.9159554 157048.20811995]\n", + " ...\n", + " [ 157048.20811995 155923.9159554 156278.12207612 ...\n", + " 191816.48079969 188904.70266821 185849.00364475]\n", + " [ 156657.3051288 155569.87306421 155923.9159554 ...\n", + " 188904.70266821 189381.64170703 188474.55733949]\n", + " [ 157723.8989927 156657.3051288 157048.20811995 ...\n", + " 185849.00364475 188474.55733949 190886.7701807 ]]\n", + "\n", + " [[ 687522.42074585 690068.03760091 692370.98952709 ...\n", + " 510415.53650134 507390.38832756 506446.68961168]\n", + " [ 690068.03760091 697729.09820837 703340.94934255 ...\n", + " 511191.4633141 508222.54677431 507390.38832756]\n", + " [ 692370.98952709 703340.94934255 713794.87987696 ...\n", + " 514141.48582852 511191.4633141 510415.53650134]\n", + " ...\n", + " [ 510415.53650134 511191.4633141 514141.48582852 ...\n", + " 713794.87987696 703340.94934255 692370.98952709]\n", + " [ 507390.38832756 508222.54677431 511191.4633141 ...\n", + " 703340.94934255 697729.09820837 690068.03760091]\n", + " [ 506446.68961168 507390.38832756 510415.53650134 ...\n", + " 692370.98952709 690068.03760091 687522.42074585]]]]\n", + "[[[-0.00776844 0.03193292 -0.02190021 ... -0.01967823 0.03001971\n", + " -0.00888104]\n", + " [-0.01141223 0.01261335 0.02016473 ... 0.01930055 0.01481435\n", + " -0.01501347]\n", + " [ 0.01339742 -0.02036281 0.0327504 ... 0.03148365 -0.02175744\n", + " 0.0157307 ]\n", + " ...\n", + " [ 0.01612403 -0.07226699 0.09574159 ... 0.09574159 -0.07226699\n", + " 0.01612403]\n", + " [-0.00475539 -0.02033391 0.03408606 ... 0.03408606 -0.02033391\n", + " -0.00475539]\n", + " [-0.04063615 -0.05660783 0.04304323 ... 0.04304328 -0.05660786\n", + " -0.04063614]]\n", + "\n", + " [[-0.01859845 0.01546722 0.0108962 ... 0.0078561 0.01428418\n", + " -0.02116207]\n", + " [ 0.00531654 0.0057736 -0.00060638 ... -0.00112536 0.00732128\n", + " -0.00220609]\n", + " [ 0.01095194 -0.00353982 0.00285532 ... -0.00191663 -0.00148994\n", + " 0.00316263]\n", + " ...\n", + " [-0.01622886 0.02497454 -0.01994764 ... -0.01994766 0.02497455\n", + " -0.01622886]\n", + " [-0.00999878 0.03655502 -0.07536039 ... -0.07536034 0.03655499\n", + " -0.00999877]\n", + " [-0.03270121 -0.0377052 0.01467869 ... 0.01467865 -0.03770519\n", + " -0.03270121]]\n", + "\n", + " [[-0.01859822 0.02345282 0.00115298 ... 0.00606191 0.02393539\n", + " -0.02102015]\n", + " [ 0.00883563 -0.00247924 0.00416388 ... -0.00213191 0.00759602\n", + " -0.00169398]\n", + " [ 0.00826256 0.00418403 0.00105309 ... -0.00243997 0.00225191\n", + " 0.00488603]\n", + " ...\n", + " [ 0.01227053 -0.07772588 0.1630244 ... 0.1630244 -0.07772588\n", + " 0.01227053]\n", + " [ 0.02446056 -0.10246701 0.12106155 ... 0.12106155 -0.10246702\n", + " 0.02446056]\n", + " [-0.02383464 -0.02997095 0.02674616 ... 0.0267462 -0.02997098\n", + " -0.02383463]]\n", + "\n", + " [[-0.02117638 0.02581447 0.00038692 ... -0.00182418 0.02850038\n", + " -0.02232684]\n", + " [ 0.00812576 -0.01163149 0.01796988 ... 0.01739769 -0.01133722\n", + " 0.00797908]\n", + " [ 0.00544527 -0.00267384 0.01253947 ... 0.01378071 -0.00394178\n", + " 0.00615619]\n", + " ...\n", + " [-0.05062682 0.10451329 -0.10287672 ... -0.10287671 0.10451328\n", + " -0.05062682]\n", + " [ 0.01820577 0.00172198 -0.04704746 ... -0.04704746 0.00172198\n", + " 0.01820577]\n", + " [-0.01436059 -0.04356252 -0.01837525 ... -0.01837525 -0.04356252\n", + " -0.01436059]]]\n" + ] + } + ], + "source": [ + "print(Q)\n", + "print(h)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(h)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(3, 2, 2)\n", + "(3, 2, 2)\n", + "[[[[ 7 11 13]\n", + " [15 16 4]]\n", + "\n", + " [[10 16 18]\n", + " [22 24 6]]]\n", + "\n", + "\n", + " [[[10 16 18]\n", + " [22 24 6]]\n", + "\n", + " [[11 18 19]\n", + " [25 28 7]]]\n", + "\n", + "\n", + " [[[ 3 5 5]\n", + " [ 7 8 2]]\n", + "\n", + " [[ 6 11 8]\n", + " [16 20 5]]]]\n" + ] + }, + { + "data": { + "text/plain": [ + "array([[[ 1, 4, 1],\n", + " [ 4, 9, 16]],\n", + "\n", + " [[ 9, 16, 1],\n", + " [16, 16, 1]]])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f1 = np.array([[[1,2], [1,2]],\n", + " [[3,4], [3,4]],\n", + " [[1,4], [4,1]]])\n", + "print(f1.shape)\n", + "f1 = f1.reshape(2,2,3)\n", + "print(f1.T.shape)\n", + "print(np.dot(f1.T, f1))\n", + "f1 * f1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Playground" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 0.00324561, -0.00059579, -0.00128021, ..., -0.00578292,\n", + " 0.01777824, -0.00643502],\n", + " [-0.01600889, 0.00809095, 0.03050988, ..., 0.00758871,\n", + " 0.01989145, -0.01325478],\n", + " [ 0.00656672, -0.00490941, -0.00502968, ..., 0.00179324,\n", + " -0.00832478, 0.01015856],\n", + " ...,\n", + " [ 0.0444698 , -0.12427632, 0.18072975, ..., -0.00603139,\n", + " 0.00686369, -0.03684298],\n", + " [-0.0129811 , -0.00030824, 0.00968535, ..., 0.02612797,\n", + " -0.07032155, 0.02073493],\n", + " [-0.03408313, -0.02110304, -0.00275129, ..., 0.02475028,\n", + " -0.04518779, -0.03648413]])" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "h[3]" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"Filters/filter\"+str(R), \"rb\") as fp:\n", + " h_raisr = pickle.load(fp)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[-0.0007075 , -0.00708702, -0.01046391, ..., 0.00033279,\n", + " -0.0004557 , -0.00411572],\n", + " [-0.00033651, -0.00460817, -0.00756705, ..., -0.00341872,\n", + " -0.00238595, 0.00307929],\n", + " [-0.0040753 , -0.00427952, -0.00423952, ..., -0.00210784,\n", + " -0.00135864, -0.00191929],\n", + " ...,\n", + " [ 0.05302069, -0.07342937, 0.00305579, ..., -0.17168161,\n", + " 0.15819626, 0.01565984],\n", + " [-0.01224221, -0.0717789 , 0.15969609, ..., -0.19601314,\n", + " 0.19350631, -0.05991437],\n", + " [-0.15019842, 0.05535512, 0.0566023 , ..., 0.00841502,\n", + " -0.01929808, 0.0336716 ]])" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "h_raisr[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import scipy.io as io\n", + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(15,)" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pca_matrix = io.loadmat('1000_patch_PCA_matrix.mat')['p']\n", + "#pca_matrix = np.array(pca_matrix)\n", + "pca_matrix[:,0].shape" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-0.20094993244945833" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.min(pca_matrix)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "kmeans = joblib.load('2_2000_kmeans.model')" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([2], dtype=int32)" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kmeans.predict([kmeans.cluster_centers_[2]])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 1.89180212, 1.79128627],\n", + " [-2.41173289, 1.01900477],\n", + " [-1.18390828, -2.8171925 ],\n", + " [ 0.1069151 , -0.08437171]])" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kmeans.cluster_centers_" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(121, 1)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mean = io.loadmat('2000_patch_mean_matrix.mat')['m']\n", + "mean.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"Filters/Ckmeans_filter\"+str(2), \"rb\") as fp:\n", + " h = pickle.load(fp)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"Filters/8x_filter\"+str(2), \"rb\") as fp:\n", + " h = pickle.load(fp)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "from scipy.spatial.distance import cosine" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.159237958216096" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cosine(h[2,10].reshape(-1, 1), h[3,10].reshape(-1, 1))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(121,)" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "h[0,0].shape" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/trainingData/.DS_Store b/trainingData/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/trainingData/.DS_Store differ diff --git a/trainingData/100075.jpg b/trainingData/100075.jpg new file mode 100644 index 0000000..192268a Binary files /dev/null and b/trainingData/100075.jpg differ diff --git a/trainingData/100080.jpg b/trainingData/100080.jpg new file mode 100644 index 0000000..74fa27f Binary files /dev/null and b/trainingData/100080.jpg differ diff --git a/trainingData/100098.jpg b/trainingData/100098.jpg new file mode 100644 index 0000000..9b14009 Binary files /dev/null and b/trainingData/100098.jpg differ diff --git a/trainingData/103041.jpg b/trainingData/103041.jpg new file mode 100644 index 0000000..cf30680 Binary files /dev/null and b/trainingData/103041.jpg differ diff --git a/trainingData/104022.jpg b/trainingData/104022.jpg new file mode 100644 index 0000000..015e692 Binary files /dev/null and b/trainingData/104022.jpg differ diff --git a/trainingData/105019.jpg b/trainingData/105019.jpg new file mode 100644 index 0000000..a1a811c Binary files /dev/null and b/trainingData/105019.jpg differ diff --git a/trainingData/105053.jpg b/trainingData/105053.jpg new file mode 100644 index 0000000..0fcff78 Binary files /dev/null and b/trainingData/105053.jpg differ diff --git a/trainingData/106020.jpg b/trainingData/106020.jpg new file mode 100644 index 0000000..1845c8f Binary files /dev/null and b/trainingData/106020.jpg differ diff --git a/trainingData/106025.jpg b/trainingData/106025.jpg new file mode 100644 index 0000000..fd1b592 Binary files /dev/null and b/trainingData/106025.jpg differ diff --git a/trainingData/108041.jpg b/trainingData/108041.jpg new file mode 100644 index 0000000..41ffe0f Binary files /dev/null and b/trainingData/108041.jpg differ diff --git a/trainingData/108073.jpg b/trainingData/108073.jpg new file mode 100644 index 0000000..b4a23e5 Binary files /dev/null and b/trainingData/108073.jpg differ diff --git a/trainingData/109034.jpg b/trainingData/109034.jpg new file mode 100644 index 0000000..caa78bb Binary files /dev/null and b/trainingData/109034.jpg differ diff --git a/trainingData/112082.jpg b/trainingData/112082.jpg new file mode 100644 index 0000000..aa3601d Binary files /dev/null and b/trainingData/112082.jpg differ diff --git a/trainingData/113009.jpg b/trainingData/113009.jpg new file mode 100644 index 0000000..2da9d38 Binary files /dev/null and b/trainingData/113009.jpg differ diff --git a/trainingData/113016.jpg b/trainingData/113016.jpg new file mode 100644 index 0000000..d2b1dc5 Binary files /dev/null and b/trainingData/113016.jpg differ diff --git a/trainingData/113044.jpg b/trainingData/113044.jpg new file mode 100644 index 0000000..97f7a7c Binary files /dev/null and b/trainingData/113044.jpg differ diff --git a/trainingData/117054.jpg b/trainingData/117054.jpg new file mode 100644 index 0000000..6ac138c Binary files /dev/null and b/trainingData/117054.jpg differ diff --git a/trainingData/118020.jpg b/trainingData/118020.jpg new file mode 100644 index 0000000..aac200a Binary files /dev/null and b/trainingData/118020.jpg differ diff --git a/trainingData/118035.jpg b/trainingData/118035.jpg new file mode 100644 index 0000000..047f73f Binary files /dev/null and b/trainingData/118035.jpg differ diff --git a/trainingData/12003.jpg b/trainingData/12003.jpg new file mode 100644 index 0000000..2957db8 Binary files /dev/null and b/trainingData/12003.jpg differ diff --git a/trainingData/12074.jpg b/trainingData/12074.jpg new file mode 100644 index 0000000..4ee984b Binary files /dev/null and b/trainingData/12074.jpg differ diff --git a/trainingData/122048.jpg b/trainingData/122048.jpg new file mode 100644 index 0000000..8fdfa34 Binary files /dev/null and b/trainingData/122048.jpg differ diff --git a/trainingData/124084.jpg b/trainingData/124084.jpg new file mode 100644 index 0000000..571fa9b Binary files /dev/null and b/trainingData/124084.jpg differ diff --git a/trainingData/126039.jpg b/trainingData/126039.jpg new file mode 100644 index 0000000..ec9e2fc Binary files /dev/null and b/trainingData/126039.jpg differ diff --git a/trainingData/130034.jpg b/trainingData/130034.jpg new file mode 100644 index 0000000..63e3099 Binary files /dev/null and b/trainingData/130034.jpg differ diff --git a/trainingData/134008.jpg b/trainingData/134008.jpg new file mode 100644 index 0000000..234fc15 Binary files /dev/null and b/trainingData/134008.jpg differ diff --git a/trainingData/134052.jpg b/trainingData/134052.jpg new file mode 100644 index 0000000..950cff0 Binary files /dev/null and b/trainingData/134052.jpg differ diff --git a/trainingData/135037.jpg b/trainingData/135037.jpg new file mode 100644 index 0000000..dc0e2aa Binary files /dev/null and b/trainingData/135037.jpg differ diff --git a/trainingData/135069.jpg b/trainingData/135069.jpg new file mode 100644 index 0000000..a009ee5 Binary files /dev/null and b/trainingData/135069.jpg differ diff --git a/trainingData/138032.jpg b/trainingData/138032.jpg new file mode 100644 index 0000000..cd876f5 Binary files /dev/null and b/trainingData/138032.jpg differ diff --git a/trainingData/138078.jpg b/trainingData/138078.jpg new file mode 100644 index 0000000..e8b0f4f Binary files /dev/null and b/trainingData/138078.jpg differ diff --git a/trainingData/140055.jpg b/trainingData/140055.jpg new file mode 100644 index 0000000..ef3bf1d Binary files /dev/null and b/trainingData/140055.jpg differ diff --git a/trainingData/140075.jpg b/trainingData/140075.jpg new file mode 100644 index 0000000..3436752 Binary files /dev/null and b/trainingData/140075.jpg differ diff --git a/trainingData/144067.jpg b/trainingData/144067.jpg new file mode 100644 index 0000000..a3618a5 Binary files /dev/null and b/trainingData/144067.jpg differ diff --git a/trainingData/145014.jpg b/trainingData/145014.jpg new file mode 100644 index 0000000..dcfce8f Binary files /dev/null and b/trainingData/145014.jpg differ diff --git a/trainingData/145053.jpg b/trainingData/145053.jpg new file mode 100644 index 0000000..408106f Binary files /dev/null and b/trainingData/145053.jpg differ diff --git a/trainingData/147021.jpg b/trainingData/147021.jpg new file mode 100644 index 0000000..956acc7 Binary files /dev/null and b/trainingData/147021.jpg differ diff --git a/trainingData/147062.jpg b/trainingData/147062.jpg new file mode 100644 index 0000000..8737523 Binary files /dev/null and b/trainingData/147062.jpg differ diff --git a/trainingData/15004.jpg b/trainingData/15004.jpg new file mode 100644 index 0000000..b04dc96 Binary files /dev/null and b/trainingData/15004.jpg differ diff --git a/trainingData/15088.jpg b/trainingData/15088.jpg new file mode 100644 index 0000000..8019a85 Binary files /dev/null and b/trainingData/15088.jpg differ diff --git a/trainingData/151087.jpg b/trainingData/151087.jpg new file mode 100644 index 0000000..cee544f Binary files /dev/null and b/trainingData/151087.jpg differ diff --git a/trainingData/153077.jpg b/trainingData/153077.jpg new file mode 100644 index 0000000..1c86f09 Binary files /dev/null and b/trainingData/153077.jpg differ diff --git a/trainingData/153093.jpg b/trainingData/153093.jpg new file mode 100644 index 0000000..0381e8b Binary files /dev/null and b/trainingData/153093.jpg differ diff --git a/trainingData/155060.jpg b/trainingData/155060.jpg new file mode 100644 index 0000000..e9329a0 Binary files /dev/null and b/trainingData/155060.jpg differ diff --git a/trainingData/156079.jpg b/trainingData/156079.jpg new file mode 100644 index 0000000..257454a Binary files /dev/null and b/trainingData/156079.jpg differ diff --git a/trainingData/157036.jpg b/trainingData/157036.jpg new file mode 100644 index 0000000..4b92dd0 Binary files /dev/null and b/trainingData/157036.jpg differ diff --git a/trainingData/159029.jpg b/trainingData/159029.jpg new file mode 100644 index 0000000..194520d Binary files /dev/null and b/trainingData/159029.jpg differ diff --git a/trainingData/159045.jpg b/trainingData/159045.jpg new file mode 100644 index 0000000..13f5aca Binary files /dev/null and b/trainingData/159045.jpg differ diff --git a/trainingData/159091.jpg b/trainingData/159091.jpg new file mode 100644 index 0000000..3a68e0b Binary files /dev/null and b/trainingData/159091.jpg differ diff --git a/trainingData/16052.jpg b/trainingData/16052.jpg new file mode 100644 index 0000000..9e94d50 Binary files /dev/null and b/trainingData/16052.jpg differ diff --git a/trainingData/161062.jpg b/trainingData/161062.jpg new file mode 100644 index 0000000..e1afca6 Binary files /dev/null and b/trainingData/161062.jpg differ diff --git a/trainingData/163014.jpg b/trainingData/163014.jpg new file mode 100644 index 0000000..b1da2d3 Binary files /dev/null and b/trainingData/163014.jpg differ diff --git a/trainingData/163062.jpg b/trainingData/163062.jpg new file mode 100644 index 0000000..156159c Binary files /dev/null and b/trainingData/163062.jpg differ diff --git a/trainingData/164074.jpg b/trainingData/164074.jpg new file mode 100644 index 0000000..1160d1c Binary files /dev/null and b/trainingData/164074.jpg differ diff --git a/trainingData/166081.jpg b/trainingData/166081.jpg new file mode 100644 index 0000000..71664f7 Binary files /dev/null and b/trainingData/166081.jpg differ diff --git a/trainingData/169012.jpg b/trainingData/169012.jpg new file mode 100644 index 0000000..d2bf33f Binary files /dev/null and b/trainingData/169012.jpg differ diff --git a/trainingData/170054.jpg b/trainingData/170054.jpg new file mode 100644 index 0000000..b4418cf Binary files /dev/null and b/trainingData/170054.jpg differ diff --git a/trainingData/172032.jpg b/trainingData/172032.jpg new file mode 100644 index 0000000..8465e14 Binary files /dev/null and b/trainingData/172032.jpg differ diff --git a/trainingData/173036.jpg b/trainingData/173036.jpg new file mode 100644 index 0000000..2a4ea5a Binary files /dev/null and b/trainingData/173036.jpg differ diff --git a/trainingData/176019.jpg b/trainingData/176019.jpg new file mode 100644 index 0000000..133c8e0 Binary files /dev/null and b/trainingData/176019.jpg differ diff --git a/trainingData/176035.jpg b/trainingData/176035.jpg new file mode 100644 index 0000000..e667e44 Binary files /dev/null and b/trainingData/176035.jpg differ diff --git a/trainingData/176039.jpg b/trainingData/176039.jpg new file mode 100644 index 0000000..0e9f3e9 Binary files /dev/null and b/trainingData/176039.jpg differ diff --git a/trainingData/178054.jpg b/trainingData/178054.jpg new file mode 100644 index 0000000..3cd5e43 Binary files /dev/null and b/trainingData/178054.jpg differ diff --git a/trainingData/181018.jpg b/trainingData/181018.jpg new file mode 100644 index 0000000..eaadd2b Binary files /dev/null and b/trainingData/181018.jpg differ diff --git a/trainingData/181079.jpg b/trainingData/181079.jpg new file mode 100644 index 0000000..9867147 Binary files /dev/null and b/trainingData/181079.jpg differ diff --git a/trainingData/181091.jpg b/trainingData/181091.jpg new file mode 100644 index 0000000..483ddfe Binary files /dev/null and b/trainingData/181091.jpg differ diff --git a/trainingData/183055.jpg b/trainingData/183055.jpg new file mode 100644 index 0000000..7e79343 Binary files /dev/null and b/trainingData/183055.jpg differ diff --git a/trainingData/183087.jpg b/trainingData/183087.jpg new file mode 100644 index 0000000..3aeb938 Binary files /dev/null and b/trainingData/183087.jpg differ diff --git a/trainingData/187003.jpg b/trainingData/187003.jpg new file mode 100644 index 0000000..ffa8f82 Binary files /dev/null and b/trainingData/187003.jpg differ diff --git a/trainingData/187029.jpg b/trainingData/187029.jpg new file mode 100644 index 0000000..4837b1e Binary files /dev/null and b/trainingData/187029.jpg differ diff --git a/trainingData/187039.jpg b/trainingData/187039.jpg new file mode 100644 index 0000000..88afbcc Binary files /dev/null and b/trainingData/187039.jpg differ diff --git a/trainingData/187071.jpg b/trainingData/187071.jpg new file mode 100644 index 0000000..0226210 Binary files /dev/null and b/trainingData/187071.jpg differ diff --git a/trainingData/187083.jpg b/trainingData/187083.jpg new file mode 100644 index 0000000..85e4c44 Binary files /dev/null and b/trainingData/187083.jpg differ diff --git a/trainingData/188005.jpg b/trainingData/188005.jpg new file mode 100644 index 0000000..c756853 Binary files /dev/null and b/trainingData/188005.jpg differ diff --git a/trainingData/188063.jpg b/trainingData/188063.jpg new file mode 100644 index 0000000..ff3311c Binary files /dev/null and b/trainingData/188063.jpg differ diff --git a/trainingData/188091.jpg b/trainingData/188091.jpg new file mode 100644 index 0000000..5842962 Binary files /dev/null and b/trainingData/188091.jpg differ diff --git a/trainingData/189003.jpg b/trainingData/189003.jpg new file mode 100644 index 0000000..63f45db Binary files /dev/null and b/trainingData/189003.jpg differ diff --git a/trainingData/189011.jpg b/trainingData/189011.jpg new file mode 100644 index 0000000..3171401 Binary files /dev/null and b/trainingData/189011.jpg differ diff --git a/trainingData/196015.jpg b/trainingData/196015.jpg new file mode 100644 index 0000000..8dfaf6e Binary files /dev/null and b/trainingData/196015.jpg differ diff --git a/trainingData/198004.jpg b/trainingData/198004.jpg new file mode 100644 index 0000000..314055b Binary files /dev/null and b/trainingData/198004.jpg differ diff --git a/trainingData/198023.jpg b/trainingData/198023.jpg new file mode 100644 index 0000000..fcdfa7a Binary files /dev/null and b/trainingData/198023.jpg differ diff --git a/trainingData/198054.jpg b/trainingData/198054.jpg new file mode 100644 index 0000000..50b2f8a Binary files /dev/null and b/trainingData/198054.jpg differ diff --git a/trainingData/20008.jpg b/trainingData/20008.jpg new file mode 100644 index 0000000..6bcdab0 Binary files /dev/null and b/trainingData/20008.jpg differ diff --git a/trainingData/202012.jpg b/trainingData/202012.jpg new file mode 100644 index 0000000..08d4577 Binary files /dev/null and b/trainingData/202012.jpg differ diff --git a/trainingData/207056.jpg b/trainingData/207056.jpg new file mode 100644 index 0000000..d32c0b6 Binary files /dev/null and b/trainingData/207056.jpg differ diff --git a/trainingData/209070.jpg b/trainingData/209070.jpg new file mode 100644 index 0000000..9eb8dca Binary files /dev/null and b/trainingData/209070.jpg differ diff --git a/trainingData/2092.jpg b/trainingData/2092.jpg new file mode 100644 index 0000000..bdd4cf3 Binary files /dev/null and b/trainingData/2092.jpg differ diff --git a/trainingData/216041.jpg b/trainingData/216041.jpg new file mode 100644 index 0000000..7346c85 Binary files /dev/null and b/trainingData/216041.jpg differ diff --git a/trainingData/216053.jpg b/trainingData/216053.jpg new file mode 100644 index 0000000..9b434ff Binary files /dev/null and b/trainingData/216053.jpg differ diff --git a/trainingData/216066.jpg b/trainingData/216066.jpg new file mode 100644 index 0000000..d634f86 Binary files /dev/null and b/trainingData/216066.jpg differ diff --git a/trainingData/22013.jpg b/trainingData/22013.jpg new file mode 100644 index 0000000..da70331 Binary files /dev/null and b/trainingData/22013.jpg differ diff --git a/trainingData/22090.jpg b/trainingData/22090.jpg new file mode 100644 index 0000000..d1295dd Binary files /dev/null and b/trainingData/22090.jpg differ diff --git a/trainingData/22093.jpg b/trainingData/22093.jpg new file mode 100644 index 0000000..583d294 Binary files /dev/null and b/trainingData/22093.jpg differ diff --git a/trainingData/225017.jpg b/trainingData/225017.jpg new file mode 100644 index 0000000..5f48eb6 Binary files /dev/null and b/trainingData/225017.jpg differ diff --git a/trainingData/227040.jpg b/trainingData/227040.jpg new file mode 100644 index 0000000..79c6bb5 Binary files /dev/null and b/trainingData/227040.jpg differ diff --git a/trainingData/227046.jpg b/trainingData/227046.jpg new file mode 100644 index 0000000..fe0c44f Binary files /dev/null and b/trainingData/227046.jpg differ diff --git a/trainingData/23025.jpg b/trainingData/23025.jpg new file mode 100644 index 0000000..b3bb33d Binary files /dev/null and b/trainingData/23025.jpg differ diff --git a/trainingData/23080.jpg b/trainingData/23080.jpg new file mode 100644 index 0000000..2921b2e Binary files /dev/null and b/trainingData/23080.jpg differ diff --git a/trainingData/23084.jpg b/trainingData/23084.jpg new file mode 100644 index 0000000..97373cc Binary files /dev/null and b/trainingData/23084.jpg differ diff --git a/trainingData/231015.jpg b/trainingData/231015.jpg new file mode 100644 index 0000000..078258d Binary files /dev/null and b/trainingData/231015.jpg differ diff --git a/trainingData/232038.jpg b/trainingData/232038.jpg new file mode 100644 index 0000000..b1c0f7d Binary files /dev/null and b/trainingData/232038.jpg differ diff --git a/trainingData/236017.jpg b/trainingData/236017.jpg new file mode 100644 index 0000000..317f066 Binary files /dev/null and b/trainingData/236017.jpg differ diff --git a/trainingData/238011.jpg b/trainingData/238011.jpg new file mode 100644 index 0000000..77de150 Binary files /dev/null and b/trainingData/238011.jpg differ diff --git a/trainingData/239007.jpg b/trainingData/239007.jpg new file mode 100644 index 0000000..61d0e95 Binary files /dev/null and b/trainingData/239007.jpg differ diff --git a/trainingData/239096.jpg b/trainingData/239096.jpg new file mode 100644 index 0000000..e4f1f12 Binary files /dev/null and b/trainingData/239096.jpg differ diff --git a/trainingData/24004.jpg b/trainingData/24004.jpg new file mode 100644 index 0000000..57d2f41 Binary files /dev/null and b/trainingData/24004.jpg differ diff --git a/trainingData/24063.jpg b/trainingData/24063.jpg new file mode 100644 index 0000000..d054215 Binary files /dev/null and b/trainingData/24063.jpg differ diff --git a/trainingData/242078.jpg b/trainingData/242078.jpg new file mode 100644 index 0000000..6cc3967 Binary files /dev/null and b/trainingData/242078.jpg differ diff --git a/trainingData/245051.jpg b/trainingData/245051.jpg new file mode 100644 index 0000000..d038b2f Binary files /dev/null and b/trainingData/245051.jpg differ diff --git a/trainingData/246016.jpg b/trainingData/246016.jpg new file mode 100644 index 0000000..d8c6ba8 Binary files /dev/null and b/trainingData/246016.jpg differ diff --git a/trainingData/246053.jpg b/trainingData/246053.jpg new file mode 100644 index 0000000..025469c Binary files /dev/null and b/trainingData/246053.jpg differ diff --git a/trainingData/247085.jpg b/trainingData/247085.jpg new file mode 100644 index 0000000..01a5114 Binary files /dev/null and b/trainingData/247085.jpg differ diff --git a/trainingData/249061.jpg b/trainingData/249061.jpg new file mode 100644 index 0000000..05a2bea Binary files /dev/null and b/trainingData/249061.jpg differ diff --git a/trainingData/249087.jpg b/trainingData/249087.jpg new file mode 100644 index 0000000..2b3d0b8 Binary files /dev/null and b/trainingData/249087.jpg differ diff --git a/trainingData/25098.jpg b/trainingData/25098.jpg new file mode 100644 index 0000000..db3519e Binary files /dev/null and b/trainingData/25098.jpg differ diff --git a/trainingData/253036.jpg b/trainingData/253036.jpg new file mode 100644 index 0000000..91a8e0e Binary files /dev/null and b/trainingData/253036.jpg differ diff --git a/trainingData/254033.jpg b/trainingData/254033.jpg new file mode 100644 index 0000000..c99331e Binary files /dev/null and b/trainingData/254033.jpg differ diff --git a/trainingData/254054.jpg b/trainingData/254054.jpg new file mode 100644 index 0000000..0177e30 Binary files /dev/null and b/trainingData/254054.jpg differ diff --git a/trainingData/260081.jpg b/trainingData/260081.jpg new file mode 100644 index 0000000..6d716c6 Binary files /dev/null and b/trainingData/260081.jpg differ diff --git a/trainingData/26031.jpg b/trainingData/26031.jpg new file mode 100644 index 0000000..22f8eb0 Binary files /dev/null and b/trainingData/26031.jpg differ diff --git a/trainingData/268002.jpg b/trainingData/268002.jpg new file mode 100644 index 0000000..77950a9 Binary files /dev/null and b/trainingData/268002.jpg differ diff --git a/trainingData/27059.jpg b/trainingData/27059.jpg new file mode 100644 index 0000000..6d409ed Binary files /dev/null and b/trainingData/27059.jpg differ diff --git a/trainingData/271008.jpg b/trainingData/271008.jpg new file mode 100644 index 0000000..de3e95e Binary files /dev/null and b/trainingData/271008.jpg differ diff --git a/trainingData/271031.jpg b/trainingData/271031.jpg new file mode 100644 index 0000000..20af2e5 Binary files /dev/null and b/trainingData/271031.jpg differ diff --git a/trainingData/274007.jpg b/trainingData/274007.jpg new file mode 100644 index 0000000..80d5e3d Binary files /dev/null and b/trainingData/274007.jpg differ diff --git a/trainingData/277095.jpg b/trainingData/277095.jpg new file mode 100644 index 0000000..879f5fb Binary files /dev/null and b/trainingData/277095.jpg differ diff --git a/trainingData/28075.jpg b/trainingData/28075.jpg new file mode 100644 index 0000000..f849768 Binary files /dev/null and b/trainingData/28075.jpg differ diff --git a/trainingData/28096.jpg b/trainingData/28096.jpg new file mode 100644 index 0000000..c3d6b41 Binary files /dev/null and b/trainingData/28096.jpg differ diff --git a/trainingData/285036.jpg b/trainingData/285036.jpg new file mode 100644 index 0000000..ce030a0 Binary files /dev/null and b/trainingData/285036.jpg differ diff --git a/trainingData/286092.jpg b/trainingData/286092.jpg new file mode 100644 index 0000000..5748b10 Binary files /dev/null and b/trainingData/286092.jpg differ diff --git a/trainingData/292066.jpg b/trainingData/292066.jpg new file mode 100644 index 0000000..b060e8a Binary files /dev/null and b/trainingData/292066.jpg differ diff --git a/trainingData/293029.jpg b/trainingData/293029.jpg new file mode 100644 index 0000000..51f34b1 Binary files /dev/null and b/trainingData/293029.jpg differ diff --git a/trainingData/299091.jpg b/trainingData/299091.jpg new file mode 100644 index 0000000..eb26732 Binary files /dev/null and b/trainingData/299091.jpg differ diff --git a/trainingData/301007.jpg b/trainingData/301007.jpg new file mode 100644 index 0000000..cf6a2de Binary files /dev/null and b/trainingData/301007.jpg differ diff --git a/trainingData/302003.jpg b/trainingData/302003.jpg new file mode 100644 index 0000000..fa21591 Binary files /dev/null and b/trainingData/302003.jpg differ diff --git a/trainingData/309004.jpg b/trainingData/309004.jpg new file mode 100644 index 0000000..10ef925 Binary files /dev/null and b/trainingData/309004.jpg differ diff --git a/trainingData/310007.jpg b/trainingData/310007.jpg new file mode 100644 index 0000000..a3fe819 Binary files /dev/null and b/trainingData/310007.jpg differ diff --git a/trainingData/311068.jpg b/trainingData/311068.jpg new file mode 100644 index 0000000..dd55f27 Binary files /dev/null and b/trainingData/311068.jpg differ diff --git a/trainingData/311081.jpg b/trainingData/311081.jpg new file mode 100644 index 0000000..d53c90d Binary files /dev/null and b/trainingData/311081.jpg differ diff --git a/trainingData/314016.jpg b/trainingData/314016.jpg new file mode 100644 index 0000000..38ae224 Binary files /dev/null and b/trainingData/314016.jpg differ diff --git a/trainingData/317080.jpg b/trainingData/317080.jpg new file mode 100644 index 0000000..2b14b5d Binary files /dev/null and b/trainingData/317080.jpg differ diff --git a/trainingData/323016.jpg b/trainingData/323016.jpg new file mode 100644 index 0000000..8e65e58 Binary files /dev/null and b/trainingData/323016.jpg differ diff --git a/trainingData/326038.jpg b/trainingData/326038.jpg new file mode 100644 index 0000000..41a6893 Binary files /dev/null and b/trainingData/326038.jpg differ diff --git a/trainingData/33066.jpg b/trainingData/33066.jpg new file mode 100644 index 0000000..bd91c6c Binary files /dev/null and b/trainingData/33066.jpg differ diff --git a/trainingData/35008.jpg b/trainingData/35008.jpg new file mode 100644 index 0000000..7b58d43 Binary files /dev/null and b/trainingData/35008.jpg differ diff --git a/trainingData/35010.jpg b/trainingData/35010.jpg new file mode 100644 index 0000000..5e600e1 Binary files /dev/null and b/trainingData/35010.jpg differ diff --git a/trainingData/35058.jpg b/trainingData/35058.jpg new file mode 100644 index 0000000..71f8a13 Binary files /dev/null and b/trainingData/35058.jpg differ diff --git a/trainingData/35070.jpg b/trainingData/35070.jpg new file mode 100644 index 0000000..8fc7e17 Binary files /dev/null and b/trainingData/35070.jpg differ diff --git a/trainingData/35091.jpg b/trainingData/35091.jpg new file mode 100644 index 0000000..b0436ea Binary files /dev/null and b/trainingData/35091.jpg differ diff --git a/trainingData/353013.jpg b/trainingData/353013.jpg new file mode 100644 index 0000000..0ac7ac0 Binary files /dev/null and b/trainingData/353013.jpg differ diff --git a/trainingData/361084.jpg b/trainingData/361084.jpg new file mode 100644 index 0000000..13d52c6 Binary files /dev/null and b/trainingData/361084.jpg differ diff --git a/trainingData/365025.jpg b/trainingData/365025.jpg new file mode 100644 index 0000000..4fdf8a5 Binary files /dev/null and b/trainingData/365025.jpg differ diff --git a/trainingData/365073.jpg b/trainingData/365073.jpg new file mode 100644 index 0000000..924ff40 Binary files /dev/null and b/trainingData/365073.jpg differ diff --git a/trainingData/368016.jpg b/trainingData/368016.jpg new file mode 100644 index 0000000..295db06 Binary files /dev/null and b/trainingData/368016.jpg differ diff --git a/trainingData/368078.jpg b/trainingData/368078.jpg new file mode 100644 index 0000000..c01f6c5 Binary files /dev/null and b/trainingData/368078.jpg differ diff --git a/trainingData/370036.jpg b/trainingData/370036.jpg new file mode 100644 index 0000000..545949e Binary files /dev/null and b/trainingData/370036.jpg differ diff --git a/trainingData/372047.jpg b/trainingData/372047.jpg new file mode 100644 index 0000000..5f4d561 Binary files /dev/null and b/trainingData/372047.jpg differ diff --git a/trainingData/374020.jpg b/trainingData/374020.jpg new file mode 100644 index 0000000..5da4ce2 Binary files /dev/null and b/trainingData/374020.jpg differ diff --git a/trainingData/374067.jpg b/trainingData/374067.jpg new file mode 100644 index 0000000..c12b075 Binary files /dev/null and b/trainingData/374067.jpg differ diff --git a/trainingData/376001.jpg b/trainingData/376001.jpg new file mode 100644 index 0000000..fa765e8 Binary files /dev/null and b/trainingData/376001.jpg differ diff --git a/trainingData/376020.jpg b/trainingData/376020.jpg new file mode 100644 index 0000000..0a8d713 Binary files /dev/null and b/trainingData/376020.jpg differ diff --git a/trainingData/385028.jpg b/trainingData/385028.jpg new file mode 100644 index 0000000..95e3305 Binary files /dev/null and b/trainingData/385028.jpg differ diff --git a/trainingData/388016.jpg b/trainingData/388016.jpg new file mode 100644 index 0000000..1220557 Binary files /dev/null and b/trainingData/388016.jpg differ diff --git a/trainingData/41004.jpg b/trainingData/41004.jpg new file mode 100644 index 0000000..f2ac372 Binary files /dev/null and b/trainingData/41004.jpg differ diff --git a/trainingData/41025.jpg b/trainingData/41025.jpg new file mode 100644 index 0000000..2e2ca83 Binary files /dev/null and b/trainingData/41025.jpg differ diff --git a/trainingData/42044.jpg b/trainingData/42044.jpg new file mode 100644 index 0000000..31c2217 Binary files /dev/null and b/trainingData/42044.jpg differ diff --git a/trainingData/42078.jpg b/trainingData/42078.jpg new file mode 100644 index 0000000..c4c168a Binary files /dev/null and b/trainingData/42078.jpg differ diff --git a/trainingData/43070.jpg b/trainingData/43070.jpg new file mode 100644 index 0000000..11de997 Binary files /dev/null and b/trainingData/43070.jpg differ diff --git a/trainingData/43083.jpg b/trainingData/43083.jpg new file mode 100644 index 0000000..4ae1a51 Binary files /dev/null and b/trainingData/43083.jpg differ diff --git a/trainingData/45077.jpg b/trainingData/45077.jpg new file mode 100644 index 0000000..98ff1e6 Binary files /dev/null and b/trainingData/45077.jpg differ diff --git a/trainingData/46076.jpg b/trainingData/46076.jpg new file mode 100644 index 0000000..4a16659 Binary files /dev/null and b/trainingData/46076.jpg differ diff --git a/trainingData/48055.jpg b/trainingData/48055.jpg new file mode 100644 index 0000000..298aba0 Binary files /dev/null and b/trainingData/48055.jpg differ diff --git a/trainingData/54005.jpg b/trainingData/54005.jpg new file mode 100644 index 0000000..1db2b07 Binary files /dev/null and b/trainingData/54005.jpg differ diff --git a/trainingData/55067.jpg b/trainingData/55067.jpg new file mode 100644 index 0000000..ce946c1 Binary files /dev/null and b/trainingData/55067.jpg differ diff --git a/trainingData/55075.jpg b/trainingData/55075.jpg new file mode 100644 index 0000000..5bde381 Binary files /dev/null and b/trainingData/55075.jpg differ diff --git a/trainingData/56028.jpg b/trainingData/56028.jpg new file mode 100644 index 0000000..c5db81a Binary files /dev/null and b/trainingData/56028.jpg differ diff --git a/trainingData/59078.jpg b/trainingData/59078.jpg new file mode 100644 index 0000000..09cfbef Binary files /dev/null and b/trainingData/59078.jpg differ diff --git a/trainingData/60079.jpg b/trainingData/60079.jpg new file mode 100644 index 0000000..aad2d2a Binary files /dev/null and b/trainingData/60079.jpg differ diff --git a/trainingData/61060.jpg b/trainingData/61060.jpg new file mode 100644 index 0000000..bb89b34 Binary files /dev/null and b/trainingData/61060.jpg differ diff --git a/trainingData/61086.jpg b/trainingData/61086.jpg new file mode 100644 index 0000000..fd4d9bd Binary files /dev/null and b/trainingData/61086.jpg differ diff --git a/trainingData/65010.jpg b/trainingData/65010.jpg new file mode 100644 index 0000000..ed1f223 Binary files /dev/null and b/trainingData/65010.jpg differ diff --git a/trainingData/65019.jpg b/trainingData/65019.jpg new file mode 100644 index 0000000..5291a6a Binary files /dev/null and b/trainingData/65019.jpg differ diff --git a/trainingData/65074.jpg b/trainingData/65074.jpg new file mode 100644 index 0000000..d29c69b Binary files /dev/null and b/trainingData/65074.jpg differ diff --git a/trainingData/65132.jpg b/trainingData/65132.jpg new file mode 100644 index 0000000..2d370de Binary files /dev/null and b/trainingData/65132.jpg differ diff --git a/trainingData/66039.jpg b/trainingData/66039.jpg new file mode 100644 index 0000000..926dbf8 Binary files /dev/null and b/trainingData/66039.jpg differ diff --git a/trainingData/66075.jpg b/trainingData/66075.jpg new file mode 100644 index 0000000..0e0940e Binary files /dev/null and b/trainingData/66075.jpg differ diff --git a/trainingData/67079.jpg b/trainingData/67079.jpg new file mode 100644 index 0000000..bdbdbe6 Binary files /dev/null and b/trainingData/67079.jpg differ diff --git a/trainingData/68077.jpg b/trainingData/68077.jpg new file mode 100644 index 0000000..d54db65 Binary files /dev/null and b/trainingData/68077.jpg differ diff --git a/trainingData/71046.jpg b/trainingData/71046.jpg new file mode 100644 index 0000000..96bf198 Binary files /dev/null and b/trainingData/71046.jpg differ diff --git a/trainingData/76002.jpg b/trainingData/76002.jpg new file mode 100644 index 0000000..8657cfb Binary files /dev/null and b/trainingData/76002.jpg differ diff --git a/trainingData/78019.jpg b/trainingData/78019.jpg new file mode 100644 index 0000000..b769712 Binary files /dev/null and b/trainingData/78019.jpg differ diff --git a/trainingData/80099.jpg b/trainingData/80099.jpg new file mode 100644 index 0000000..06b23ab Binary files /dev/null and b/trainingData/80099.jpg differ diff --git a/trainingData/8049.jpg b/trainingData/8049.jpg new file mode 100644 index 0000000..07cc2f6 Binary files /dev/null and b/trainingData/8049.jpg differ diff --git a/trainingData/8143.jpg b/trainingData/8143.jpg new file mode 100644 index 0000000..4ff69df Binary files /dev/null and b/trainingData/8143.jpg differ diff --git a/trainingData/87065.jpg b/trainingData/87065.jpg new file mode 100644 index 0000000..6bb8c3d Binary files /dev/null and b/trainingData/87065.jpg differ diff --git a/trainingData/90076.jpg b/trainingData/90076.jpg new file mode 100644 index 0000000..3d48eec Binary files /dev/null and b/trainingData/90076.jpg differ diff --git a/trainingData/92059.jpg b/trainingData/92059.jpg new file mode 100644 index 0000000..7e7f0e8 Binary files /dev/null and b/trainingData/92059.jpg differ diff --git a/trainingData/94079.jpg b/trainingData/94079.jpg new file mode 100644 index 0000000..bb9bb06 Binary files /dev/null and b/trainingData/94079.jpg differ diff --git a/trainingData/95006.jpg b/trainingData/95006.jpg new file mode 100644 index 0000000..aef7769 Binary files /dev/null and b/trainingData/95006.jpg differ diff --git a/trainingData/97017.jpg b/trainingData/97017.jpg new file mode 100644 index 0000000..76c7f21 Binary files /dev/null and b/trainingData/97017.jpg differ diff --git a/trainingDataSmall/.DS_Store b/trainingDataSmall/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/trainingDataSmall/.DS_Store differ diff --git a/trainingDataSmall/153093.jpg b/trainingDataSmall/153093.jpg new file mode 100644 index 0000000..0381e8b Binary files /dev/null and b/trainingDataSmall/153093.jpg differ diff --git a/x2_1_3000_kmeans.model b/x2_1_3000_kmeans.model new file mode 100644 index 0000000..340c2b9 Binary files /dev/null and b/x2_1_3000_kmeans.model differ diff --git a/x2_1_3000_patch_PCA_matrix.mat b/x2_1_3000_patch_PCA_matrix.mat new file mode 100644 index 0000000..9981467 Binary files /dev/null and b/x2_1_3000_patch_PCA_matrix.mat differ diff --git a/x2_1_3000_patch_mean_matrix.mat b/x2_1_3000_patch_mean_matrix.mat new file mode 100644 index 0000000..4420956 Binary files /dev/null and b/x2_1_3000_patch_mean_matrix.mat differ diff --git a/x3_1_3000_kmeans.model b/x3_1_3000_kmeans.model new file mode 100644 index 0000000..cfec505 Binary files /dev/null and b/x3_1_3000_kmeans.model differ diff --git a/x3_1_3000_patch_PCA_matrix.mat b/x3_1_3000_patch_PCA_matrix.mat new file mode 100644 index 0000000..6b60d0c Binary files /dev/null and b/x3_1_3000_patch_PCA_matrix.mat differ diff --git a/x3_1_3000_patch_mean_matrix.mat b/x3_1_3000_patch_mean_matrix.mat new file mode 100644 index 0000000..c903d48 Binary files /dev/null and b/x3_1_3000_patch_mean_matrix.mat differ