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
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1.版本:matlab2021a,包含程序仿真操作录像,可以跟着操作出仿真结果 2.领域:图像修复算法 3.内容:基于matlab图像修复算法仿真,对比插值,OMP以及KSVD三种算法+仿真录像,输出三种算法的图像修复结果。
资源推荐
资源详情
资源评论
收起资源包目录
基于matlab图像修复算法仿真,对比插值,OMP以及KSVD三种算法.rar (12个子文件)
基于matlab图像修复算法仿真,对比插值,OMP以及KSVD三种算法
untitled.jpg 122KB
matlab
dat.png 645KB
func
KSVD_Inpainting.m 881B
Interpolation.m 288B
overlap_im2col.m 362B
overlap_col2im.m 1KB
ImageRecover.m 414B
RMS.m 73B
OMP_Inpainting.m 982B
PSNR.m 88B
runme.m 4KB
操作录像0034.avi 50.97MB
共 12 条
- 1
资源评论
- 追风00682024-05-06感谢资源主的分享,这个资源对我来说很有用,内容描述详尽,值得借鉴。
fpga和matlab
- 粉丝: 17w+
- 资源: 2629
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功