📄 inpaint.m
字号:
%This is the high-level function to inpaint an image given an image, a
%mask, and a parameter file. To use default parameters, simply pass
%anything thats not a struct for param, such as param=0.
%
%Param is a structure of structs. Each struct is the parameter struct for
%one of the three parts of the algorithm, decomposition, texture synthesis,
%and structure image inpainting.
%
%An example of param can be seen in the demo.m file
function [out,u,v,U,V] = inpaint(IM, mask, param);
%If no parameter structure passed, use the default parameters...
if sum(class(param) == 'struct') < 6
param = struct('decompose', 0, 'texture', 0, 'structure', 0);
end
IM = double(IM);
mask = logical(mask);
%Artifacts are created along the black regions to be inpainted so I expand
%the mask a little so we can paint over those artifacts
SE = strel('arbitrary', ones(3,3));
mask = imerode(mask, SE);
%If we have a color image, do each channel independently
for i = 1:size(IM,3)
%Decompose the image into its structure and texture components
disp('Decomposing Image...')
[a,b] = decompose_image(IM(:,:,i), param.decompose);
u(:,:,i) = a;
v(:,:,i) = b;
%Fill in the texture region using texture synthesis
disp('Filling in texture...')
B = texture_synth(b, mask, param.texture);
V(:,:,i) = B;
%Fill in the structure region using image inpainting
disp('Performing Inpainting...')
A = structure_inpaint(a, mask, param.structure);
U(:,:,i) = A;
out(:,:,i) = A + B;
end
figure, subplot(2,3,1), imshow(uint8(IM));
subplot(2,3,2), imshow(uint8(u));
subplot(2,3,3), imshow(uint8(150+v));
subplot(2,3,4), imshow(uint8(U+V));
subplot(2,3,5), imshow(uint8(U));
subplot(2,3,6), imshow(uint8(150+V));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -