24 |
25 | #ifndef MAX
26 | #define MAX(a, b) ((a)>(b)?(a):(b))
27 | #define MIN(a, b) ((a)<(b)?(a):(b))
28 | #endif
29 |
30 | /* -------------------------------------------------------------------------
31 | BITMAP: Minimal image class
32 | ------------------------------------------------------------------------- */
33 |
34 | class BITMAP { public:
35 | int w, h;
36 | int *data;
37 | BITMAP(int w_, int h_) :w(w_), h(h_) { data = new int[w*h]; }
38 | ~BITMAP() { delete[] data; }
39 | int *operator[](int y) { return &data[y*w]; }
40 | };
41 |
42 | void check_im() {
43 | int i;
44 | i = system("identify ../test-images/test1.jpg");
45 | printf ("The value returned was: %d.\n",i);
46 | if (i != 0) {
47 | fprintf(stderr, "ImageMagick must be installed, and 'convert' and 'identify' must be in the path\n"); exit(1);
48 | }
49 | }
50 |
51 | BITMAP *load_bitmap(const char *filename) {
52 | check_im();
53 | char rawname[256], txtname[256];
54 | strcpy(rawname, filename);
55 | strcpy(txtname, filename);
56 | if (!strstr(rawname, ".")) { fprintf(stderr, "Error reading image '%s': no extension found\n", filename); exit(1); }
57 | sprintf(strstr(rawname, "."), ".raw");
58 | sprintf(strstr(txtname, "."), ".txt");
59 | char buf[256];
60 | sprintf(buf, "convert %s rgba:%s", filename, rawname);
61 | if (system(buf) != 0) { fprintf(stderr, "Error reading image '%s': ImageMagick convert gave an error\n", filename); exit(1); }
62 | sprintf(buf, "identify -format \"%%w %%h\" %s > %s", filename, txtname);
63 | if (system(buf) != 0) { fprintf(stderr, "Error reading image '%s': ImageMagick identify gave an error\n", filename); exit(1); }
64 | FILE *f = fopen(txtname, "rt");
65 | if (!f) { fprintf(stderr, "Error reading image '%s': could not read output of ImageMagick identify\n", filename); exit(1); }
66 | int w = 0, h = 0;
67 | if (fscanf(f, "%d %d", &w, &h) != 2) { fprintf(stderr, "Error reading image '%s': could not get size from ImageMagick identify\n", filename); exit(1); }
68 | fclose(f);
69 | printf("(w, h) = (%d, %d)\n", w, h);
70 | f = fopen(rawname, "rb");
71 | BITMAP *ans = new BITMAP(w, h);
72 | unsigned char *p = (unsigned char *) ans->data;
73 | for (int i = 0; i < w*h*4; i++) {
74 | int ch = fgetc(f);
75 | if (ch == EOF) { fprintf(stderr, "Error reading image '%s': raw file is smaller than expected size %dx%dx%d\n", filename, w, h, 4); exit(1); }
76 | *p++ = ch;
77 | }
78 | fclose(f);
79 | return ans;
80 | }
81 |
82 | void save_bitmap(BITMAP *bmp, const char *filename) {
83 | check_im();
84 | char rawname[256];
85 | strcpy(rawname, filename);
86 | if (!strstr(rawname, ".")) { fprintf(stderr, "Error writing image '%s': no extension found\n", filename); exit(1); }
87 | sprintf(strstr(rawname, "."), ".raw");
88 | char buf[256];
89 | //printf("rawname = %s\n", rawname);
90 | FILE *f = fopen(rawname, "wb");
91 | if (!f) { fprintf(stderr, "Error writing image '%s': could not open raw temporary file\n", filename); exit(1); }
92 | unsigned char *p = (unsigned char *) bmp->data;
93 | for (int i = 0; i < bmp->w*bmp->h*4; i++) {
94 | fputc(*p++, f);
95 | }
96 | fclose(f);
97 | sprintf(buf, "convert -size %dx%d -depth 8 rgba:%s %s", bmp->w, bmp->h, rawname, filename);
98 | //printf("system returned value = %d\n", system(buf));
99 | if (system(buf) != 0) { fprintf(stderr, "Error writing image '%s': ImageMagick convert gave an error\n", filename); exit(1); }
100 | }
101 |
102 | /* -------------------------------------------------------------------------
103 | PatchMatch, using L2 distance between upright patches that translate only
104 | ------------------------------------------------------------------------- */
105 |
106 | int patch_w = 7;
107 | int pm_iters = 1;
108 | int rs_max = INT_MAX; // random search
109 |
110 | #define XY_TO_INT(x, y) (((y)<<12)|(x))
111 | #define INT_TO_X(v) ((v)&((1<<12)-1))
112 | #define INT_TO_Y(v) ((v)>>12)
113 |
114 |
115 | void reconstruct(BITMAP *a, BITMAP *b, BITMAP *ann, BITMAP *&ans);
116 |
117 | /* Measure distance between 2 patches with upper left corners (ax, ay) and (bx, by), terminating early if we exceed a cutoff distance.
118 | You could implement your own descriptor here. */
119 | int dist(BITMAP *a, BITMAP *b, int ax, int ay, int bx, int by, int cutoff=INT_MAX) {
120 | int ans = 0;
121 | for (int dy = 0; dy < patch_w; dy++) {
122 | int *arow = &(*a)[ay+dy][ax];
123 | int *brow = &(*b)[by+dy][bx];
124 | for (int dx = 0; dx < patch_w; dx++) {
125 | int ac = arow[dx];
126 | int bc = brow[dx];
127 | int dr = (ac&255)-(bc&255);
128 | int dg = ((ac>>8)&255)-((bc>>8)&255);
129 | int db = (ac>>16)-(bc>>16);
130 | ans += dr*dr + dg*dg + db*db;
131 | }
132 | if (ans >= cutoff) { return cutoff; }
133 | }
134 | return ans;
135 | }
136 |
137 | void improve_guess(BITMAP *a, BITMAP *b, int ax, int ay, int &xbest, int &ybest, int &dbest, int bx, int by) {
138 | int d = dist(a, b, ax, ay, bx, by, dbest);
139 | if (d < dbest) {
140 | dbest = d;
141 | xbest = bx;
142 | ybest = by;
143 | }
144 | }
145 |
146 | /* Match image a to image b, returning the nearest neighbor field mapping a => b coords, stored in an RGB 24-bit image as (by<<12)|bx. */
147 | void patchmatch(BITMAP *a, BITMAP *b, BITMAP *&ann, BITMAP *&annd) {
148 | /* Initialize with random nearest neighbor field (NNF). */
149 | ann = new BITMAP(a->w, a->h);
150 | annd = new BITMAP(a->w, a->h);
151 | int aew = a->w - patch_w+1, aeh = a->h - patch_w + 1; /* Effective width and height (possible upper left corners of patches). */
152 | int bew = b->w - patch_w+1, beh = b->h - patch_w + 1;
153 | memset(ann->data, 0, sizeof(int)*a->w*a->h);
154 | memset(annd->data, 0, sizeof(int)*a->w*a->h);
155 |
156 | // Initialization
157 | for (int ay = 0; ay < aeh; ay++) {
158 | for (int ax = 0; ax < aew; ax++) {
159 | int bx = rand()%bew;
160 | int by = rand()%beh;
161 | (*ann)[ay][ax] = XY_TO_INT(bx, by);
162 | (*annd)[ay][ax] = dist(a, b, ax, ay, bx, by);
163 | }
164 | }
165 |
166 | for (int iter = 0; iter < pm_iters; iter++) {
167 | printf("iter = %d\n", iter);
168 | /* In each iteration, improve the NNF, by looping in scanline or reverse-scanline order. */
169 | int ystart = 0, yend = aeh, ychange = 1;
170 | int xstart = 0, xend = aew, xchange = 1;
171 | if (iter % 2 == 1) {
172 | xstart = xend-1; xend = -1; xchange = -1;
173 | ystart = yend-1; yend = -1; ychange = -1;
174 | }
175 | for (int ay = ystart; ay != yend; ay += ychange) {
176 | for (int ax = xstart; ax != xend; ax += xchange) {
177 | /* Current (best) guess. */
178 | int v = (*ann)[ay][ax];
179 | int xbest = INT_TO_X(v), ybest = INT_TO_Y(v);
180 | int dbest = (*annd)[ay][ax];
181 |
182 | /* Propagation: Improve current guess by trying instead correspondences from left and above (below and right on odd iterations). */
183 | if ((unsigned) (ax - xchange) < (unsigned) aew) {
184 | int vp = (*ann)[ay][ax-xchange];
185 | int xp = INT_TO_X(vp) + xchange, yp = INT_TO_Y(vp);
186 | if ((unsigned) xp < (unsigned) bew) {
187 | improve_guess(a, b, ax, ay, xbest, ybest, dbest, xp, yp);
188 | }
189 | }
190 |
191 | if ((unsigned) (ay - ychange) < (unsigned) aeh) {
192 | int vp = (*ann)[ay-ychange][ax];
193 | int xp = INT_TO_X(vp), yp = INT_TO_Y(vp) + ychange;
194 | if ((unsigned) yp < (unsigned) beh) {
195 | improve_guess(a, b, ax, ay, xbest, ybest, dbest, xp, yp);
196 | }
197 | }
198 |
199 | /* Random search: Improve current guess by searching in boxes of exponentially decreasing size around the current best guess. */
200 | int rs_start = rs_max;
201 | if (rs_start > MAX(b->w, b->h)) { rs_start = MAX(b->w, b->h); }
202 | for (int mag = rs_start; mag >= 1; mag /= 2) {
203 | /* Sampling window */
204 | int xmin = MAX(xbest-mag, 0), xmax = MIN(xbest+mag+1,bew);
205 | int ymin = MAX(ybest-mag, 0), ymax = MIN(ybest+mag+1,beh);
206 | int xp = xmin+rand()%(xmax-xmin);
207 | int yp = ymin+rand()%(ymax-ymin);
208 | improve_guess(a, b, ax, ay, xbest, ybest, dbest, xp, yp);
209 | }
210 |
211 | (*ann)[ay][ax] = XY_TO_INT(xbest, ybest);
212 | (*annd)[ay][ax] = dbest;
213 | }
214 | }
215 |
216 | // try to reconstruct at every iter
217 | /*
218 | BITMAP *r = NULL;
219 | reconstruct(a, b, ann, r);
220 | std::stringstream ss;
221 | ss << iter;
222 | std::string r_file = "a_recons_iter_" + ss.str() + ".jpg";
223 | const char* r_ptr = r_file.c_str();
224 | save_bitmap(r, r_ptr);
225 | */
226 | }
227 | }
228 |
229 | BITMAP *norm_image(double *accum, int w, int h, BITMAP *ainit=NULL) {
230 | BITMAP *ans = new BITMAP(w, h);
231 | for (int y = 0; y < h; y++) {
232 | int *row = (*ans)[y];
233 | int *arow = NULL;
234 | if (ainit)
235 | arow = (*ainit)[y];
236 | double *prow = &accum[4*(y*w)];
237 | for (int x = 0; x < w; x++) {
238 | double *p = &prow[4*x];
239 | int c = p[3] ? p[3]: 1;
240 | int c2 = c>>1; /* Changed: round() instead of floor. */
241 | if (ainit)
242 | row[x] = p[3] ? int((p[0]+c2)/c)|(int((p[1]+c2)/c)<<8)|(int((p[2]+c2)/c)<<16)|(255<<24) : arow[x];
243 | else
244 | row[x] = int((p[0]+c2)/c)|(int((p[1]+c2)/c)<<8)|(int((p[2]+c2)/c)<<16)|(255<<24);
245 | }
246 | }
247 | return ans;
248 | }
249 |
250 | void reconstruct(BITMAP *a, BITMAP *b, BITMAP *ann, BITMAP *&ans) {
251 |
252 | int sz = a->w*a->h; sz = sz << 2; // 4*w*h
253 | double* accum = new double[sz];
254 | memset(accum, 0, sizeof(double)*sz );
255 |
256 | for (int ay = 0; ay < a->h - patch_w + 1; ay++) {
257 | for (int ax = 0; ax < a->w - patch_w + 1; ax++) {
258 | int vp = (*ann)[ay][ax];
259 | int xp = INT_TO_X(vp), yp = INT_TO_Y(vp);
260 | for (int dy = 0; dy < patch_w; dy++) {
261 | int* brow = (*b)[yp+dy] + xp;
262 | double* prow = &accum[4*((ay+dy)*a->w + ax)];
263 | for(int dx = 0; dx < patch_w; dx++) {
264 | int c = brow[dx];
265 | double* p = &prow[4*dx];
266 | p[0] += (c&255);
267 | p[1] += ((c>>8)&255);
268 | p[2] += ((c>>16)&255);
269 | p[3] += 1;
270 | }
271 | }
272 | }
273 | }
274 | ans = norm_image(accum, a->w, a->h, NULL);
275 | }
276 |
277 |
278 | int main(int argc, char *argv[]) {
279 | argc--;
280 | argv++;
281 | if (argc != 4) { fprintf(stderr, "pm_minimal a b ann annd\n"
282 | "Given input images a, b outputs nearest neighbor field 'ann' mapping a => b coords, and the squared L2 distance 'annd'\n"
283 | "These are stored as RGB 24-bit images, with a 24-bit int at every pixel. For the NNF we store (by<<12)|bx."); exit(1); }
284 | printf("(1) Loading input images\n");
285 | BITMAP *a = load_bitmap(argv[0]);
286 | BITMAP *b = load_bitmap(argv[1]);
287 | BITMAP *ann = NULL, *annd = NULL;
288 | printf("\n(2) Running PatchMatch\n");
289 | patchmatch(a, b, ann, annd);
290 | printf("\n(3) Saving output images: ann & annd\n");
291 | save_bitmap(ann, argv[2]);
292 | save_bitmap(annd, argv[3]);
293 |
294 | // Reconstruct image based on ann
295 | printf("\n(4) Reconstructibg an image for the source image\n");
296 | BITMAP *r = NULL;
297 | reconstruct(a, b, ann, r);
298 | save_bitmap(r, "a_restructed.jpg");
299 |
300 | return 0;
301 | }
302 |
--------------------------------------------------------------------------------
/gui/PatchMatch.fig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/gui/PatchMatch.fig
--------------------------------------------------------------------------------
/gui/PatchMatch.m:
--------------------------------------------------------------------------------
1 | function varargout = PatchMatch(varargin)
2 | % PATCHMATCH MATLAB code for PatchMatch.fig
3 | % PATCHMATCH, by itself, creates a new PATCHMATCH or raises the existing
4 | % singleton*.
5 | %
6 | % H = PATCHMATCH returns the handle to a new PATCHMATCH or the handle to
7 | % the existing singleton*.
8 | %
9 | % PATCHMATCH('CALLBACK',hObject,eventData,handles,...) calls the local
10 | % function named CALLBACK in PATCHMATCH.M with the given input arguments.
11 | %
12 | % PATCHMATCH('Property','Value',...) creates a new PATCHMATCH or raises the
13 | % existing singleton*. Starting from the left, property value pairs are
14 | % applied to the GUI before PatchMatch_OpeningFcn gets called. An
15 | % unrecognized property name or invalid value makes property application
16 | % stop. All inputs are passed to PatchMatch_OpeningFcn via varargin.
17 | %
18 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
19 | % instance to run (singleton)".
20 | %
21 | % See also: GUIDE, GUIDATA, GUIHANDLES
22 |
23 | % Edit the above text to modify the response to help PatchMatch
24 |
25 | % Last Modified by GUIDE v2.5 04-Apr-2018 00:26:10
26 |
27 | % Begin initialization code - DO NOT EDIT
28 |
29 |
30 | gui_Singleton = 1;
31 | gui_State = struct('gui_Name', mfilename, ...
32 | 'gui_Singleton', gui_Singleton, ...
33 | 'gui_OpeningFcn', @PatchMatch_OpeningFcn, ...
34 | 'gui_OutputFcn', @PatchMatch_OutputFcn, ...
35 | 'gui_LayoutFcn', [] , ...
36 | 'gui_Callback', []);
37 | if nargin && ischar(varargin{1})
38 | gui_State.gui_Callback = str2func(varargin{1});
39 | end
40 |
41 | if nargout
42 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
43 | else
44 | gui_mainfcn(gui_State, varargin{:});
45 | end
46 | % End initialization code - DO NOT EDIT
47 |
48 |
49 | % --- Executes just before PatchMatch is made visible.
50 | function PatchMatch_OpeningFcn(hObject, eventdata, handles, varargin)
51 | % This function has no output args, see OutputFcn.
52 | % hObject handle to figure
53 | % eventdata reserved - to be defined in a future version of MATLAB
54 | % handles structure with handles and user data (see GUIDATA)
55 | % varargin command line arguments to PatchMatch (see VARARGIN)
56 | global img;
57 | global msk;
58 | global mskcol;
59 | global wbmFlg;
60 | global point0;
61 | global drawFlg;
62 | global pnSize;
63 | global imSize;
64 | global viewMode;
65 |
66 | img = [];
67 | msk = [];
68 | mskcol = [0 0 0];
69 | wbmFlg = 0;
70 | point0 = [];
71 | drawFlg = -1;
72 | imSize = [];
73 | pnSize = 5;
74 | viewMode = 1;
75 | % Choose default command line output for PatchMatch
76 | handles.output = hObject;
77 |
78 | % Update handles structure
79 | guidata(hObject, handles);
80 |
81 | %set(hObject,...
82 | %'WindowButtonMotionFcn',{@uipanel1_ButtonMotionFcn},...
83 | %'WindowButtonUpFcn',{@uipanel1_ButtonUpFcn},...
84 | %'WindowButtonDownFcn',{@uipanel1_ButtonDownFcn});
85 |
86 | % UIWAIT makes PatchMatch wait for user response (see UIRESUME)
87 | % uiwait(handles.figure1);
88 |
89 |
90 | % --- Outputs from this function are returned to the command line.
91 | function varargout = PatchMatch_OutputFcn(hObject, eventdata, handles)
92 | % varargout cell array for returning output args (see VARARGOUT);
93 | % hObject handle to figure
94 | % eventdata reserved - to be defined in a future version of MATLAB
95 | % handles structure with handles and user data (see GUIDATA)
96 |
97 | % Get default command line output from handles structure
98 | varargout{1} = handles.output;
99 |
100 |
101 | function uipanel1_ButtonDownFcn(hObject, eventdata, handles)
102 | % hObject handle to figure1 (see GCBO)
103 | % eventdata reserved - to be defined in a future version of MATLAB
104 | % handles structure with handles and user data (see GUIDATA)
105 |
106 | % --- Executes on button press in pushbutton1.
107 | function pushbutton1_Callback(hObject, eventdata, handles)
108 | % hObject handle to pushbutton1 (see GCBO)
109 | % eventdata reserved - to be defined in a future version of MATLAB
110 | % handles structure with handles and user data (see GUIDATA)
111 |
112 | global filename;
113 | global dir;
114 | [filename, dir] = uigetfile( '*.*', 'Load Image');
115 |
116 | global img;
117 | global msk;
118 | global imSize;
119 |
120 | img = imread([dir filename]);
121 | imSize = size(img);
122 | msk = zeros(imSize(1),imSize(2),'uint8');
123 | axes(handles.uipanel1);
124 | imshow(img);
125 |
126 |
127 |
128 |
129 | function edit1_Callback(hObject, eventdata, handles)
130 | % hObject handle to edit1 (see GCBO)
131 | % eventdata reserved - to be defined in a future version of MATLAB
132 | % handles structure with handles and user data (see GUIDATA)
133 |
134 | % Hints: get(hObject,'String') returns contents of edit1 as text
135 | % str2double(get(hObject,'String')) returns contents of edit1 as a double
136 |
137 |
138 | % --- Executes during object creation, after setting all properties.
139 | function edit1_CreateFcn(hObject, eventdata, handles)
140 | % hObject handle to edit1 (see GCBO)
141 | % eventdata reserved - to be defined in a future version of MATLAB
142 | % handles empty - handles not created until after all CreateFcns called
143 |
144 | % Hint: edit controls usually have a white background on Windows.
145 | % See ISPC and COMPUTER.
146 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
147 | set(hObject,'BackgroundColor','white');
148 | end
149 |
150 |
151 | % --- Executes during object creation, after setting all properties.
152 | function pushbutton1_CreateFcn(hObject, eventdata, handles)
153 | % hObject handle to pushbutton1 (see GCBO)
154 | % eventdata reserved - to be defined in a future version of MATLAB
155 | % handles empty - handles not created until after all CreateFcns called
156 |
157 |
158 | % --- Executes on mouse press over figure background, over a disabled or
159 | % --- inactive control, or over an axes background.
160 | function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
161 | % hObject handle to figure1 (see GCBO)
162 | % eventdata reserved - to be defined in a future version of MATLAB
163 | % handles structure with handles and user data (see GUIDATA)
164 | global drawFlg;
165 | global point0;
166 |
167 | mouse = get(gcf,'SelectionType');
168 | if( strcmpi( mouse, 'normal' ) )
169 | drawFlg = 1;
170 | point0 = getPixelPosition();
171 |
172 | elseif( strcmpi( mouse, 'alt' ) )
173 | drawFlg = 0;
174 | point0 = getPixelPosition();
175 |
176 | else
177 | drawFlg = -1;
178 | end
179 |
180 |
181 | % --- Executes on mouse motion over figure - except title and menu.
182 | function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
183 | % hObject handle to figure1 (see GCBO)
184 | % eventdata reserved - to be defined in a future version of MATLAB
185 | % handles structure with handles and user data (see GUIDATA)
186 | global pnSize;
187 | global imSize;
188 | global msk;
189 | global point0;
190 | global drawFlg;
191 |
192 | global wbmFlg;
193 |
194 | if( wbmFlg == 0 && drawFlg >= 0 )
195 | wbmFlg = 1;
196 |
197 | point1 = getPixelPosition()
198 |
199 | if( ~isempty( point0 ) )
200 | ps = pnSize / 480 * max([imSize(1),imSize(2)]);
201 | msk = drawLine( msk, point0, point1, ps, drawFlg );
202 | showImageMask(handles.uipanel1);
203 | end
204 |
205 | point0 = point1;
206 |
207 | wbmFlg = 0;
208 | end
209 |
210 |
211 | % --- Executes on mouse press over figure background, over a disabled or
212 | % --- inactive control, or over an axes background.
213 | function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
214 | % hObject handle to figure1 (see GCBO)
215 | % eventdata reserved - to be defined in a future version of MATLAB
216 | % handles structure with handles and user data (see GUIDATA)
217 | global drawFlg;
218 | global point0;
219 | drawFlg = -1;
220 | point0 = [];
221 |
222 | function point = getPixelPosition()
223 | global imSize;
224 |
225 | if( isempty( imSize ) )
226 | point = [];
227 | else
228 | cp = get (gca, 'CurrentPoint');
229 | cp = cp(1,1:2);
230 | row = int32(round( axes2pix(imSize(1), [1 imSize(1)], cp(2)) ));
231 | col = int32(round( axes2pix(imSize(2), [1 imSize(2)], cp(1)) ));
232 |
233 | point = [row col];
234 | end
235 |
236 |
237 | % --- Executes on button press in pushbutton2.
238 | function pushbutton2_Callback(hObject, eventdata, handles)
239 | % hObject handle to pushbutton2 (see GCBO)
240 | % eventdata reserved - to be defined in a future version of MATLAB
241 | % handles structure with handles and user data (see GUIDATA)
242 | global filename;
243 | global dir;
244 | global img;
245 | global msk;
246 | global mskcol;
247 |
248 | [d name ext] = fileparts(filename);
249 |
250 | msk = uint8(msk*255);
251 | maskimage = double(img).*double(repmat(~msk,1,1,3));
252 | imwrite( uint8(maskimage), [dir name '_img.png'] );
253 | imwrite( uint8(msk), [dir name '_msk.png'] );
254 |
255 | function [] = showImageMask(handle)
256 | global img;
257 | global msk;
258 | global mskcol;
259 | global viewMode;
260 |
261 | if( ~isempty(img) )
262 | switch( viewMode )
263 | case 1
264 | maskimage = genImageMask( single(img), single(msk), single(mskcol) );
265 | case 2
266 | maskimage = reshape( mskcol, [1 1 3] );
267 | maskimage = single(repmat( maskimage, [size(msk,1), size(msk,2), 1] )) .* single(repmat( msk, [1 1 3] ));
268 | case 3
269 | maskimage = img;
270 | otherwise
271 | maskimage = zeros(size(msk));
272 | end
273 | axes(handle);
274 | imshow(uint8(maskimage));
275 | end
276 |
--------------------------------------------------------------------------------
/gui/Untitled Document:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/gui/Untitled Document
--------------------------------------------------------------------------------
/index.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 |
4 |
5 | Image/Video editing tools and applications have been widely used in many areas, including marketing, fashion design, and film production. Among these applications, we are especially interested in Image Completion, and think it is an important function. Why is Image Completion important? Actually, it is very useful for lots of purposes. No matter it’s for everyday photo or movie post-processing, it can help you remove objects you don’t want (see Fig1 and Fig2).
6 |
7 |
8 |
9 |
10 |
11 |

