-
Notifications
You must be signed in to change notification settings - Fork 2
/
GIMP-style-transfer.py
executable file
·175 lines (154 loc) · 5.54 KB
/
GIMP-style-transfer.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/python
# GIMP Style Transfer
# This plugin implements the Neural Style Transfer. At the moment, the following
# approaches are implemented:
# 1. implementation_1: https://github.com/lengstrom/fast-style-transfer
# 2. implementation_1: https://github.com/CompVis/adaptive-style-transfer
# 3. implementation_1: https://github.com/tensorlayer/adaptive-style-transfer
# Copyright (c) 2019 Davide Sandona'
# sandona [dot] davide [at] gmail [dot] com
# https://github.com/Davide-sd/GIMP-style-transfer
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>
from gimpfu import *
import sys, os
from commons_1_2 import styles, artists
pluginFolderPath = os.path.abspath(sys.argv[0])
pluginFolder = os.path.dirname(pluginFolderPath)
sys.path.insert(0, pluginFolder)
from implementation_1.main import fast_style_transfer, batch_fast_style_transfer
from implementation_2.main import artist_style_transfer, batch_artist_style_transfer
from implementation_3.main import arbitrary_style_transfer, batch_arbitrary_style_transfer
author = "Davide Sandona'"
year = "2019"
menu_filter = "<Image>/Filters/Style Transfer"
menu_batch = "<Image>/File/Batch Style Transfer"
prefix = "davide_sd_ai_"
################################################################################
############################ IMPLEMENTATION 1 ##################################
################################################################################
descr = "Apply to a target image the style of the selected painting."
register(
prefix + "style_transfer",
descr,
descr,
author,
author,
year,
"Style Transfer...",
"RGB*, GRAY*",
[
(PF_IMAGE, "image", "Input image", None),
(PF_OPTION, "style", "Style", 2, tuple(styles)),
(PF_LAYER, "layer", "Content layer", None),
],
[],
fast_style_transfer,
menu=menu_filter)
register(
prefix + "batch_style_transfer",
descr,
descr,
author,
author,
year,
"Style Transfer...",
"",
[
(PF_DIRNAME, "content_folder","Content Folder",""),
(PF_DIRNAME, "output_folder","Output Folder",""),
(PF_OPTION, "style", "Style", 2, tuple(styles)),
],
[],
batch_fast_style_transfer,
menu=menu_batch)
################################################################################
############################ IMPLEMENTATION 2 ##################################
################################################################################
descr = "Apply to a target image the style of a well known artist."
register(
prefix + "artist_style_transfer",
descr,
descr,
author,
author,
year,
"Artist Style Transfer...",
"RGB*, GRAY*",
[
(PF_IMAGE, "image", "Input image", None),
(PF_OPTION, "style", "Style", 2, tuple(artists)),
(PF_LAYER, "layer", "Content layer", None),
],
[],
artist_style_transfer,
menu=menu_filter)
register(
prefix + "batch_artist_style_transfer",
descr,
descr,
author,
author,
year,
"Artist Style Transfer...",
"",
[
(PF_DIRNAME, "content_folder","Content Folder",""),
(PF_DIRNAME, "output_folder","Output Folder",""),
(PF_OPTION, "style", "Style", 2, tuple(artists)),
],
[],
batch_artist_style_transfer,
menu=menu_batch)
################################################################################
############################ IMPLEMENTATION 3 ##################################
################################################################################
descr = "Apply to a target image the style of a specified style image."
register(
prefix + "arbitrary_style_transfer",
descr,
descr,
author,
author,
year,
"Arbitrary Style Transfer...",
"RGB*, GRAY*",
[
(PF_IMAGE, "image", "Input image", None),
(PF_SLIDER, "alpha", "Mix Factor", 100, (0, 100, 1)),
(PF_LAYER, "layer_content", "Content layer", None),
(PF_LAYER, "layer_style", "Style layer", None),
],
[],
arbitrary_style_transfer,
menu=menu_filter)
descr = "Apply to a target images the style of specified style images."
register(
prefix + "batch_arbitrary_style_transfer",
descr,
descr,
author,
author,
year,
"Arbitrary Style Transfer...",
"",
[
(PF_DIRNAME, "content_folder","Content Folder",""),
(PF_DIRNAME, "style_folder","Style Folder",""),
(PF_DIRNAME, "output_folder","Output Folder",""),
(PF_SLIDER, "alpha", "Mix Factor", 100, (0, 100, 1)),
],
[],
batch_arbitrary_style_transfer,
menu=menu_batch)
main()