API Reference
Welcome to the complete API reference for BayerDithering.
Types & Aliases
These custom type aliases are used throughout the library to ensure static typing safety and make function signatures cleaner.
BayerDithering.core.MediaInput: TypeAlias = Union[NDArray[np.uint8], cv2.VideoCapture, Any]
module-attribute
Represents the accepted input formats for the dithering process. Can be a raw NumPy image array, an OpenCV VideoCapture stream, or an imageio GIF reader.
BayerDithering.core.MediaOutput: TypeAlias = Union[NDArray[np.uint8], ProcessedVideo, ProcessedGIF]
module-attribute
Represents the possible outputs returned by the dithering orchestrator, depending on the input provided.
BayerDithering.core.RGBColor: TypeAlias = tuple[int, int, int]
module-attribute
A standard RGB color representation using a tuple of three integers (0-255).
BayerDithering.core.ColorFilter: TypeAlias = tuple[RGBColor, RGBColor]
module-attribute
A duotone palette consisting of two RGBColor tuples: (light_color, dark_color).
Core Processing
Below are the primary classes responsible for orchestrating the dithering process and configuring the media pipeline.
BayerDithering.DitherConfig
dataclass
Main configuration for the Bayer Dithering process.
Attributes:
| Name | Type | Description |
|---|---|---|
b_matrix |
NDArray[float32]
|
Normalized Bayer matrix (values from 0.0 to 1.0). |
contrast |
float
|
Contrast multiplier applied before dithering (default: 1.5). |
sharpness |
float
|
Intensity of the unsharp mask filter (default: 1.6). |
downscale_factor |
int
|
Factor by which the input is downscaled before processing (default: 1). |
upscale |
bool
|
If True, resizes the processed image back to its original dimensions (default: False). |
filter |
Optional[ColorFilter]
|
Tuple with two RGB colors (light, dark) to apply as a duotone palette (default: None). |
Source code in BayerDithering/core.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
BayerDithering.BayerDither
Main orchestrator for the Bayer Dithering library.
Handles media routing (images vs. video) and delegates the actual computation to the injected processor (CPU or GPU).
Source code in BayerDithering/dither.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
__init__(processor: MediaProcessor, verbose: bool = False) -> None
Initializes the Dithering orchestrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processor
|
MediaProcessor
|
An initialized instance of CPUProcessor or GPUProcessor. |
required |
verbose
|
bool
|
Enables detailed DEBUG logging. Defaults to False. |
False
|
Source code in BayerDithering/dither.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
apply(media: MediaInput) -> MediaOutput
Unified method to apply the dithering effect to supported media streams.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
media
|
MediaInput
|
cv2.VideoCapture, NDArray (image), or imageio.Reader (GIF). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MediaOutput |
MediaOutput
|
The processed result (NDArray, ProcessedVideo, or ProcessedGIF). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the media type is not supported. |
Source code in BayerDithering/dither.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
apply_to_gif(gif_reader: imageio.v2.LegacyReader) -> ProcessedGIF
Applies the dithering process to an animated GIF stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gif_reader
|
LegacyReader
|
An opened imageio Reader object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ProcessedGIF |
ProcessedGIF
|
A wrapper object containing the path to the temporary processed GIF. |
Source code in BayerDithering/dither.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
apply_to_image(image: NDArray[np.uint8]) -> NDArray[np.uint8]
Applies the dithering process to a single image array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[uint8]
|
The source image as a NumPy array (BGR format). |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
NDArray[np.uint8]: The processed image as a NumPy array. |
Source code in BayerDithering/dither.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
apply_to_video(video: cv2.VideoCapture) -> ProcessedVideo
Applies the dithering process to an entire video stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
VideoCapture
|
An opened OpenCV VideoCapture object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ProcessedVideo |
ProcessedVideo
|
A wrapper object containing the path to the processed temporary video file. |
Source code in BayerDithering/dither.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
get_available_devices() -> list[str]
staticmethod
Checks the system for supported processing hardware.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: A list of available devices. Will always include 'cpu', and will include 'gpu' if Taichi detects a valid backend (CUDA, Vulkan, or Metal). |
Source code in BayerDithering/dither.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
Hardware Backends
The library delegates the heavy computational lifting to these MediaProcessor classes. The GPUProcessor leverages the Taichi framework for massive parallel execution, while the CPUProcessor uses optimized NumPy and OpenCV routines as a fallback.
BayerDithering.core.MediaProcessor
Bases: ABC
Base interface for all media processors (CPU and GPU).
Source code in BayerDithering/core.py
43 44 45 46 47 48 49 50 | |
BayerDithering.CPUProcessor
Bases: MediaProcessor
Pure CPU implementation for Bayer Dithering.
Ideal for processing single images or when hardware acceleration (GPU) is unavailable.
Source code in BayerDithering/cpu.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
adjust_contrast(image: NDArray[np.uint8]) -> NDArray[np.uint8]
Adjusts the contrast of an image based on its mean luminance.
The intensity of the adjustment is controlled by DitherConfig.contrast.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[uint8]
|
A grayscale image array. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
NDArray[np.uint8]: The contrast-adjusted grayscale image. |
Source code in BayerDithering/cpu.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
apply_color_filter(image: NDArray[np.uint8], colors: ColorFilter) -> NDArray[np.uint8]
staticmethod
Applies a duotone filter to a binarized image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[uint8]
|
Binarized grayscale image (values 0 and 255 only). |
required |
colors
|
ColorFilter
|
A tuple containing (light_color_rgb, dark_color_rgb). |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
NDArray[np.uint8]: Colored image in BGR format. |
Source code in BayerDithering/cpu.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
bayer_dither_array(image_array: NDArray[np.uint8]) -> NDArray[np.uint8]
Applies the Bayer thresholding to a grayscale image array.
It utilizes the pre-computed matrix defined in DitherConfig.b_matrix, tiling it across the entire image to determine pixel activation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_array
|
NDArray[uint8]
|
The pre-processed grayscale image. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
NDArray[np.uint8]: The binarized image (containing only 0 or 255 values). |
Source code in BayerDithering/cpu.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
downscale(image: NDArray[np.uint8]) -> NDArray[np.uint8]
Reduces the image resolution based on the configured downscale factor.
This uses the value defined in DitherConfig.downscale_factor to divide the original dimensions, achieving a more pixelated retro look.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[uint8]
|
The original input image. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
NDArray[np.uint8]: The downscaled image. |
Source code in BayerDithering/cpu.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
process_frame(image: NDArray[np.uint8]) -> NDArray[np.uint8]
Executes the full CPU processing pipeline on a single frame.
The pipeline order is: Grayscale Conversion -> Contrast -> Sharpening -> Downscaling -> Bayer Dithering -> Color Filtering (Optional) -> Upscaling (Optional).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[uint8]
|
The raw input image in BGR format. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
NDArray[np.uint8]: The final processed and dithered image. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided input image is None. |
Source code in BayerDithering/cpu.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
sharpen(image: NDArray[np.uint8]) -> NDArray[np.uint8]
Applies an unsharp mask filter to enhance edges.
The intensity of the sharpening is controlled by DitherConfig.sharpness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[uint8]
|
A grayscale image array. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
NDArray[np.uint8]: The sharpened grayscale image. |
Source code in BayerDithering/cpu.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
upscale(image: NDArray[np.uint8], target_size: tuple[int, int]) -> NDArray[np.uint8]
staticmethod
Resizes the image to a target size using nearest-neighbor interpolation.
Triggered when DitherConfig.upscale is set to True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[uint8]
|
The processed, downscaled image. |
required |
target_size
|
tuple[int, int]
|
The desired (width, height) to restore. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
NDArray[np.uint8]: The upscaled image. |
Source code in BayerDithering/cpu.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
BayerDithering.GPUProcessor
Bases: MediaProcessor
GPU-accelerated implementation for Bayer Dithering using Taichi.
Highly recommended for video processing due to its massive parallelization capabilities.
Source code in BayerDithering/gpu.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
compute_batch_mean(frames: ti.types.ndarray(dtype=(ti.u8), ndim=4), batch_len: ti.i32, src_h: ti.i32, src_w: ti.i32) -> ti.f32
Parallel reduction kernel to compute the mean luminance of an entire video batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
ndarray(dtype=u8, ndim=4)
|
The batch of input frames. |
required |
batch_len
|
i32
|
The number of frames currently in the batch. |
required |
src_h
|
i32
|
The height of the source frames. |
required |
src_w
|
i32
|
The width of the source frames. |
required |
Returns:
| Type | Description |
|---|---|
f32
|
ti.f32: The overall mean grayscale value of the batch. |
Source code in BayerDithering/gpu.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
get_gray(frames: ti.template(), n: ti.i32, y: ti.i32, x: ti.i32) -> ti.f32
Taichi sub-function to extract and convert a specific BGR pixel to grayscale luminance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
template()
|
The Taichi field or ndarray containing the image batch. |
required |
n
|
i32
|
The index of the frame within the batch. |
required |
y
|
i32
|
The vertical coordinate (row) of the pixel. |
required |
x
|
i32
|
The horizontal coordinate (column) of the pixel. |
required |
Returns:
| Type | Description |
|---|---|
f32
|
ti.f32: The calculated grayscale luminance value (0.0 to 255.0). |
Source code in BayerDithering/gpu.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
process_frame(image: NDArray[np.uint8]) -> NDArray[np.uint8]
Executes the GPU pipeline for a single frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
NDArray[uint8]
|
Input image in BGR format. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
NDArray[np.uint8]: Processed dithered image. |
Source code in BayerDithering/gpu.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
process_video_batch(batch: list[NDArray[np.uint8]]) -> NDArray[np.uint8]
Manages the memory transfer and execution of the GPU kernel for a batch of frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
list[NDArray[uint8]]
|
A list of raw BGR frames. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
NDArray[np.uint8]: A numpy array containing the processed frames. |
Source code in BayerDithering/gpu.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
process_video_batch_kernel(frames: ti.types.ndarray(dtype=(ti.u8), ndim=4), out_frames: ti.types.ndarray(dtype=(ti.u8), ndim=4), batch_len: ti.i32, src_h: ti.i32, src_w: ti.i32, out_h: ti.i32, out_w: ti.i32, downscale: ti.i32, contrast: ti.f32, mean_val: ti.f32, sharpness: ti.f32, use_filter: ti.i32, r0: ti.u8, g0: ti.u8, b0: ti.u8, r1: ti.u8, g1: ti.u8, b1: ti.u8)
Core GPU kernel that applies unsharp masking, contrast adjustment, and Bayer dithering to a batch of frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
ndarray(dtype=u8, ndim=4)
|
The input batch of frames in BGR format. |
required |
out_frames
|
ndarray(dtype=u8, ndim=4)
|
The output buffer where processed frames are written. |
required |
batch_len
|
i32
|
The number of frames currently in the batch. |
required |
src_h
|
i32
|
The original height of the source frames. |
required |
src_w
|
i32
|
The original width of the source frames. |
required |
out_h
|
i32
|
The target height of the output frames (after downscaling). |
required |
out_w
|
i32
|
The target width of the output frames (after downscaling). |
required |
downscale
|
i32
|
The factor by which the image is scaled down. |
required |
contrast
|
f32
|
The contrast multiplier to apply. |
required |
mean_val
|
f32
|
The mean luminance of the batch used as a pivot for contrast adjustment. |
required |
sharpness
|
f32
|
The intensity of the unsharp mask filter. |
required |
use_filter
|
i32
|
Flag indicating whether to apply a custom color palette (1 for True, 0 for False). |
required |
r0
|
u8
|
Red channel of the dark color palette. |
required |
g0
|
u8
|
Green channel of the dark color palette. |
required |
b0
|
u8
|
Blue channel of the dark color palette. |
required |
r1
|
u8
|
Red channel of the light color palette. |
required |
g1
|
u8
|
Green channel of the light color palette. |
required |
b1
|
u8
|
Blue channel of the light color palette. |
required |
Source code in BayerDithering/gpu.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
Utilities & Media Wrappers
Helper classes used internally to securely manage temporary file streams, merge audio, and ensure proper cleanup from the disk after the processing is finished.
BayerDithering.utils.ProcessedVideo
Wrapper for a processed video saved in a temporary file.
Provides utility methods to save the final video, merge the original audio, and safely clean up the temporary files from the disk using a context manager.
Source code in BayerDithering/utils.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
__init__(path: str, log_level: int) -> None
Initializes the ProcessedVideo wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The absolute path to the temporary processed video file. |
required |
log_level
|
int
|
The logging level inherited from the main orchestrator. |
required |
Source code in BayerDithering/utils.py
22 23 24 25 26 27 28 29 30 31 32 33 34 | |
open() -> cv2.VideoCapture
Opens the processed video file for reading.
Returns:
| Type | Description |
|---|---|
VideoCapture
|
cv2.VideoCapture: An OpenCV VideoCapture object pointing to the processed video. |
Source code in BayerDithering/utils.py
36 37 38 39 40 41 42 43 44 45 | |
release() -> None
Closes the video capture and deletes the temporary video file from the disk.
Source code in BayerDithering/utils.py
112 113 114 115 116 117 118 119 120 121 | |
save(path: str) -> None
Saves the processed video to the specified destination path without audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The destination file path (e.g., 'output.mp4'). |
required |
Source code in BayerDithering/utils.py
47 48 49 50 51 52 53 54 55 56 | |
save_with_audio(original_video_path: str, path: str) -> None
Merges the audio track from the original video into the processed video.
Requires FFmpeg to be installed and available in the system's PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_video_path
|
str
|
The path to the source video containing the audio track. |
required |
path
|
str
|
The destination file path for the final merged video. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the FFmpeg executable is not found in the system PATH. |
ValueError
|
If the original_video_path is empty. |
FileNotFoundError
|
If the original_video_path does not exist on the disk. |
Source code in BayerDithering/utils.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
BayerDithering.utils.ProcessedGIF
Wrapper for a processed animated GIF saved in a temporary file.
Source code in BayerDithering/utils.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
release() -> None
Deletes the temporary GIF file from the disk.
Source code in BayerDithering/utils.py
143 144 145 146 147 | |
save(dest_path: str) -> None
Saves the processed GIF to the specified destination path.
Source code in BayerDithering/utils.py
137 138 139 140 141 | |
BayerDithering.utils.load_filters() -> dict[str:ColorFilter]
Source code in BayerDithering/utils.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Matrix Generation & Presets
Here you can find the dynamic matrix generator and the pre-computed matrix presets available for immediate use.
BayerDithering.matrices = {'2x2': bayer_matrix_2x2, '4x4': bayer_matrix_4x4, '8x8': bayer_matrix_8x8}
module-attribute
A dictionary containing pre-computed, normalized Bayer matrices for quick access.
Available keys:
- '2x2'
- '4x4'
- '8x8'
BayerDithering.generate_bayer_matrix(order: int) -> NDArray[np.float32]
Generates a Bayer matrix of size (2^order x 2^order).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
int
|
The order of the matrix (e.g., 1 for 2x2, 2 for 4x4, 3 for 8x8). |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float32]
|
NDArray[np.float32]: The normalized Bayer matrix. |
Source code in BayerDithering/matrix.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |