# coding:utf-8
__author__ = 'liangz14'
import math
import numpy as np
from skimage import io
from skimage import color
import scipy.io
from scipy.misc import imresize
from scipy.signal import convolve2d
from sklearn.externals import joblib
from skimage import data
#求解线性方程组:
from sklearn import linear_model
import bicubic_2d
import matplotlib.pyplot as plt
import skimage
from skimage.filters import gaussian_filter
from skimage.morphology import disk
from skimage.filters.rank import median
#超分辨率处理函数
def SR(img,Dh, Dl,l_da=0.0001, scale=3.0,patch_sizel=3.0, overlap=1.0 ,img_size=1.0):
#l_da是经验值
#得到特征域
feat_scale=2.0
patch_sizeh = patch_sizel*scale
patch_sizem = patch_sizel*feat_scale
imgm = bicubic_2d.bicubic2d(img, feat_scale)
imgh = np.zeros((img.shape[0]*3,img.shape[1]*3),dtype='float64')
img_bicubic = bicubic_2d.bicubic2d(img, 3.0)
normalizationMat = np.zeros((img.shape[0]*3,img.shape[1]*3))
print img.shape, imgm.shape, imgh.shape
f1 = np.asarray([[-1, 0, 1]], dtype='float64')
f2 = np.asarray([[-1], [0], [1]], dtype='float64')
f3 = np.asarray([[1, 0, -2, 0, 1]], dtype='float64')
f4 = np.asarray([[1], [0], [-2], [0], [1]], dtype='float64')
F = np.zeros((imgm.shape[0], imgm.shape[1], 4))
F[:, :, 0] = convolve2d(imgm, f1, mode='same')
F[:, :, 1] = convolve2d(imgm, f2, mode='same')
F[:, :, 2] = convolve2d(imgm, f3, mode='same')
F[:, :, 3] = convolve2d(imgm, f4, mode='same')
xgrid = np.ogrid[np.ceil(patch_sizel/2.0):img.shape[1]-patch_sizel:patch_sizel - overlap]
ygrid = np.ogrid[np.ceil(patch_sizel/2.0):img.shape[0]-patch_sizel:patch_sizel - overlap]
xgrid = np.asarray(xgrid)
ygrid = np.asarray(ygrid)
xgrid = np.append(xgrid, img.shape[1]-patch_sizel)
ygrid = np.append(ygrid, img.shape[0]-patch_sizel)
xgridm = (xgrid-1)*feat_scale + 1
ygridm = (ygrid-1)*feat_scale + 1
xgridh = (xgrid-1)*scale+1
ygridh = (ygrid-1)*scale+1
for i in range(len(xgridm)):
for j in range(len(ygridm)):
x,y = xgridm[i], ygridm[j]
xh,yh = xgridh[i], ygridh[j]
patchm = imgm[y:y+patch_sizem, x:x+patch_sizem]
avg_patch = np.mean(patchm)
featpatch = np.transpose(F[y:y+patch_sizem, x:x+patch_sizem,:],axes=(2,0,1)).reshape(patch_sizem*patch_sizem*4)
normalization_m = math.sqrt(np.sum(featpatch**2))
yy=[]
if normalization_m > 1:
yy = featpatch/normalization_m
else:
yy = featpatch
clf = linear_model.Lasso(alpha=l_da)
clf.fit(Dl, yy)
w = clf.coef_
patchh=[]
if normalization_m > 1:
patchh = np.dot(Dh,w)*normalization_m
else:
patchh = np.dot(Dh,w)
patchh = patchh.reshape([patch_sizeh, patch_sizeh]) + avg_patch
imgh[yh:yh+patch_sizeh, xh:xh+patch_sizeh]= imgh[yh:yh+patch_sizeh, xh:xh+patch_sizeh] + patchh
normalizationMat[yh:yh+patch_sizeh, xh:xh+patch_sizeh]= normalizationMat[yh:yh+patch_sizeh, xh:xh+patch_sizeh]+ 1
print x,y
mask = normalizationMat == 0
normalizationMat[mask] = 1
imgh = imgh/normalizationMat
imgh[mask] = img_bicubic[mask]
joblib.dump(imgh, 'img_h0005.pkl')
return imgh
def readSR():
return joblib.load('img_h0005.pkl')
def psnr( img1,img2):
mse = np.mean( (img1 - img2) ** 2 )
if mse == 0:
return 100
return 20 * math.log10(np.max(img1) / math.sqrt(mse))
#恢复child图像
def m1():
#加载字典
mat = scipy.io.loadmat('./Dictionary/dictionary.mat')
Dl_dict = np.asarray( mat['Dl'],dtype='float64')
Dh_dict = np.asarray( mat['Dh'],dtype='float64')
#提取出L通道进行计算其他通道使用Bicubic进行计算
#src_rgb_img = io.imread('./Data/Child_input.png')
src_rgb_img = data.lena()
src = src_rgb_img[:src_rgb_img.shape[0]-src_rgb_img.shape[0]%3,:src_rgb_img.shape[1]-src_rgb_img.shape[0]%3,:]
src_rgb_img = src
#需要变称散的倍数才能处理
#src_rgb_img = bicubic_2d.bicubic2d(src,1/3.0)
src_rgb_img = bicubic_2d.bicubic2d(src_rgb_img,1/3.0)
src_rgb_img = src_rgb_img[:src_rgb_img.shape[0]-src_rgb_img.shape[0]%3,:src_rgb_img.shape[1]-src_rgb_img.shape[0]%3,:]
#print src_rgb_img.shape
src_Lab_img = color.rgb2lab(src_rgb_img)
src_Lab_img_L = src_Lab_img[:,:,0]
src_Lab_img_a = src_Lab_img[:,:,1]
src_Lab_img_b = src_Lab_img[:,:,2]
#不同的L通道来源
#dst_Lab_img_L = readSR()
#m = dst_Lab_img_L<0
#dst_Lab_img_L[m] = 0
#print np.max(dst_Lab_img_L),np.min(dst_Lab_img_L)
#dst_Lab_img_L = SR(src_Lab_img_L,Dh_dict,Dl_dict)
dst_Lab_img_L = imresize(src_Lab_img_L,3.0,'bicubic')
#dst_Lab_img_L= dst_Lab_img_L/255.0*(np.max(src_Lab_img_L)-np.min(src_Lab_img_L))+np.min(src_Lab_img_L)
dst_Lab_img_a = imresize(src_Lab_img_a,3.0,'bicubic')
dst_Lab_img_a= dst_Lab_img_a/255.0*(np.max(src_Lab_img_a)-np.min(src_Lab_img_a))+np.min(src_Lab_img_a)
dst_Lab_img_b = imresize(src_Lab_img_b,3.0,'bicubic')
dst_Lab_img_b= dst_Lab_img_b/255.0*(np.max(src_Lab_img_b)-np.min(src_Lab_img_b))+np.min(src_Lab_img_b)
img_lab = np.zeros((dst_Lab_img_L.shape[0],dst_Lab_img_L.shape[1],3))
img_lab[:,:,0] = dst_Lab_img_L
img_lab[:,:,1] = dst_Lab_img_a
img_lab[:,:,2] = dst_Lab_img_b
dst = color.lab2rgb(img_lab)
#src = src[:dst.shape[0],:dst.shape[1]]
#print np.mean(dst[10:-15,10:-15]*255-src[10:-15,10:-15])
#print psnr(dst[10:-15,10:-15]*255,src[10:-15,10:-15])
plt.imshow(dst,interpolation="none")
plt.show()
#回复lena图像并进行比较
def m2():
#加载字典
mat = scipy.io.loadmat('./Dictionary/dictionary.mat')
Dl_dict = np.asarray( mat['Dl'],dtype='float64')
Dh_dict = np.asarray( mat['Dh'],dtype='float64')
#提取出L通道进行计算其他通道使用Bicubic进行计算
src_rgb_img = io.imread('./Data/Child_input.png')
src_yCrCb = colormanage.rgb2ycbcr(src_rgb_img)
src_Ycbcr_img_Y = src_yCrCb[:,:,0]
src_Ycbcr_img_Cb = src_yCrCb[:,:,1]
src_Ycbcr_img_Cr = src_yCrCb[:,:,2]
src_Ycbcr_img_Y = src_Ycbcr_img_Y[:src_yCrCb.shape[0]-src_yCrCb.shape[0]%3,:src_yCrCb.shape[1]-src_yCrCb.shape[1]%3]
src_Ycbcr_img_Cb = src_Ycbcr_img_Cb[:src_yCrCb.shape[0]-src_yCrCb.shape[0]%3,:src_yCrCb.shape[1]-src_yCrCb.shape[1]%3]
src_Ycbcr_img_Cr = src_Ycbcr_img_Cr[:src_yCrCb.shape[0]-src_yCrCb.shape[0]%3,:src_yCrCb.shape[1]-src_yCrCb.shape[1]%3]
#不同的L通道来源
#dst_Lab_img_L = readSR()
#dst_YCbCr_img_Y = SR(src_Ycbcr_img_Y,Dh_dict,Dl_dict)
dst_YCbCr_img_Y = bicubic_2d.bicubic2d(src_Ycbcr_img_Y,3.0)
dst_YCbCr_img_Cb = bicubic_2d.bicubic2d(src_Ycbcr_img_Cb,3.0)
dst_YCbCr_img_Cr = bicubic_2d.bicubic2d(src_Ycbcr_img_Cr,3.0)
img_YCbCr = np.zeros((dst_YCbCr_img_Y.shape[0],dst_YCbCr_img_Y.shape[1],3))
img_YCbCr[:,:,0] = dst_YCbCr_img_Y
img_YCbCr[:,:,1] = dst_YCbCr_img_Cb
img_YCbCr[:,:,2] = dst_YCbCr_img_Cr
dst = colormanage.ycbcr2rgb(img_YCbCr)
joblib.dump(dst,'child_result_bicubic_3x_ycbcr.pkl')
plt.imshow(np.asarray(dst,dtype='uint8'),interpolation="none")
plt.show()
#回复lena图像,尝试在不同的状态下进行比较得到的结果,原始图像是ycbcr空间
import colormanage
def m3():
#加载字典
mat = scipy.io.loadmat('./Dictionary/dictionary.mat')
Dl_dict = np.asarray( mat['Dl'],dtype='float64')
Dh_dict = np.asarray( mat['Dh'],dtype='float64')
#提取出L通道进行计算其他通道使用Bicubic进行计算
src = data.lena()
src_yCrCb = colormanage.rgb2ycbcr(src)
src_Ycbcr_img_Y = bicubic_2d.bicubic2d(src_yCrCb[:,:,0],1/3.0)
src_Ycbcr_img_Cb = bicubic_2d.bicubic2d(src_yCrCb[:,:,1],1/3.0)
src_Ycbcr_img_Cr = bicubic_2d.bicubic2d(src_yCrCb[:,:,2],1/3.0)
没有合适的资源?快使用搜索试试~ 我知道了~
超分辨率算法python源码+项目说明.zip
共144个文件
bmp:92个
pkl:12个
npy:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 41 浏览量
2024-03-15
00:16:58
上传
评论
收藏 40.08MB ZIP 举报
温馨提示
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 超分辨率算法python源码+项目说明.zip超分辨率算法python源码+项目说明.zip 超分辨率算法python源码+项目说明.zip超分辨率算法python源码+项目说明.zip 超分辨率算法python源码+项目说明.zip超分辨率算法python源码+项目说明.zip 超分辨率算法python源码+项目说明.zip超分辨率算法python源码+项目说明.zip 超分辨率算法python源码+项目说明.zip超分辨率算法python源码+项目说明.zip 超分辨率算法python源码+项目说明.zip超分辨率算法python源码+项目说明.zip 超分辨率算法python源码+项目说明.zip超分辨率算法python源码+项目说明.zip
资源推荐
资源详情
资源评论
收起资源包目录
超分辨率算法python源码+项目说明.zip (144个子文件)
tt2.bmp 448KB
tt3.bmp 445KB
tt9.bmp 427KB
tt4.bmp 417KB
tt25.bmp 405KB
tt1.bmp 398KB
tt5.bmp 397KB
tt6.bmp 383KB
tt21.bmp 374KB
tt8.bmp 371KB
tt26.bmp 350KB
t46.bmp 347KB
tt12.bmp 335KB
tt24.bmp 331KB
t37.bmp 305KB
tt13.bmp 286KB
tt27.bmp 277KB
tt23.bmp 265KB
tt20.bmp 260KB
t50.bmp 254KB
t51.bmp 246KB
t49.bmp 237KB
tt10.bmp 236KB
tt17.bmp 233KB
t53.bmp 232KB
t66.bmp 229KB
tt15.bmp 211KB
t59.bmp 209KB
t52.bmp 202KB
t42.bmp 198KB
t40.bmp 195KB
t38.bmp 195KB
t39.bmp 193KB
tt19.bmp 186KB
tt16.bmp 172KB
t55.bmp 169KB
tt22.bmp 159KB
t43.bmp 153KB
tt14.bmp 150KB
t54.bmp 150KB
t63.bmp 145KB
t47.bmp 140KB
tt7.bmp 140KB
t60.bmp 138KB
t48.bmp 132KB
t58.bmp 130KB
t4.bmp 126KB
t15.bmp 124KB
t27.bmp 123KB
t35.bmp 122KB
t25.bmp 122KB
t45.bmp 117KB
t11.bmp 116KB
t62.bmp 115KB
t64.bmp 115KB
t44.bmp 113KB
t36.bmp 111KB
t65.bmp 111KB
t57.bmp 109KB
t61.bmp 109KB
t1.bmp 102KB
t8.bmp 100KB
t31.bmp 99KB
t13.bmp 99KB
t56.bmp 96KB
t19.bmp 94KB
tt18.bmp 94KB
t28.bmp 90KB
t2.bmp 90KB
t6.bmp 88KB
t3.bmp 87KB
t29.bmp 85KB
t32.bmp 85KB
t7.bmp 82KB
t16.bmp 82KB
t33.bmp 80KB
t14.bmp 75KB
t5.bmp 69KB
t17.bmp 68KB
t34.bmp 65KB
t30.bmp 60KB
t22.bmp 58KB
t26.bmp 57KB
t18.bmp 54KB
t10.bmp 54KB
t23.bmp 46KB
t21.bmp 40KB
t12.bmp 40KB
t9.bmp 37KB
t24.bmp 36KB
Girl_input.bmp 22KB
t20.bmp 18KB
.gitattributes 378B
.gitignore 600B
scsr.iml 344B
dictionary.mat 1.68MB
dictionary.mat 1.68MB
.name 4B
lena_result_sc_3x_ycbcr.pkl_01.npy 5.81MB
lena_result_bicubic_3x_ycbcr.pkl_01.npy 5.81MB
共 144 条
- 1
- 2
资源评论
土豆片片
- 粉丝: 1529
- 资源: 5641
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功