| 54 | return 0.114 * blue + 0.587 * green + 0.299 * red |
| 55 | |
| 56 | def process(self) -> None: |
| 57 | for y in range(self.height): |
| 58 | for x in range(self.width): |
| 59 | greyscale = int(self.get_greyscale(*self.input_img[y][x])) |
| 60 | if self.threshold > greyscale + self.error_table[y][x]: |
| 61 | self.output_img[y][x] = (0, 0, 0) |
| 62 | current_error = greyscale + self.error_table[y][x] |
| 63 | else: |
| 64 | self.output_img[y][x] = (255, 255, 255) |
| 65 | current_error = greyscale + self.error_table[y][x] - 255 |
| 66 | """ |
| 67 | Burkes error propagation (`*` is current pixel): |
| 68 | |
| 69 | * 8/32 4/32 |
| 70 | 2/32 4/32 8/32 4/32 2/32 |
| 71 | """ |
| 72 | self.error_table[y][x + 1] += int(8 / 32 * current_error) |
| 73 | self.error_table[y][x + 2] += int(4 / 32 * current_error) |
| 74 | self.error_table[y + 1][x] += int(8 / 32 * current_error) |
| 75 | self.error_table[y + 1][x + 1] += int(4 / 32 * current_error) |
| 76 | self.error_table[y + 1][x + 2] += int(2 / 32 * current_error) |
| 77 | self.error_table[y + 1][x - 1] += int(4 / 32 * current_error) |
| 78 | self.error_table[y + 1][x - 2] += int(2 / 32 * current_error) |
| 79 | |
| 80 | |
| 81 | if __name__ == "__main__": |