本文主要是实现论文--基于稀疏表示的图像超分辨率《Image Super-Resolution Via Sparse Representation》中的Figure2。通过对100000个高分辨率和低分辨率图像块训练得到的高分辨率图像块字典,字典原子总数为512,图像块尺寸大小为9X9

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

方法一:

clc;
clear all; % load dictionary
load('Dictionary/D_512_0.15_9.mat'); patch_size=9;
nRow=24;
nCol=22;
D=Dh';
w=nCol*patch_size;
h=nRow*patch_size; gridx = 1:patch_size :w;
gridx = [gridx, w-patch_size+1];
gridy = 1:patch_size : h;
gridy = [gridy, h-patch_size+1];
K=512; %字典原子总数
DD=cell(1,K);
row=length(gridx);
col=length(gridy);
hIm=zeros([w,h]);
for i=1:K
DD{i}=D(i,:);
end for ii = 1:length(gridx),
for jj = 1:length(gridy),
yy = gridx(ii);
xx = gridy(jj);
if (ii-1)*nRow+jj >K
break
end
temp=DD{(ii-1)*nCol+jj};
hPatch=reshape(temp,[patch_size,patch_size]);
hIm(yy:yy+patch_size-1, xx:xx+patch_size-1) = hIm(yy:yy+patch_size-1, xx:xx+patch_size-1) +hPatch;
end
end figure;
imagesc(hIm);
colormap(gray);
axis image;

输出结果:

能够看出,相比于论文中字典的显示图。颜色有点浅,通过调节MATLAB的colorbar,能够将背景颜色变深,

结果例如以下图所看到的:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

方法二:

通过http://www.cs.technion.ac.il/~elad/software/提供的ksvd工具箱中的displayDictionaryElementsAsImage( )函数,来实现字典的显示。

displayDictionaryElementsAsImage.m

function I = displayDictionaryElementsAsImage2(D, numRows, numCols,X,Y,sortVarFlag)
% function I = displayDictionaryElementsAsImage(D, numRows, numCols, X,Y)
% displays the dictionary atoms as blocks. For activation, the dictionary D
% should be given, as also the number of rows (numRows) and columns
% (numCols) for the atoms to be displayed. X and Y are the dimensions of
% each atom. borderSize = 1;
columnScanFlag = 1;
strechEachVecFlag = 1;
showImFlag = 1; if (length(who('X'))==0)
X = 8;
Y = 8;
end
if (length(who('sortVarFlag'))==0)
sortVarFlag = 1;
end numElems = size(D,2);
if (length(who('numRows'))==0)
numRows = floor(sqrt(numElems));
numCols = numRows;
end
if (length(who('strechEachVecFlag'))==0)
strechEachVecFlag = 0;
end
if (length(who('showImFlag'))==0)
showImFlag = 1;
end %%% sort the elements, if necessary.
%%% construct the image to display (I)
sizeForEachImage = sqrt(size(D,1))+borderSize;
I = zeros(sizeForEachImage*numRows+borderSize,sizeForEachImage*numCols+borderSize,3);
%%% fill all this image in blue
I(:,:,1) = 1; %min(min(D));
I(:,:,2) = 1; %min(min(D));
I(:,:,3) = 1; %max(max(D));
% %%% fill all this image in blue
% I(:,:,1) = 0; %min(min(D));
% I(:,:,2) = 0; %min(min(D));
% I(:,:,3) = 1; %max(max(D)); %%% now fill the image squares with the elements (in row scan or column
%%% scan).
if (strechEachVecFlag)
for counter = 1:size(D,2)
D(:,counter) = D(:,counter)-min(D(:,counter));
if (max(D(:,counter)))
D(:,counter) = D(:,counter)./max(D(:,counter));
end
end
end if (sortVarFlag)
vars = var(D);
[V,indices] = sort(vars');
indices = fliplr(indices);
D = [D(:,1:sortVarFlag-1),D(:,indices+sortVarFlag-1)];
signs = sign(D(1,:));
signs(find(signs==0)) = 1;
D = D.*repmat(signs,size(D,1),1);
D = D(:,1:numRows*numCols);
end counter=1;
for j = 1:numRows
for i = 1:numCols
% if (strechEachVecFlag)
% D(:,counter) = D(:,counter)-min(D(:,counter));
% D(:,counter) = D(:,counter)./max(D(:,counter));
% end
% if (columnScanFlag==1)
% I(borderSize+(i-1)*sizeForEachImage+1:i*sizeForEachImage,borderSize+(j-1)*sizeForEachImage+1:j*sizeForEachImage,1)=reshape(D(:,counter),8,8);
% I(borderSize+(i-1)*sizeForEachImage+1:i*sizeForEachImage,borderSize+(j-1)*sizeForEachImage+1:j*sizeForEachImage,2)=reshape(D(:,counter),8,8);
% I(borderSize+(i-1)*sizeForEachImage+1:i*sizeForEachImage,borderSize+(j-1)*sizeForEachImage+1:j*sizeForEachImage,3)=reshape(D(:,counter),8,8);
% else
% Go in Column Scan:
I(borderSize+(j-1)*sizeForEachImage+1:j*sizeForEachImage,borderSize+(i-1)*sizeForEachImage+1:i*sizeForEachImage,1)=reshape(D(:,counter),X,Y);
I(borderSize+(j-1)*sizeForEachImage+1:j*sizeForEachImage,borderSize+(i-1)*sizeForEachImage+1:i*sizeForEachImage,2)=reshape(D(:,counter),X,Y);
I(borderSize+(j-1)*sizeForEachImage+1:j*sizeForEachImage,borderSize+(i-1)*sizeForEachImage+1:i*sizeForEachImage,3)=reshape(D(:,counter),X,Y);
% end
counter = counter+1;
end
end if (showImFlag)
I = I-min(min(min(I)));
I = I./max(max(max(I)));
imshow(I,[]);
end

測试程序

displayDictionary_test.m

clc;
clear all; %载入字典
load('F:\Research\ScSR\ScSR\Dictionary\D_512_0.15_9.mat'); patch_size=9;
D=Dh;
K=512;
figure;
%调用KSVD工具箱中的字典显示函数
im=displayDictionaryElementsAsImage(D, floor(sqrt(K)), floor(size(D,2)/floor(sqrt(K))),patch_size,patch_size);

输出结果:

方法三:

由于方法一显示的字典图像偏灰,对照度不强,所以通过对字典原子像素值进行拉伸变化到0-1。增强图像对照度。

clc;
clear all; % load dictionary
load('Dictionary/D_512_0.15_9.mat'); patch_size=9;
nRow=24;
nCol=22;
D=Dh';
w=nCol*patch_size;
h=nRow*patch_size; gridx = 1:patch_size :w;
gridx = [gridx, w-patch_size+1];
gridy = 1:patch_size : h;
gridy = [gridy, h-patch_size+1];
K=512; %字典原子总数
DD=cell(1,K);
row=length(gridx);
col=length(gridy);
hIm=zeros([w,h]);
for i=1:K
DD{i}=D(i,:);
end for ii = 1:length(gridx),
for jj = 1:length(gridy),
yy = gridx(ii);
xx = gridy(jj);
if (ii-1)*nRow+jj >K
break
end
temp=DD{(ii-1)*nCol+jj};
hPatch=reshape(temp,[patch_size,patch_size]);
I=hPatch;
I = I-min(min(min(I)));
I = I./max(max(max(I)));%对字典原子像素值进行拉伸变化到0-1
hIm(yy:yy+patch_size-1, xx:xx+patch_size-1) = hIm(yy:yy+patch_size-1, xx:xx+patch_size-1) +I;
end
end figure;
imshow(hIm);

调整參数。将字典原子像素值拉伸变换到0-0.7

        hPatch=reshape(temp,[patch_size,patch_size]);
I=hPatch;
I = I-min(min(min(I)));
I = 0.7*I./max(max(max(I)));%对字典原子像素值进行拉伸变化到0-0.7

稀疏表示字典的显示(MATLAB实现代码)的更多相关文章

  1. gvim如何显示html属性代码提示? vim 如何显示 javascript属性及方法提示?

    gvim如何显示html属性代码 可以在vim中 显示 html, css, js等的属性/方法 提示: 一是: 在 ~/.vim/after/syntax/ 目录中 安装 css-color.vim ...

  2. C# WinForm中 让控件全屏显示的实现代码

    夏荣全 ( lyout(at)163.com )原文 C#中让控件全屏显示的实现代码(WinForm) 有时候需要让窗口中某一块的内容全屏显示,比如视频播放.地图等等.经过摸索,暂时发现两种可行方法, ...

  3. Python - 字典(dict) 详解 及 代码

    字典(dict) 详解 及 代码 本文地址: http://blog.csdn.net/caroline_wendy/article/details/17291329 字典(dict)是表示映射的数据 ...

  4. 借助全新 MATLAB® 适配器代码示例读取英特尔® 实感™ 摄像头数据流

    下载源代码请访问原文地址:借助全新 MATLAB® 适配器代码示例读取英特尔® 实感™ 摄像头数据流 简介 该可下载代码示例简要介绍了如何使用英特尔® 实感™ SDK 和 MATLAB 的图像采集工具 ...

  5. 关于Hexo,Next主题的‘下一页’、‘上一页’按钮错误显示为html代码 的解决方法

    关于Next主题的'下一页'.'上一页'按钮错误显示为html代码的解决方法 我在建立自己的博客过程中遇到了页面'下一页'和'上一页'按钮显示为html代码<i class="fa f ...

  6. vs 2010调用matlab dll显示窗口核心代码

    matlab代码: figure('NumberTitle','off','menubar','none','toolbar','none','name','Topo Image'); x=0:pi/ ...

  7. matlab 在代码中,显示错误,退出程序

    使用函数error('message_id', 'message'),出现错误时函数中止运行. 参考http://www.ilovematlab.cn/thread-43261-1-1.html

  8. windows 下 putty 登陆服务器 显示matlab图形界面

    本文需要下载 putty.exe 和 pscp.exe :http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Xming 主 ...

  9. 图片尺寸批量resize的matlab并行代码

    在caffe ImageNet例子中有对图片进行resize的部分,文中使用的是linux shell脚本命令: for name in /path/to/imagenet/val/*.JPEG; d ...

随机推荐

  1. 安卓开发--HttpClient

    package com.zx.httpclient01; import android.app.Activity; import android.os.Bundle; import android.v ...

  2. dedecms实现表单提交数据到指定的邮箱

    1.http://blog.csdn.net/webnoties/article/details/17219219 2.http://www.jz96.com/451.html 3.https://m ...

  3. 工作日志:dispatch_once、网络缓存、分享问题

    问题描述一: 每一个接口对应的model的数据在进入对应的模块(视图)时,执行一次本地缓存加载: 执行缓存加载的实现在基类实现. 解决方案: 将dispatch_once_t设置为成员变量: 问题扩展 ...

  4. Layout Team

    The layout team is a long-term engineering team tasked with maintaining, supporting, and improving t ...

  5. 列表的所有的input,将它的值以键值对的形式存放到一个数组里

    要求的格式 代码块 $('.btn-confirm').on('tap',function(){ var arr={}; var name = $("input[name='insuranc ...

  6. 利用第三方类 phpmailer 发邮件

    第一.百度一下 phpmailer 随便找个 girhub 网站 download 下来即可. 第二.复制如下代码放在项目根目录,填写完整你的账号信息,即可发送邮件.就是这么简单! <?php ...

  7. PostgreSQL指定用户可访问的数据库pg_hba.conf

    进入指定目录: # cd /var/lib/pgsql/9.3/data/ 使用vi编辑pg_hba.conf文件 # vi pg_hba.conf 以上配置为所有IP及网关都允许访问,使用MD5认证 ...

  8. 由防止表单重复提交引发的一系列问题--servletRequest的复制、body值的获取

    @Time:2019年1月4日 16:19:19 @Author:QGuo   背景:最开始打算写个防止表单重复提交的拦截器:网上见到一种不错的方式,比较合适前后端分离,校验在后台实现: 我在此基础上 ...

  9. tload---显示系统负载

    tload命令以图形化的方式输出当前系统的平均负载到指定的终端.假设不给予终端机编号,则会在执行tload指令的终端机显示负载情形. 语法 tload(选项)(参数) 选项 -s:指定闲时的刻度: - ...

  10. numpy基础篇-简单入门教程1

    np.split(A, 4, axis=1),np.hsplit(A, 4) 分割 A = np.arange(12).reshape((3, 4)) # 水平方向的长度是4 print(np.spl ...