稀疏表示字典的显示(MATLAB实现代码)
本文主要是实现论文--基于稀疏表示的图像超分辨率《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实现代码)的更多相关文章
- gvim如何显示html属性代码提示? vim 如何显示 javascript属性及方法提示?
gvim如何显示html属性代码 可以在vim中 显示 html, css, js等的属性/方法 提示: 一是: 在 ~/.vim/after/syntax/ 目录中 安装 css-color.vim ...
- C# WinForm中 让控件全屏显示的实现代码
夏荣全 ( lyout(at)163.com )原文 C#中让控件全屏显示的实现代码(WinForm) 有时候需要让窗口中某一块的内容全屏显示,比如视频播放.地图等等.经过摸索,暂时发现两种可行方法, ...
- Python - 字典(dict) 详解 及 代码
字典(dict) 详解 及 代码 本文地址: http://blog.csdn.net/caroline_wendy/article/details/17291329 字典(dict)是表示映射的数据 ...
- 借助全新 MATLAB® 适配器代码示例读取英特尔® 实感™ 摄像头数据流
下载源代码请访问原文地址:借助全新 MATLAB® 适配器代码示例读取英特尔® 实感™ 摄像头数据流 简介 该可下载代码示例简要介绍了如何使用英特尔® 实感™ SDK 和 MATLAB 的图像采集工具 ...
- 关于Hexo,Next主题的‘下一页’、‘上一页’按钮错误显示为html代码 的解决方法
关于Next主题的'下一页'.'上一页'按钮错误显示为html代码的解决方法 我在建立自己的博客过程中遇到了页面'下一页'和'上一页'按钮显示为html代码<i class="fa f ...
- vs 2010调用matlab dll显示窗口核心代码
matlab代码: figure('NumberTitle','off','menubar','none','toolbar','none','name','Topo Image'); x=0:pi/ ...
- matlab 在代码中,显示错误,退出程序
使用函数error('message_id', 'message'),出现错误时函数中止运行. 参考http://www.ilovematlab.cn/thread-43261-1-1.html
- windows 下 putty 登陆服务器 显示matlab图形界面
本文需要下载 putty.exe 和 pscp.exe :http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Xming 主 ...
- 图片尺寸批量resize的matlab并行代码
在caffe ImageNet例子中有对图片进行resize的部分,文中使用的是linux shell脚本命令: for name in /path/to/imagenet/val/*.JPEG; d ...
随机推荐
- GoldenGate 应用系统升级
(仅复制DML时)源端和目标端数据库增减复制表 增加复制表 在GoldenGate的进程参数中,如果通过*来匹配所有表,因此只要符合*所匹配的条件,那么只要在源端建立了表之后GoldenGate就能自 ...
- GoldenGate 1403错误解决方法
OGG oracle goldengate 1403错误解决方法 1. 错误描述WARNING OGG-01154 Oracle GoldenGate Delivery for Oracle, re ...
- C#自定义事件监视变量变化
首先监视定义类 class Event { public delegate void tempChange(object sender, EventArgs e); public event temp ...
- 运维派 企业面试题2 创建10个 "十个随机字母_test.html" 文件
Linux运维必会的实战编程笔试题(19题) 企业面试题2: 使用for循环在/tmp/www目录下通过随机小写10个字母加固定字符串test批量创建10个html文件,名称例如为: --[root@ ...
- javascript实现多线程 Concurrent.Thread.js
在这次我的项目中,因为前端要检测硬件加载并识别,再向后台请求发送数据,然后再返回的相应的配置文件!在这过程,要好时好几秒钟,严重影响体验效果,所以在网上靠看的方案,运用多线程去处理,这效果明显改善! ...
- 苹果下一代iPhone曝光
3月23日消息,据9TO5Mac报道,苹果下一代iPhone(以下暂命名为iPhone 11)可能会提供像三星Galaxy S10的PowerShare功能,能为Apple Watch和AirPods ...
- ImageLoader的简单分析(二)
在<ImageLoader的简单分析>这篇博客中对IImageLoader三大组件的创建过程以及三者之间的关系做了说明.同一时候文章的最后也简单的说明了一下ImageLoader是怎么通过 ...
- HBase源代码分析之HRegion上MemStore的flsuh流程(二)
继上篇<HBase源代码分析之HRegion上MemStore的flsuh流程(一)>之后.我们继续分析下HRegion上MemStore flush的核心方法internalFlushc ...
- Mysql Workbench初体验
可以画图,建立表关系. 分类整理数据表. 可以直接导出sql语句. 可以导出png图片. 可以连接mysql数据库. 基本满足了各项需求. 这次初体验只是基本的功能,这个软件对于mysql还是很牛的.
- Java基本数据类型及字节
1.基本类型可以分为三类,字符类型char,布尔类型boolean以及数值类型byte.short.int.long.float.double.数值类型又可以分为整数类型byte.short.int. ...