Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Frank Tjado Ihmels
medienverarbeitung17.projectmood
Commits
c9a3225f
Commit
c9a3225f
authored
Dec 19, 2017
by
Arne Gerdes
Browse files
Kommentare hinzugefügt
parent
f7e311af
Changes
1
Hide whitespace changes
Inline
Side-by-side
projectmood/image_commons.py
View file @
c9a3225f
"""
This module contains functions used to manipulate images in OpenCV and PIL's Image.
Diese Klasse enthält Funktionen zum Bearbeiten von Bildern in OpenCV und PIL's Image.
PIL => PIL ist die Python-Imaging-Bibliothek
"""
import
cv2
import
numpy
as
np
...
...
@@ -8,28 +9,28 @@ from PIL import Image
def
image_as_nparray
(
image
):
"""
C
onvert
s
PIL
's
Image
to numpy's a
rray
.
K
onvert
iert
PIL Image
in ein Numpy A
rray
:param image: PIL's Image object.
:return: Numpy
's a
rray
of the image
.
:return: Numpy
A
rray
der Bilder
.
"""
return
np
.
asarray
(
image
)
def
nparray_as_image
(
nparray
,
mode
=
'RGB'
):
"""
C
onvert
s numpy's array of image to
PIL
's
Image
.
K
onvert
iert Numpy Array der Bilder in
PIL Image
:param nparray: Numpy's array of image.
:param mode: Mod
e of the conversion. Defaults to '
RGB
'
.
:return: PIL
's
Image
containing the image.
:param mode: Mod
us der Umwandlung. Standardeinstellung ist "
RGB
"
.
:return: PIL Image
mit dem Bild
"""
return
Image
.
fromarray
(
np
.
asarray
(
np
.
clip
(
nparray
,
0
,
255
),
dtype
=
'uint8'
),
mode
)
def
load_image
(
source_path
):
"""
L
oads RGB image a
nd
c
onvert
s it to grayscale
.
:param source_path:
Image's source path
.
:return:
Image loaded from the path and converted to grayscale
.
L
ädt das RGB-Bild u
nd
k
onvert
iert es in Graustufen
.
:param source_path:
Quellpfad des Bildes
.
:return:
Bild wird vom Pfad geladen und in Graustufen konvertiert
.
"""
source_image
=
cv2
.
imread
(
source_path
)
return
cv2
.
cvtColor
(
source_image
,
cv2
.
COLOR_BGR2GRAY
)
...
...
@@ -37,10 +38,10 @@ def load_image(source_path):
def
draw_with_alpha
(
source_image
,
image_to_draw
,
coordinates
):
"""
Draws a partially transparent image over another image
.
:param source_image:
Image to draw over
.
:param image_to_draw:
Image to draw
.
:param coordinates:
C
oordinate
s to draw an image at. Tuple of x, y, width and height
.
Zeichnet ein teilweise transparentes Bild über ein anderes Bild
.
:param source_image:
Bild zum Übermalen
.
:param image_to_draw:
Bild zum Zeichnen
.
:param coordinates:
: K
oordinate
n um ein Bild zu zeichnen. Tupel von x, y, Breite und Höhe
.
"""
x
,
y
,
w
,
h
=
coordinates
image_to_draw
=
image_to_draw
.
resize
((
h
,
w
),
Image
.
ANTIALIAS
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment