Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Image-Editor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marc Feger
Image-Editor
Commits
54b182d8
Commit
54b182d8
authored
6 years ago
by
Marc Feger
Browse files
Options
Downloads
Patches
Plain Diff
Refactor the writing of the result image; Add optional color range
parent
3f24ba21
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
GUI.py
+6
-1
6 additions, 1 deletion
GUI.py
editor.py
+6
-4
6 additions, 4 deletions
editor.py
filter.py
+31
-4
31 additions, 4 deletions
filter.py
images/edit.jpeg
+0
-0
0 additions, 0 deletions
images/edit.jpeg
with
43 additions
and
9 deletions
GUI.py
+
6
−
1
View file @
54b182d8
...
...
@@ -91,7 +91,7 @@ class GUI(object):
:return: None
"""
self
.
image_path
:
String
=
askopenfilename
(
initialdir
=
'
/
'
,
title
=
'
Select file
'
,
filetypes
=
(
(
'
jpeg files
'
,
'
*.jpeg
'
),
(
'
all
files
'
,
'
*.
*
'
)
)
)
filetypes
=
[
(
'
jpeg files
'
,
'
*.jpeg
'
),
(
'
jpg
files
'
,
'
*.
jpg
'
)
]
)
new_image
=
self
.
read_image
(
self
.
image_path
)
...
...
@@ -132,6 +132,11 @@ if __name__ == '__main__':
Notice: The edited image will be saved in ./images/edited.py. Each new filter will overwrite this image. This may
take a while.
It is not possible to edit *.png images since they are images with size NxMx4.
If the colors should be in a certain range e.g. [0, 255] feel free to checkout Filter.
For the edges it is proofed if the H-element is in the image. This is done because otherwise the opposite site of
the image would be relevant within the filter region.
"""
root
=
Tk
()
root
.
resizable
(
False
,
False
)
...
...
This diff is collapsed.
Click to expand it.
editor.py
+
6
−
4
View file @
54b182d8
import
copy
from
tokenize
import
String
from
skimage
import
io
...
...
@@ -27,12 +26,15 @@ class Editor(object):
:return: None
"""
image
=
io
.
imread
(
fname
=
self
.
image_path
)
edited_image
=
copy
.
deepcopy
(
image
)
# io.imread(fname=self.image_path)
height
,
width
,
_
=
image
.
shape
height
,
width
,
_
=
image
.
shape
# len(image), len(image[0, 0:, 0:]) wont work for .png-images.
edited_image
=
np
.
zeros
((
height
,
width
,
3
),
dtype
=
np
.
float64
)
edited_pixels
=
0
for
v
in
range
(
height
):
for
u
in
range
(
width
):
pixel
=
Pixel
(
image
,
v
,
u
)
edited_image
[
v
,
u
]
=
pixel
.
filter_with
(
option
)
edited_pixels
+=
1
if
edited_pixels
%
10000
==
0
:
print
(
'
Finished with:
'
+
str
(
edited_pixels
)
+
'
of
'
+
str
(
width
*
height
))
io
.
imsave
(
arr
=
edited_image
,
fname
=
self
.
edit_path
)
This diff is collapsed.
Click to expand it.
filter.py
+
31
−
4
View file @
54b182d8
...
...
@@ -13,10 +13,11 @@ from mask import *
class
Filter
(
object
):
def
__init__
(
self
,
image
:
imageio
.
core
.
util
.
Array
,
v
:
int
,
u
:
int
)
->
None
:
def
__init__
(
self
,
image
:
imageio
.
core
.
util
.
Array
,
v
:
int
,
u
:
int
,
color_range
:
List
=
None
)
->
None
:
"""
This class edits a pixel in a image with a given filter.
:param color_range: If the image pixel should be in a certain range e.g. [0, 255].
:param image: The image in which the filter should be used.
:param v: The v coordinate
:param u: The u coordinate
...
...
@@ -24,6 +25,10 @@ class Filter(object):
self
.
image
=
image
self
.
v
=
v
self
.
u
=
u
self
.
color_range
=
color_range
if
color_range
:
self
.
min_color
=
np
.
min
(
self
.
color_range
)
self
.
max_color
=
np
.
max
(
self
.
color_range
)
def
use
(
self
,
option
:
String
=
FILTER
.
empty
.
value
,
linear
:
bool
=
True
,
dim
:
Tuple
=
(
5
,
5
),
f
:
function
=
np
.
min
)
->
List
:
...
...
@@ -41,6 +46,21 @@ class Filter(object):
else
:
return
self
.
non_linear_filter
(
f
,
dim
)
def
__keep_values_in_range
(
self
,
pixel
):
if
pixel
[
COLOR
.
red
.
value
]
>
self
.
max_color
:
pixel
[
COLOR
.
red
.
value
]
=
self
.
max_color
if
pixel
[
COLOR
.
green
.
value
]
>
self
.
max_color
:
pixel
[
COLOR
.
green
.
value
]
=
self
.
max_color
if
pixel
[
COLOR
.
blue
.
value
]
>
self
.
max_color
:
pixel
[
COLOR
.
blue
.
value
]
=
self
.
max_color
if
pixel
[
COLOR
.
red
.
value
]
<
self
.
min_color
:
pixel
[
COLOR
.
red
.
value
]
=
self
.
min_color
if
pixel
[
COLOR
.
green
.
value
]
<
self
.
min_color
:
pixel
[
COLOR
.
green
.
value
]
=
self
.
min_color
if
pixel
[
COLOR
.
blue
.
value
]
<
self
.
min_color
:
pixel
[
COLOR
.
blue
.
value
]
=
self
.
min_color
def
linear_filter
(
self
,
option
:
String
)
->
List
:
"""
This method is for filtering with linear filters.
...
...
@@ -50,7 +70,7 @@ class Filter(object):
:return: A modified rgb-pixel
"""
height_I
,
width_I
,
_
=
self
.
image
.
shape
height_I
,
width_I
,
_
=
self
.
image
.
shape
# len(self.image), len(self.image[0, 0:, 0:])
H
=
np
.
matrix
(
Mask
().
H
[
option
])
divider
=
abs
(
H
.
sum
())
...
...
@@ -68,6 +88,9 @@ class Filter(object):
for
color
in
COLOR
:
new_pixel
[
color
.
value
]
+=
self
.
image
[
self
.
v
+
j
,
self
.
u
+
i
,
color
.
value
]
*
\
np
.
multiply
(
1
/
divider
,
H
[
center_j
+
j
,
center_i
+
i
])
if
self
.
color_range
:
self
.
__keep_values_in_range
(
new_pixel
)
return
new_pixel
def
non_linear_filter
(
self
,
f
:
function
,
dim
:
Tuple
=
(
5
,
5
))
->
List
:
...
...
@@ -91,9 +114,13 @@ class Filter(object):
(
self
.
v
+
j
>=
0
)
and
(
self
.
v
+
j
<=
height_I
-
1
):
for
color
in
COLOR
:
colors_neighbors
[
color
.
value
]
+=
[
self
.
image
[
self
.
v
+
j
,
self
.
u
+
i
,
color
.
value
]]
return
[
new_pixel
=
[
f
(
colors_neighbors
[
COLOR
.
red
.
value
]),
f
(
colors_neighbors
[
COLOR
.
green
.
value
]),
f
(
colors_neighbors
[
COLOR
.
blue
.
value
])
]
if
self
.
color_range
:
self
.
__keep_values_in_range
(
new_pixel
)
return
new_pixel
This diff is collapsed.
Click to expand it.
images/edit.jpeg
+
0
−
0
View replaced file @
3f24ba21
View file @
54b182d8
18.6 KiB
|
W:
|
H:
10.3 KiB
|
W:
|
H:
2-up
Swipe
Onion skin
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment