-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathimage_inpainting.m
41 lines (38 loc) · 1.37 KB
/
image_inpainting.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
% this script is the entry of the program
%
clear;
clc;
% config
image_path = './test_images/5.jpg';
patch_size = 9;
image_data = im2double(imread(image_path));
% get missing region from user
% missing region point out where the missing pixels are in image
imshow(image_data);
% use mouse to get some coordination by clicking
[x, y] = ginput;
% after clicking, you should press ENTER
% use these coordination to get the target region
target_region = poly2mask(x, y, size(image_data,1), size(image_data, 2));
image_data = image_data.*(1-target_region);
% show the masked image
imshow(image_data);
imwrite(image_data, 'masked_image.jpg');
% init
[image_data, Information] = init(image_data, target_region, patch_size);
% while there are some missing pixels in image, inpaint the image
tic
while ~Information.Boundary.is_empty
% calculate the priority of the patch in boundary, select the patch
% which has the biggest priority to inpaint
[coordinate, Information] = calculate_priority(image_data, Information);
% brute force filling
image_data = brute_force_filling(image_data, coordinate, Information);
% comment the imshow() will speed up the program
imshow(image_data);
% update some infomation which help to inpaint image
Information = update_information(image_data, coordinate, Information);
end
toc
imwrite(image_data, 'image_inpainted.jpg');
imshow(image_data);