import cv2 import sys import os import numpy as np file = "test.jpg" if len(sys.argv)>1: file = sys.argv[1] if not os.path.exists(file): raise f"Datei {file} nicht gefunden!" def readAndConvert(file): return cv2.cvtColor(cv2.imread(file), cv2.COLOR_BGR2GRAY)/255 # Conversion to float in 0..1 def toBWSimple(img): c = np.copy(img) h,w = c.shape for y in range(h): for x in range(w): if img[y,x]<0.5: c[y,x] = 0 else: c[y,x] = 1.0 return c def floydSteinberg(img): c = np.copy(img) h,w = c.shape # # TODO # return c img = readAndConvert(file) print(img.shape) cv2.imshow('Image', img) cv2.waitKey(1000) c = toBWSimple(img) cv2.imshow('Image', c) cv2.waitKey(1000) c = floydSteinberg(img) cv2.imshow('Image', c) cv2.waitKey(10000)