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

稀疏表⽰字典的显⽰【MATLAB实现】
本⽂主要是实现论⽂--基于稀疏表⽰的图像分辨率《Image Super-Resolution Via Sparse Representation》中的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);

本文发布于:2024-09-23 12:33:14,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/178277.html

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

标签:图像   结果   字典   分辨率
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议