• 大小: 1.26MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-29
  • 语言: Matlab
  • 标签: MATLAB  CDD  

资源简介

CDD的matlab代码,里面也有处理前和处理后的图像。 用的是lena标准图。下载后注意改代码中图像的相对位置

资源截图

代码片段和文件信息

function [B] = CDDInpainting()
tic;
%t0 = clock;
ImgOriginal=imread(‘Lena1.bmp‘);
figure(1);imshow(ImgOriginal);
[widthheight] = size(ImgOriginal);
Img = double(ImgOriginal);
U = Img;
V = Img;
n = 1;
a=0.0001;
IterTimes=150;
MASK=~(Img>=251); %人为选择阈值
figure(2);imshow(MASK);



while n <= IterTimes
    %更新修复区域内每点值
    for i = 2:width-1
        for j = 2:height-1
            
%             if (MASK(ij+1) == 255)|(MASK(ij-1) == 255)|(MASK(i+1j) == 255)|(MASK(i-1j) == 255)
            if MASK(ij) == 0
                if MASK(ij) == 0
                %计算w1w2w3w4
                gridw2 = (V(ij)-V(i-1j))^2+((V(i-1j-1)-V(i-1j+1))/2)^2;
                gride2 = (V(ij)-V(i+1j))^2+((V(i+1j-1)-V(i+1j+1))/2)^2;
                grids2 = (V(ij)-V(ij-1))^2+((V(i-1j-1)-V(i+1j-1))/2)^2;
                gridn2 = (V(ij)-V(ij+1))^2+((V(i-1j+1)-V(i+1j+1))/2)^2;
                a1 = 1/sqrt(gridw2+a);
                a2 = 1/sqrt(gride2+a);
                a3 = 1/sqrt(grids2+a);
                a4 = 1/sqrt(gridn2+a);
              k =(a1*V(i-1j)+a2*V(i+1j)+a3*V(ij+1)+a4*V(ij-1))/(a1+a2+a3+a4);
            end
                %计算w1w2w3w4
                gridUw2 = (V(ij)-V(i-1j))^2+((V(i-1j-1)-V(i-1j+1))/2)^2;
                gridUe2 = (V(ij)-V(i+1j))^2+((V(i+1j-1)-V(i+1j+1))/2)^2;
                gridUs2 = (V(ij)-V(ij-1))^2+((V(i-1j-1)-V(i+1j-1))/2)^2;
                gridUn2 = (V(ij)-V(ij+1))^2+((V(i-1j+1)-V(i+1j+1))/2)^2;
                w1 = k/sqrt(gridUw2+a);
                w2 = k/sqrt(gridUe2+a);
                w3 = k/sqrt(gridUs2+a);
                w4 = k/sqrt(gridUn2+a);
               U(ij) =(w1*V(i-1j)+w2*V(i+1j)+w3*V(ij+1)+w4*V(ij-1))/(w1+w2+w3+w4);
            end
        end
    end
    n = n+1;
    V = U;
end
D = floor(V);
figure(3);imshow(D[]);

 inpaintedImg=double(D);
% origImg=double(ImgOriginal);
% % fill_mse=mse(origImg(fill(:))-inpaintedImg(fill(:)))
% fill_all=mse(origImg-inpaintedImg)
% psnr_img=10*log10(255^2/fill_all)

origImg=double(imread(‘Lena.bmp‘));

% fill_mse=mse(origImg(fill(:))-inpaintedImg(fill(:)))

fill_all=mse(origImg-inpaintedImg)

fill_all_before=mse(origImg-double(ImgOriginal))
psnr_img=10*log10(255^2/fill_all)
toc;
%etime(clockt0)
%imwrite(uint8(D)‘inpainted.bmp‘);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2369  2010-12-17 13:37  CDD\CDDgray.m

     文件       5723  2010-12-17 13:37  CDD\CDDRGB.m

     文件     263224  2010-12-17 13:37  CDD\Lena.bmp

     文件     263222  2010-12-17 13:37  CDD\Lena1.bmp

     文件     263222  2010-12-17 13:37  CDD\Lena2.bmp

     文件     263222  2010-12-17 13:37  CDD\Lena3.bmp

     文件     263222  2010-12-17 13:37  CDD\Lena4.bmp

     文件     263222  2010-12-17 13:37  CDD\Lena5.bmp

     文件     263222  2010-12-17 13:37  CDD\Lena6.bmp

     文件     274262  2010-12-17 13:37  CDD\Lincoln2.bmp

    ..A.SH.     42496  2010-12-17 14:04  CDD\Thumbs.db

     目录          0  2010-12-17 14:04  CDD

----------- ---------  ---------- -----  ----

              2167406                    12


评论

共有 条评论