clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
Case = 2;
bb = 8; % block size
K = 256; % number of atoms in the dictionary
overlap = 3; % number of pixels between consecutive patches
J = 5; % Number of iteration in KSVD
img =imresize(imread('dat.png'),1);
switch Case
%% Interpolation
case 1
Mask = double(~(img(:,:,1)==0));
for channel = 1:3
IMin0 = img(:,:,channel);
IMin0= double(IMin0);
out(:,:,channel) = Interpolation(IMin0,~Mask);
end
imshow(uint8(out))
%% OMP
case 2
[N,M,dim]=size(img);
img = double(img);
NN = ceil((N-bb)/overlap) * overlap + bb;
MM = ceil((M-bb)/overlap) * overlap + bb;
img_new = 255 * zeros(NN,MM,dim);
img_new(1:N,1:M,:) = img;
%imshow(uint8(img_new))
%Compute mask and extracting its patches
Mask = double(~(img_new(:,:,1)==0));
blkMask = overlap_im2col(Mask, bb, overlap);
img_yuv = rgb2ycbcr(uint8(img_new));
img_inpaint_yuv = zeros(size(img_yuv));
% Interpolation CbCr Componet
img_inpaint_yuv(:,:,2) = Interpolation(double(img_yuv(:,:,2)),~Mask);
img_inpaint_yuv(:,:,3) = Interpolation(double(img_yuv(:,:,3)),~Mask);
IMin0 = double(img_yuv(:,:,1));
% The dictionary DCT
DCT=zeros(bb,sqrt(K));
for k=0:1:sqrt(K)-1,
V=cos([0:1:bb-1]'*k*pi/sqrt(K));
if k>0
V=V-mean(V);
end;
DCT(:,k+1)=V/norm(V);
end;
DCT=kron(DCT,DCT);
% Extracting the noisy image patches
blkMatrixIm = overlap_im2col(IMin0, bb, overlap);
sigma = 0.001; % 0.005 0.01
rc_min = 0.01; % rc_min: minimal residual correlation before stopping pursuit
max_coeff = 10; % max_coeff: sparsity constraint for signal representation 10
% Inpainting the Patches (OMP)
Coeff=OMP_Inpainting(DCT,blkMatrixIm.*blkMask,blkMask,sigma,rc_min,max_coeff); %256*146405
Coeff = full(Coeff);
% Creating the output image
imag_Y = overlap_col2im(DCT*Coeff, blkMask, bb, overlap, size(img_new));
imag_Y=max(min(imag_Y,255),0);
img_inpaint_yuv(:,:,1) = imag_Y;
img_inpaint_rgb = ycbcr2rgb(uint8(img_inpaint_yuv));
img_out = img_inpaint_rgb(1:N,1:M,:);
imshow(uint8(img_out))
%% KSVD
case 3
[N,M,dim]=size(img);
img = double(img);
NN = ceil((N-bb)/overlap) * overlap + bb;
MM = ceil((M-bb)/overlap) * overlap + bb;
img_new = 255 * zeros(NN,MM,dim);
img_new(1:N,1:M,:) = img;
%imshow(uint8(img_new))
%Compute mask and extracting its patches
Mask = double(~(img_new(:,:,1)==0));
blkMask = overlap_im2col(Mask, bb, overlap);
img_yuv = rgb2ycbcr(uint8(img_new));
img_inpaint_yuv = zeros(size(img_yuv));
% CbCr Componet Interpolation
img_inpaint_yuv(:,:,2) = Interpolation(double(img_yuv(:,:,2)),~Mask);
img_inpaint_yuv(:,:,3) = Interpolation(double(img_yuv(:,:,3)),~Mask);
IMin0 = double(img_yuv(:,:,1));
% The dictionary DCT
DCT=zeros(bb,sqrt(K));
for k=0:1:sqrt(K)-1,
V=cos([0:1:bb-1]'*k*pi/sqrt(K));
if k>0
V=V-mean(V);
end;
DCT(:,k+1)=V/norm(V);
end;
DCT=kron(DCT,DCT);
% Extracting the noisy image patches
blkMatrixIm = overlap_im2col(IMin0, bb, overlap);
sigma = 0.01; % 0.005 0.01
rc_min = 0.01; % rc_min: minimal residual correlation before stopping pursuit
max_coeff = 10; % max_coeff: sparsity constraint for signal representation 10
% Inpainting the Patches (K-SVD)
[Dict Coeff]=KSVD_Inpainting(DCT,blkMatrixIm,blkMask,sigma,rc_min,max_coeff,J); %DCT
% Creating the output image
imag_Y = overlap_col2im(Dict*Coeff, blkMask, bb, overlap, size(img_new));
imag_Y=max(min(imag_Y,255),0);
img_inpaint_yuv(:,:,1) = imag_Y;
img_inpaint_rgb = ycbcr2rgb(uint8(img_inpaint_yuv));
img_out = img_inpaint_rgb(1:N,1:M,:);
imshow(uint8(img_out))
end


fpga和matlab
- 粉丝: 18w+
- 资源: 2657
最新资源
- 滑坡区受损输电铁塔承载力分析与加固研究(2).docx
- 基于S-变换理论的变压器励磁涌流鉴别的研究开题报告.docx
- 基于超声振动与微量润滑耦合...制的钛合金铣削表面质量研究_戎杰.pdf
- 基于改进TD3算法的无人机轨迹规划_牟文心(1).pdf
- 基于关键断面分析的电网安全校核方法研究.docx
- 基于二维FDTD算法的甚低频电波传播特性分析_李毅.pdf
- 基于改进灰狼优化算法的储能双向变流器控制策略研究_冯良瑞(1).pdf
- 基于深度学习的花卉识别系统的设计与实现任务书.docx
- 基于模糊控制策略的高速列车防滑控制研究_苏超.pdf
- 基于优化EKF的PMSM无位置传感器矢量控制研究_崔鹏龙.pdf
- 履带车辆路径规划与轨迹跟踪控制方法研究_周琳.pdf
- Simulink光伏MPPT模型:遮荫条件下扰动观察法与粒子群优化结果对比,Simulink光伏MPPT模型的扰动观察法与粒子群算法对比研究 图解:模型构建、I-U与P-U曲线分析以及算法结果对比
- 灵活性资源聚合参考模型与量化指标体系.pdf
- 汽车AEB系统行人避撞策略的研究-中期报告(1).docx
- 区域能源互联网“站-网”布局优化研究.pdf
- 面向无线自组网的防窃听和抗干扰通信研究.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


