Open the context
Choose the project folder and name the files or behavior involved.
Apply a repeating two-by-two threshold tile to integer grayscale pixels in matrices up to 64 by 64. Check black, white and threshold equality, rejecting ragged shapes and non-byte or Boolean pixels without changing the input.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def ordered_dither(pixels):
pixels = [tuple(row) for row in pixels]
width = len(pixels[0]) if pixels else 0
if len(pixels) > 64 or width > 64 or any(len(row) != width for row in pixels):
raise ValueError("image.shape")
if any(type(v) is not int or not 0 <= v <= 255 for row in pixels for v in row):
raise ValueError("pixel.byte")
thresholds = ((32, 160), (224, 96))
return [[value >= thresholds[r % 2][c % 2] for c, value in enumerate(row)]
for r, row in enumerate(pixels)]The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.