12 |
Figure 1: Everyday Photo
13 |

14 |
Figure 2: Movie Post-Processing
15 |
16 |
17 |
18 | # State-of-the-Art
19 |
20 |
21 |
22 | We survey the literature works. The latest one is from SIGGRAPH 2017 (see Fig3), which is based on deep neural network.
23 |
24 |
25 |
26 |
27 |
28 |

29 |
Figure 3: Deep convolutional neural networks [1]
30 |
31 |
32 |
33 |
34 |
35 | Although this work is very powerful, it may still fail in some cases (see Fig4). We also find other problems with this model. Usually, It takes lots of time and images to train a model. Also, it doesn’t provide an interactive way for users to improve results if they are not good enough.
36 |
37 |
38 |
39 |
40 |
41 |

42 |
Figure 4: Failed case in [1]
43 |
44 |
45 |
46 | # Adobe Photoshop: Content Aware Fill (PatchMatch)
47 |
48 |
49 |
50 | Thus, we’re more interested in what’s the industry solution for this problem since we usually ask for a higher standard of image quality provided by those market products. We find that Adobe Photoshop also has this function which is called Content Aware Fill (see Fig5) using PatchMatch algorithm [2]. So, we try to find some insights from this algorithm.
51 |
52 |
53 |
54 |
55 |
56 |

57 |
Figure 5: Adobe Photoshop: Content Aware Fill
58 |
59 |
60 |
61 | # PatchMatch
62 | ## Algorithm
63 |
64 |
65 |
66 | The purpose of the PatchMatch algorithm is to efficiently find the similar patches between two images. Basically, its algorithm contains three steps: random initlization, propagation, and random search (see Fig6).
67 |
68 |
69 |
70 |
71 |
72 |

73 |
Figure 6: PatchMatch Algorithm
74 |
75 |
76 |
77 |
78 |
79 | Take Fig7 as example. For each patch in A, we try to find a similar patch in B. In the fist step, we randomly match each patch in A with a patch in B. If we’re lucky, we may get some pairs already similar enough. Then, in the second step, we check if our neighbors can give us a better candidate patch. If it is, we just propagate this benefit, i.e., just update the patch. In the final step, we continue looking for a better patch in our neighborhood by random search in order to get out of a local optimum.
80 |
81 |
82 |
83 |
84 |
85 |

86 |
Figure 7: Example of PatchMatch Algorithm
87 |
88 |
89 |
90 | ## Simulation Result
91 |
92 |
93 |
94 | Here is the simulation results (see Fig8). You can see how fast this algorithm is. Even for the first iteration, we can almost reconstruct the image just using pixels from B. Then, after that, each iteration just gets the result sharper and sharper.
95 |
96 |
97 |
98 |
99 |
100 |

