Commit c9a3225f authored by Arne Gerdes's avatar Arne Gerdes

Kommentare hinzugefügt

parent f7e311af
"""
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):
"""
Converts PIL's Image to numpy's array.
Konvertiert PIL Image in ein Numpy Array
:param image: PIL's Image object.
:return: Numpy's array of the image.
:return: Numpy Array der Bilder.
"""
return np.asarray(image)
def nparray_as_image(nparray, mode='RGB'):
"""
Converts numpy's array of image to PIL's Image.
Konvertiert Numpy Array der Bilder in PIL Image
:param nparray: Numpy's array of image.
:param mode: Mode of the conversion. Defaults to 'RGB'.
:return: PIL's Image containing the image.
:param mode: Modus 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):
"""
Loads RGB image and converts 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 und konvertiert 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: Coordinates 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: : Koordinaten 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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment