Skip to content

Commit 3675bd3

Browse files
msuessgadicc
authored andcommitted
feat: add PyPatchMatch for outpainting support
1 parent d4cf594 commit 3675bd3

File tree

17 files changed

+1429
-3
lines changed

17 files changed

+1429
-3
lines changed

Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ RUN mkdir /api
55
WORKDIR /api
66

77
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
8+
ENV DEBIAN_FRONTEND=noninteractive
89

9-
# Install git
10-
RUN apt-get update && apt-get install -y git
10+
# Install git and OpenCV
11+
RUN apt-get update && apt-get install -yqq git libopencv-dev python3-opencv
12+
13+
# Compile PyPatchMatch
14+
WORKDIR /PyPatchMatch
15+
ADD PyPatchMatch .
16+
RUN make
17+
18+
WORKDIR /
1119

1220
COPY root-cache/. /root/.cache
1321

PyPatchMatch/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/build/
2+
/*.so
3+
__pycache__
4+
*.py[cod]

PyPatchMatch/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Jiayuan Mao
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

PyPatchMatch/Makefile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# Makefile
3+
# Jiayuan Mao, 2019-01-09 13:59
4+
#
5+
6+
SRC_DIR = csrc
7+
INC_DIR = csrc
8+
OBJ_DIR = build/obj
9+
TARGET = libpatchmatch.so
10+
11+
LIB_TARGET = $(TARGET)
12+
INCLUDE_DIR = -I $(SRC_DIR) -I $(INC_DIR)
13+
14+
CXX = $(ENVIRONMENT_OPTIONS) g++
15+
CXXFLAGS = -std=c++14
16+
CXXFLAGS += -Ofast -ffast-math -w
17+
# CXXFLAGS += -g
18+
CXXFLAGS += $(shell pkg-config --cflags opencv) -fPIC
19+
CXXFLAGS += $(INCLUDE_DIR)
20+
LDFLAGS = $(shell pkg-config --cflags --libs opencv) -shared -fPIC
21+
22+
23+
CXXSOURCES = $(shell find $(SRC_DIR)/ -name "*.cpp")
24+
OBJS = $(addprefix $(OBJ_DIR)/,$(CXXSOURCES:.cpp=.o))
25+
DEPFILES = $(OBJS:.o=.d)
26+
27+
.PHONY: all clean rebuild test
28+
29+
all: $(LIB_TARGET)
30+
31+
$(OBJ_DIR)/%.o: %.cpp
32+
@echo "[CC] $< ..."
33+
@$(CXX) -c $< $(CXXFLAGS) -o $@
34+
35+
$(OBJ_DIR)/%.d: %.cpp
36+
@mkdir -pv $(dir $@)
37+
@echo "[dep] $< ..."
38+
@$(CXX) $(INCLUDE_DIR) $(CXXFLAGS) -MM -MT "$(OBJ_DIR)/$(<:.cpp=.o) $(OBJ_DIR)/$(<:.cpp=.d)" "$<" > "$@"
39+
40+
sinclude $(DEPFILES)
41+
42+
$(LIB_TARGET): $(OBJS)
43+
@echo "[link] $(LIB_TARGET) ..."
44+
@$(CXX) $(OBJS) -o $@ $(CXXFLAGS) $(LDFLAGS)
45+
46+
clean:
47+
rm -rf $(OBJ_DIR) $(LIB_TARGET)
48+
49+
rebuild:
50+
+@make clean
51+
+@make
52+
53+
# vim:ft=make
54+
#

PyPatchMatch/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
NOTE: This is a copy of https://github.com/vacancy/PyPatchMatch, with some code related to travis removed
2+
3+
PatchMatch based Inpainting
4+
=====================================
5+
This library implements the PatchMatch based inpainting algorithm. It provides both C++ and Python interfaces.
6+
This implementation is heavily based on the implementation by Younesse ANDAM:
7+
(younesse-cv/PatchMatch)[https://github.com/younesse-cv/PatchMatch], with some bugs fix.
8+
9+
Usage
10+
-------------------------------------
11+
12+
You need to first install OpenCV to compile the C++ libraries. Then, run `make` to compile the
13+
shared library `libpatchmatch.so`.
14+
15+
For Python users (example available at `examples/py_example.py`)
16+
17+
```python
18+
import patch_match
19+
20+
image = ... # either a numpy ndarray or a PIL Image object.
21+
mask = ... # either a numpy ndarray or a PIL Image object.
22+
result = patch_match.inpaint(image, mask, patch_size=5)
23+
```
24+
25+
For C++ users (examples available at `examples/cpp_example.cpp`)
26+
27+
```cpp
28+
#include "inpaint.h"
29+
30+
int main() {
31+
cv::Mat image = ...
32+
cv::Mat mask = ...
33+
34+
cv::Mat result = Inpainting(image, mask, 5).run();
35+
36+
return 0;
37+
}
38+
```
39+
40+
41+
README and COPYRIGHT by Younesse ANDAM
42+
-------------------------------------
43+
@Author: Younesse ANDAM
44+
45+
@Contact: younesse.andam@gmail.com
46+
47+
Description: This project is a personal implementation of an algorithm called PATCHMATCH that restores missing areas in an image.
48+
The algorithm is presented in the following paper
49+
PatchMatch A Randomized Correspondence Algorithm
50+
for Structural Image Editing
51+
by C.Barnes,E.Shechtman,A.Finkelstein and Dan B.Goldman
52+
ACM Transactions on Graphics (Proc. SIGGRAPH), vol.28, aug-2009
53+
54+
For more information please refer to
55+
http://www.cs.princeton.edu/gfx/pubs/Barnes_2009_PAR/index.php
56+
57+
Copyright (c) 2010-2011
58+
59+
60+
Requirements
61+
-------------------------------------
62+
63+
To run the project you need to install Opencv library and link it to your project.
64+
Opencv can be download it here
65+
http://opencv.org/downloads.html
66+

0 commit comments

Comments
 (0)