101 |
Figure 8: Simulation Results of Different Iterations
102 |
103 |
104 |
105 |
106 |
107 | In addition to the subjective evaluation, we also calculate its SNR score, which shows how similar two images look like. According to the SNR formula below, we calculate 27.860412 as the SNR score, which also shows that the original image and the final result are very similar based on the criteria of ISO 12232: Electronic Still Picture Cameras.
108 |
109 |
110 |
111 |
112 |
113 |

114 |
Figure 9: SNR Formula and ISO 12232 Criteria
115 |
116 |
117 |
118 | # Image Completion
119 | ## Task Definition
120 |
121 |
122 | Image completion/inpainting is used when there is corrupted or unwanted region in image and we want to fill those region with
123 | pixels that are coherent with the background. Below is an illustration, say we want to remove the cow in the image, we will
124 | done that by remove the cow from image and try to complete it.
125 |
126 |
127 |
128 |
129 |

130 |
Figure 10: Image Completion Task Definition
131 |
132 |
133 |
134 | ## First try
135 |
136 |
137 | To use patchmatch for image completion, we come up with this straight forward method.
138 | First, find a bounding box of the missing region.
139 | Then for each patch in the bounding box, we try to find the nearest patch outside the bounding box use PatchMatch.
140 | Finally, we just use those nearest patches to vote for the pixel value inside the missing region.
141 |
142 |
143 |
144 |
145 |

146 |
Figure 11: Algorithm of First Try
147 |
148 |
149 |
150 |
151 |

152 |
Figure 12: Result of First Try
153 |
154 |
155 |
156 | ## What's the problem?
157 |
158 |
159 | We can observe that there are some blurred region of the result in Figure 12. It is because the nearby pixels in the
160 | missing region are not finding coherent nearest neighbor patches. When those patches voting for the pixel, they give
161 | different votes and averaging them yields blur region.
162 |
163 |
164 | So how can we find better nearest neighbor patches?
165 | Turns out that we want patch size to be large enough in the first hand to see the global picture of the image.
166 | Meanwhile, we also want it to become small enough in the end so that our algithm can be aware of local structure
167 | and produce sharp image. The answer to that is adaptive patch size, or we can done that by fix patch size and varying
168 | the image size in multiple scale.
169 |
170 |
171 |
172 | ## Multi-Scale Image Completion
173 |
174 |
175 | We use multi-scale image completion, as described in [3].
176 | We start from the smallest scale, do image completion at that scale, then keep scaling up until we meet the original scale.
177 | In each scale change, for the pixels outside the missing region, we simply scale down the original image to that scale;
178 | for the pixels inside the missing region, we scale up the filled region as initialization of next scale.
179 |
180 |
181 |
182 |
183 |
184 |

185 |
Figure 13: Algorithm of Multi-Scale Image Completion
186 |
187 |
188 |
189 |
190 |

191 |
Figure 14: Result of Multi-Scale Image Completion
192 |
193 |
194 |
195 | ## Incorporating Constraints
196 |
197 |
198 | However, sometimes it still produce images with artifacts, like the left image of Figure 17.
199 | Luckily, there is a solution. We follow [1] to incorporate user-specified constraints to enhance the completion result.
200 | To do that, we simply restrict the constrained pixels in missing region to search for patches that are of same constraint.
201 |
202 |
203 |
204 |
205 |

206 |
Figure 15: Man and dog image
207 |
208 |
209 |
210 |
211 |

212 |
Figure 16: User-specified constraint
213 |
214 |
215 |
216 |
217 |

218 |
Figure 17: Image completion result of man and dog
219 |
220 |
221 |
222 | # Interactive GUI
223 |
224 |
225 | We designed an interactive GUI for end users. User can load an image and mask for that image. Then he/she can introduce some contraints to maintain some boundaries and let the algorithm complete the hole in the image. Using our imterative interface user can improve the performance of image completion. For a short demonstraion please watch the video below.
226 |
227 |
228 |
229 |
230 |

231 |
232 |
233 | # Image Completion Results
234 |
235 |
236 |
237 |

