⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tvinpaint.m

📁 tv inpainting
💻 M
字号:
function g=TVInpaint(f,mask,liter_num,a)%TVINPAINT inpainting a image using The TV model%reference from the <Modles for Local Non-texture Inpaintings> by Chan and%Shen%date: 2007\11\13%clear all%f1=imread('3ch_original.png');%imshow(f1);%f=im2double(f1);fr=f(:,:,1);fg=f(:,:,2);fb=f(:,:,3);[p,q]=size(fr);f=im2double(f);%g1=imread('3ch_mask.png');%g=mat2gray(im2double(g1));if ~islogical(mask)    mask=im2bw(mask);end[r,s]=find(mask);m=sum(sum(mask));%a is a lifting parameter%a=0.01;%A=['e','s','w','n'];%for n=1:liter_num        for i=1:m                 x=r(i);         y=s(i);         if x==1  x=2;         elseif x==p   x=p-1;         end         if y==1  y=2;         elseif y==q y=q-1;         end         We=1/sqrt((f(x,y+1)-f(x,y))^2+((f(x-1,y)+f(x-1,y+1)-f(x+1,y)-f(x+1,y+1))/4)^2+a^2);         Ws=1/sqrt((f(x+1,y)-f(x,y))^2+((f(x,y+1)+f(x+1,y+1)-f(x,y-1)-f(x+1,y-1))/4)^2+a^2);         Ww=1/sqrt((f(x,y-1)-f(x,y))^2+((f(x-1,y-1)+f(x-1,y)-f(x+1,y-1)-f(x+1,y))/4)^2+a^2);         Wn=1/sqrt((f(x-1,y)-f(x,y))^2+((f(x-1,y+1)+f(x,y+1)-f(x-1,y-1)-f(x,y-1))/4)^2+a^2);         Hop=sum([We,Ws,Ww,Wn]);         Hp=sum([We*f(x,y+1),Ws*f(x+1,y),Ww*f(x,y-1),Wn*f(x-1,y)]);         f(r(i),s(i))=Hp/Hop;                 endend      g=f;     %g=mat2gray(f);     %imwrite(h,'result1.tif');     figure,imshow(g);                                    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -