diff --git a/ctif.py b/ctif.py index 7d1c755..6a663c2 100644 --- a/ctif.py +++ b/ctif.py @@ -16,8 +16,8 @@ FONT_PATH = 'fonts/scientifica.ttf' TEXT_WIDTH = 6 # on font size 12 monocraft medium TEXT_HEIGHT = 11 -SCALE_FACTOR = 2 -RESIZE_FACTOR = 2 +SCALE_FACTOR = 1 +RESIZE_FACTOR = 0.75 SCALED_WIDTH = TEXT_WIDTH // SCALE_FACTOR SCALED_HEIGHT = TEXT_HEIGHT // SCALE_FACTOR @@ -83,14 +83,14 @@ class CTIF: if image.mode != 'RGB': image = image.convert('RGB') - image = image.resize((image.width * RESIZE_FACTOR, image.height * RESIZE_FACTOR)) + image = image.resize((int(image.width * RESIZE_FACTOR), int(image.height * RESIZE_FACTOR))) logging.debug(f'Image Size: {image.size}') L_image = image.convert('L') - logging.debug(f'L_image Size: {L_image.size}') + # logging.debug(f'L_image Size: {L_image.size}') - dog = filters.difference_of_gaussians(image) - logging.debug(f'Dog Size: {dog.size}') + dog = filters.difference_of_gaussians(image, blur_strength_2=1) + # logging.debug(f'Dog Size: {dog.size}') dog.save('debug/dog.png') @@ -209,11 +209,18 @@ class CTIF: if char not in EDGE_CHARS: v = (NEW_CHARS.find(char) + 1) * (255/len(NEW_CHARS))/255 - logging.debug(f'HSV Color: {h, s, v}') + # logging.debug(f'HSV Color: {h, s, v}') + + # Make the bright colors brighter and the darks darker + if v >= 0.5: + v *= 1.5 + # else: + # v *= 0.5 + r, g, b = colorsys.hsv_to_rgb(h, s, v) - logging.debug(f'RGB Color Before: {r, g, b}') + # logging.debug(f'RGB Color Before: {r, g, b}') r *= 255 g *= 255 b *= 255 @@ -221,7 +228,7 @@ class CTIF: r = min(r, 255) g = min(g, 255) b = min(b, 255) - logging.debug(f'RGB Color: {r, g, b}') + # logging.debug(f'RGB Color: {r, g, b}') rendered_char = font.render(char, ANTI_ALIASING, (int(r), int(g), int(b))) window.blit(rendered_char, (x * TEXT_WIDTH, y * TEXT_HEIGHT)) @@ -320,9 +327,9 @@ class CTIF: d = data[i:i + 3] - print(f'index: {i}') - print(f'index end: {i + 3}') - print(f'data: {d}') + # print(f'index: {i}') + # print(f'index end: {i + 3}') + # print(f'data: {d}') h = d[0:1] h = int.from_bytes(h, 'big') @@ -333,7 +340,7 @@ class CTIF: char_n = d[2:3] char_n = int.from_bytes(char_n, 'big') - print(char_n) + # print(char_n) char = (NEW_CHARS + EDGE_CHARS)[char_n] logging.debug(f'H: {h}, S: {s}, Char: {char}') diff --git a/engine.citf b/engine.citf index 08161b7..3957b2f 100644 Binary files a/engine.citf and b/engine.citf differ diff --git a/filters.py b/filters.py index aa532cf..a706e45 100644 --- a/filters.py +++ b/filters.py @@ -14,7 +14,7 @@ sobel_x_kernel = np.array(( sobel_y_kernel = np.transpose(sobel_x_kernel) -def difference_of_gaussians(img: Image.Image, blur_strength_1: float | None = 1.0, blur_strength_2: float | None = 1.2) -> Image.Image: +def difference_of_gaussians(img: Image.Image, blur_strength_1: float | None = 1.0, blur_strength_2: float | None = 1.2, threshold: int | None = 128*3) -> Image.Image: blur_1 = img.filter(ImageFilter.GaussianBlur(blur_strength_1)) blur_2 = img.filter(ImageFilter.GaussianBlur(blur_strength_2)) @@ -34,6 +34,9 @@ def difference_of_gaussians(img: Image.Image, blur_strength_1: float | None = 1. p2 = np.array(p2) new_pixel = p2 - p1 + # if new_pixel.sum() < threshold: + # new_pixel = np.zeros(3).astype(np.uint8) + dog.putpixel(coords, tuple(new_pixel.tolist())) return dog diff --git a/main.py b/main.py index 97963cb..8959ec6 100644 --- a/main.py +++ b/main.py @@ -13,10 +13,10 @@ def main(): image = Image.open(IMAGE_PATH) i = ctif.CTIF(image) - i.save_citf('engine') - i.read_citf('engine.citf') + # i.save_citf('engine') + # i.read_citf('engine.citf') i.save_image('render.png') - # i.save_edges('debug/edges-render.png') + i.save_edges('debug/edges-render.png') # i.save_image('render.png') # i.save_citf('engine')