238 |
239 |
240 |
241 |
242 |
243 |

244 |
245 |
246 |
247 |
248 |

249 |
250 |
251 |
252 |
253 |

254 |
255 |
256 |
257 |
258 |

259 |
260 |
261 |
262 | # Future Work
263 | 1. Adopt KNN rather than the most similar patch
264 | 2. Figure out a way for better initialization
265 | 3. Find how to determine patch size
266 | 4. Speed up our application to real time
267 | 5. Improve the sensitivity issues for initialization and patch size
268 |
269 | # Presentation
270 | [Slides](https://docs.google.com/presentation/d/1YMoPjG7pNWLSEDjNDadcxzCkqFpysvW_enfNe-DhoVM/edit#slide=id.p1)
271 |
272 | # Source Code
273 | [Code](https://github.com/WenFuLee/CS-766-Computer-Vision)
274 |
275 | # Reference
276 | 1. Iizuka, S., Simo-Serra, E., & Ishikawa, H. (2017). Globally and locally consistent image completion. ACM Transactions on Graphics (TOG), 36(4), 107.
277 | 2. Barnes, C., Shechtman, E., Finkelstein, A., & Goldman, D. B. (2009). PatchMatch: A randomized correspondence algorithm for structural image editing. ACM Transactions on Graphics-TOG, 28(3), 24.
278 | 3. Wexler, Y., Shechtman, E., & Irani, M. (2007). Space-time completion of video. IEEE Transactions on pattern analysis and machine intelligence, 29(3).
279 | 4. Hays, J., & Efros, A. A. (2007, August). Scene completion using millions of photographs. In ACM Transactions on Graphics (TOG) (Vol. 26, No. 3, p. 4). ACM.
280 |
--------------------------------------------------------------------------------
/report/image/constraint_illu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/constraint_illu.png
--------------------------------------------------------------------------------
/report/image/constraint_result.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/constraint_result.png
--------------------------------------------------------------------------------
/report/image/first_result.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/first_result.png
--------------------------------------------------------------------------------
/report/image/first_try.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/first_try.png
--------------------------------------------------------------------------------
/report/image/image1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/image1.png
--------------------------------------------------------------------------------
/report/image/image2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/image2.png
--------------------------------------------------------------------------------
/report/image/image3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/image3.png
--------------------------------------------------------------------------------
/report/image/image4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/image4.png
--------------------------------------------------------------------------------
/report/image/image5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/image5.png
--------------------------------------------------------------------------------
/report/image/image6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/image6.png
--------------------------------------------------------------------------------
/report/image/image7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/image7.png
--------------------------------------------------------------------------------
/report/image/image8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/image8.png
--------------------------------------------------------------------------------
/report/image/image9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/image9.png
--------------------------------------------------------------------------------
/report/image/man_dog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/man_dog.png
--------------------------------------------------------------------------------
/report/image/multi_algo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/multi_algo.png
--------------------------------------------------------------------------------
/report/image/multi_result.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/multi_result.png
--------------------------------------------------------------------------------
/report/image/result1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/result1.png
--------------------------------------------------------------------------------
/report/image/result2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/result2.png
--------------------------------------------------------------------------------
/report/image/result3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/result3.png
--------------------------------------------------------------------------------
/report/image/result4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/result4.png
--------------------------------------------------------------------------------
/report/image/result5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/result5.png
--------------------------------------------------------------------------------
/report/image/task_def.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/report/image/task_def.png
--------------------------------------------------------------------------------
/report/tmp.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/simulation-results/Image_Completion_Ex1/a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Completion_Ex1/a.png
--------------------------------------------------------------------------------
/simulation-results/Image_Completion_Ex1/a_completion.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Completion_Ex1/a_completion.jpg
--------------------------------------------------------------------------------
/simulation-results/Image_Completion_Ex1/a_hole.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Completion_Ex1/a_hole.jpg
--------------------------------------------------------------------------------
/simulation-results/Image_Completion_Ex1/a_hole_mask.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Completion_Ex1/a_hole_mask.jpg
--------------------------------------------------------------------------------
/simulation-results/Image_Completion_Ex2/test7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Completion_Ex2/test7.jpg
--------------------------------------------------------------------------------
/simulation-results/Image_Completion_Ex2/test7h.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Completion_Ex2/test7h.png
--------------------------------------------------------------------------------
/simulation-results/Image_Completion_Ex2/test7m.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Completion_Ex2/test7m.png
--------------------------------------------------------------------------------
/simulation-results/Image_Completion_Ex2/test7m_completion.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Completion_Ex2/test7m_completion.jpg
--------------------------------------------------------------------------------
/simulation-results/Image_Reconstruction_Ex1/Source Image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Reconstruction_Ex1/Source Image.png
--------------------------------------------------------------------------------
/simulation-results/Image_Reconstruction_Ex1/Target Image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Reconstruction_Ex1/Target Image.png
--------------------------------------------------------------------------------
/simulation-results/Image_Reconstruction_Ex1/a_restructed.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Reconstruction_Ex1/a_restructed.jpg
--------------------------------------------------------------------------------
/simulation-results/Image_Reconstruction_Ex1/ann.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Reconstruction_Ex1/ann.jpg
--------------------------------------------------------------------------------
/simulation-results/Image_Reconstruction_Ex1/annd.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/simulation-results/Image_Reconstruction_Ex1/annd.jpg
--------------------------------------------------------------------------------
/simulation-results/Untitled Document:
--------------------------------------------------------------------------------
1 | sdf
2 |
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test2.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test2.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test2h.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test2h.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test2m.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test2m.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test3.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test3.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test3h.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test3h.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test3m.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test3m.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test7.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test7.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test7h.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test7h.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test7m.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test7m.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test8.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test8.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test8h.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test8h.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/bmp/test8m.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/bmp/test8m.bmp
--------------------------------------------------------------------------------
/test-images/Image_Completion/createHole.m:
--------------------------------------------------------------------------------
1 |
2 | for i=1
3 |
4 | if exist(strcat('test',num2str(i),'.bmp'), 'file')==2
5 |
6 | a = imread(strcat('test',num2str(i),'.bmp'));
7 | mask = ~logical(imread(strcat('test',num2str(i),'m.bmp')));
8 | r = a.*uint8(~mask);
9 | imwrite(mask(:,:,1), strcat('test',num2str(i),'m.bmp'));
10 | imwrite(r, strcat('test',num2str(i),'h.bmp'));
11 | else
12 | a = imread(strcat('test',num2str(i),'.jpg'));
13 | mask = ~logical(imread(strcat('test',num2str(i),'m.jpg')));
14 | r = a.*uint8(~mask);
15 | imwrite(mask(:,:,1), strcat('test',num2str(i),'m.jpg'));
16 | imwrite(r, strcat('test',num2str(i),'h.jpg'));
17 | end
18 |
19 | end
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test1.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test1h.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test1h.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test1m.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test1m.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test4.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test4h.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test4h.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test4m.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test4m.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test5.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test5h.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test5h.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test5m.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test5m.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test6.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test6h.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test6h.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/jpg/test6m.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/jpg/test6m.jpg
--------------------------------------------------------------------------------
/test-images/Image_Completion/png/test1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/png/test1.png
--------------------------------------------------------------------------------
/test-images/Image_Completion/png/test1m.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/png/test1m.png
--------------------------------------------------------------------------------
/test-images/Image_Completion/png/test2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/png/test2.png
--------------------------------------------------------------------------------
/test-images/Image_Completion/png/test2m.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/png/test2m.png
--------------------------------------------------------------------------------
/test-images/Image_Completion/png/test3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/png/test3.png
--------------------------------------------------------------------------------
/test-images/Image_Completion/png/test3m.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/png/test3m.png
--------------------------------------------------------------------------------
/test-images/Image_Completion/png/test4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/png/test4.png
--------------------------------------------------------------------------------
/test-images/Image_Completion/png/test4m.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Completion/png/test4m.png
--------------------------------------------------------------------------------
/test-images/Image_Reconstruction/a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Reconstruction/a.png
--------------------------------------------------------------------------------
/test-images/Image_Reconstruction/b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Reconstruction/b.png
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_10_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_10_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_17_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_17_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_19_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_19_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_1_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_1_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_20_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_20_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_21_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_21_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_23_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_23_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_24_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_24_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_26_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_26_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_27_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_27_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_28_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_28_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_29_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_29_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_2_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_2_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_30_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_30_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_32_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_32_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_35_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_35_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_4_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_4_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_5_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_5_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_6_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_6_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_8_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_8_aaa.jpg
--------------------------------------------------------------------------------
/test-images/Image_Retargeting/ours_9_aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/Image_Retargeting/ours_9_aaa.jpg
--------------------------------------------------------------------------------
/test-images/a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/a.png
--------------------------------------------------------------------------------
/test-images/a_hole.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/a_hole.jpg
--------------------------------------------------------------------------------
/test-images/a_hole_mask.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/a_hole_mask.jpg
--------------------------------------------------------------------------------
/test-images/b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WenFuLee/CS-766-Computer-Vision/23aa58c6c8709fea22ca9cb3c06ddf254723e330/test-images/b.png
--------------------------------------------------------------------------------