稀疏表示字典的显示【MATLAB实现】

更新时间:2023-07-08 23:11:47 阅读: 评论:0

稀疏表⽰字典的显⽰【MATLAB实现】
本⽂主要是实现论⽂--基于稀疏表⽰的图像超分辨率《Image Super-Resolution Via Spar Reprentation》中的Figure2,通过对100000个⾼分辨率和低分辨率图像块训练得到的⾼分辨率图像块字典,字典原⼦总数为512,图像块尺⼨⼤⼩为9X9
⽅法⼀:
[cpp]
1. clc;
2. clear all;
3.
4. % load dictionary
5. load('Dictionary/D_512_0.15_9.mat');
6.
7. patch_size=9;
8. nRow=24;
9. nCol=22;
10. D=Dh';
11. w=nCol*patch_size;
12. h=nRow*patch_size;
13.
14. gridx = 1:patch_size :w;
身体的英语怎么写
15. gridx = [gridx, w-patch_size+1];
16. gridy = 1:patch_size : h;
17. gridy = [gridy, h-patch_size+1];
18. K=512; %字典原⼦总数
19. DD=cell(1,K);
20. row=length(gridx);维苏威火山
21. col=length(gridy);
22. hIm=zeros([w,h]);
23. for i=1:K
24.    DD{i}=D(i,:);
25. end
26.
27. for ii = 1:length(gridx),
28. for jj = 1:length(gridy),
29.        yy = gridx(ii);
30.        xx = gridy(jj);
31. if (ii-1)*nRow+jj >K
渴望阳光32. break
33.        end
34.        temp=DD{(ii-1)*nCol+jj};
35.        hPatch=reshape(temp,[patch_size,patch_size]);
36.        hIm(yy:yy+patch_size-1, xx:xx+patch_size-1) = hIm(yy:yy+patch_size-1, xx:xx+patch_size-1) +hPatch;
37.      end
38. end
39.
40. figure;
41. imagesc(hIm);
42. colormap(gray);
43. axis image;
输出结果:
可以看出,相⽐于论⽂中字典的显⽰图,颜⾊有点浅,通过调节MATLAB的colorbar,可以将背景颜⾊变深,结果如下图所⽰:
⽅法⼆:
displayDictionaryElementsAsImage.m
[cpp]
1. function I = displayDictionaryElementsAsImage2(D, numRows, numCols,X,Y,sortVarFlag)
2. % function I = displayDictionaryElementsAsImage(D, numRows, numCols, X,Y)
3. % displays the dictionary atoms as blocks. For activation, the dictionary D
4. % should be given, as also the number of rows (numRows) and columns
4. % should be given, as also the number of rows (numRows) and columns
5. % (numCols) for the atoms to be displayed. X and Y are the dimensions of
6. % each atom.
7.
8. borderSize = 1;
9. columnScanFlag = 1;
10. strechEachVecFlag = 1;
11. showImFlag = 1;
12.
高三励志短句13. if (length(who('X'))==0)
14.    X = 8;
15.    Y = 8;
16. end
17. if (length(who('sortVarFlag'))==0)
数学小论文三年级
18.    sortVarFlag = 1;
19. end
20.
21. numElems = size(D,2);
22. if (length(who('numRows'))==0)
23.    numRows = floor(sqrt(numElems));
24.    numCols = numRows;
25. end
26. if (length(who('strechEachVecFlag'))==0)
教师研修27.    strechEachVecFlag = 0;
28. end
英语书写格式
29. if (length(who('showImFlag'))==0)
30.    showImFlag = 1;
31. end
32.
33. %%% sort the elements, if necessary.
34. %%% construct the image to display (I)
35. sizeForEachImage = sqrt(size(D,1))+borderSize;
36. I = zeros(sizeForEachImage*numRows+borderSize,sizeForEachImage*numCols+borderSize,3);
37. %%% fill all this image in blue
38. I(:,:,1) = 1; %min(min(D));
39. I(:,:,2) = 1; %min(min(D));
40. I(:,:,3) = 1; %max(max(D));
41. % %%% fill all this image in blue
42. % I(:,:,1) = 0; %min(min(D));
43. % I(:,:,2) = 0; %min(min(D));
44. % I(:,:,3) = 1; %max(max(D));
45.
46. %%% now fill the image squares with the elements (in row scan or column
47. %%% scan).
48. if (strechEachVecFlag)
49. for counter = 1:size(D,2)
50.        D(:,counter) = D(:,counter)-min(D(:,counter));
花开的图片51. if (max(D(:,counter)))
52.            D(:,counter) = D(:,counter)./max(D(:,counter));
53.        end
54.    end
55. end
56.
57.
58. if (sortVarFlag)
59.    vars = var(D);

本文发布于:2023-07-08 23:11:47,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1073589.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:图像   结果   字典   分辨率
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图