mirror of
https://github.com/KrisKennaway/ii-pix.git
synced 2024-06-01 06:41:29 +00:00
Suppress pygame message at startup
Keep iterating until N iterations without quality improvement
This commit is contained in:
parent
5111696d5c
commit
613a36909c
17
convert.py
17
convert.py
|
@ -6,9 +6,12 @@ import os.path
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import colour
|
import colour
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pygame
|
|
||||||
from sklearn import cluster
|
from sklearn import cluster
|
||||||
|
|
||||||
|
from os import environ
|
||||||
|
environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
|
||||||
|
import pygame
|
||||||
|
|
||||||
import dither as dither_pyx
|
import dither as dither_pyx
|
||||||
import dither_pattern
|
import dither_pattern
|
||||||
import image as image_py
|
import image as image_py
|
||||||
|
@ -147,8 +150,8 @@ def main():
|
||||||
iigs_palette = np.empty((16, 16, 3), dtype=np.uint8)
|
iigs_palette = np.empty((16, 16, 3), dtype=np.uint8)
|
||||||
|
|
||||||
# TODO: flags
|
# TODO: flags
|
||||||
penalty = 1e9 # 0 # 1e9
|
penalty = 1e9
|
||||||
iterations = 50 # 0
|
iterations = 50
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
# TODO: for some reason I need to execute this twice - the first time
|
# TODO: for some reason I need to execute this twice - the first time
|
||||||
|
@ -160,8 +163,8 @@ def main():
|
||||||
|
|
||||||
total_image_error = 1e9
|
total_image_error = 1e9
|
||||||
cluster_palette = ClusterPalette(rgb)
|
cluster_palette = ClusterPalette(rgb)
|
||||||
image_generation = 0
|
iterations_since_improvement = 0
|
||||||
for iteration in range(iterations):
|
while iterations_since_improvement < iterations:
|
||||||
# TODO: clean this up - e.g. pass in an acceptance lambda to iterate()
|
# TODO: clean this up - e.g. pass in an acceptance lambda to iterate()
|
||||||
old_best_palette_distances = cluster_palette._best_palette_distances
|
old_best_palette_distances = cluster_palette._best_palette_distances
|
||||||
old_palettes_cam = cluster_palette._palettes_cam
|
old_palettes_cam = cluster_palette._palettes_cam
|
||||||
|
@ -181,14 +184,14 @@ def main():
|
||||||
new_total_image_error))
|
new_total_image_error))
|
||||||
total_image_error = new_total_image_error
|
total_image_error = new_total_image_error
|
||||||
palettes_rgb = new_palettes_rgb
|
palettes_rgb = new_palettes_rgb
|
||||||
|
iterations_since_improvement = 0
|
||||||
else:
|
else:
|
||||||
cluster_palette._palettes_cam = old_palettes_cam
|
cluster_palette._palettes_cam = old_palettes_cam
|
||||||
cluster_palette._palettes_rgb = old_palettes_rgb
|
cluster_palette._palettes_rgb = old_palettes_rgb
|
||||||
cluster_palette._best_palette_distances = old_best_palette_distances
|
cluster_palette._best_palette_distances = old_best_palette_distances
|
||||||
|
iterations_since_improvement += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
image_generation += 1
|
|
||||||
|
|
||||||
for i in range(16):
|
for i in range(16):
|
||||||
iigs_palette[i, :, :] = (
|
iigs_palette[i, :, :] = (
|
||||||
np.round(image_py.linear_to_srgb(
|
np.round(image_py.linear_to_srgb(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user