PixelOE (Detail-Oriented Pixelization)
PixelOE is a Python library for detail-oriented image pixelization based on a contrast-aware outline expansion algorithm. It's designed to create pixel art-style images while preserving key details. The current version is 0.1.4, and the library appears to be actively maintained with releases as features and improvements are developed.
Common errors
-
ModuleNotFoundError: No module named 'pixeloe'
cause The pixeloe library has not been installed or is not accessible in the current Python environment.fixInstall the library using pip: `pip install pixeloe` -
AttributeError: 'numpy.ndarray' object has no attribute 'convert'
cause You are attempting to pass a NumPy array (e.g., from OpenCV) directly to `pixeloe.pixelize`, but it expects a `PIL.Image` object.fixConvert your NumPy array to a PIL Image. Example: `from PIL import Image; pil_img = Image.fromarray(cv2.cvtColor(numpy_img, cv2.COLOR_BGR2RGB))` -
AttributeError: 'Image' object has no attribute 'to_numpy'
cause You're trying to save a `PIL.Image` object returned by `pixeloe.pixelize` using a method that expects a NumPy array (e.g., `cv2.imwrite`).fixSave the PIL Image directly using its `save()` method: `output_pil_image.save('output.png')` or convert it to a NumPy array first if you need to use OpenCV functions: `numpy_array = np.array(pil_image)`.
Warnings
- gotcha PixelOE requires Python 3.10 or newer. Installing on older Python versions will fail or result in dependency issues.
- gotcha The `pixelize` function exclusively expects a `PIL.Image` object as input. Passing NumPy arrays (common for OpenCV) or other image formats will lead to `AttributeError` or `TypeError`.
- gotcha Processing very large images (e.g., several megapixels) can be slow and consume significant memory due to the detailed analysis performed by the algorithm. Consider downscaling images if performance is critical.
Install
-
pip install pixeloe
Imports
- pixelize
from pixeloe import pixelize
import pixeloe output_image = pixeloe.pixelize(...)
Quickstart
from PIL import Image
import pixeloe
import os
# Create a dummy image for demonstration
img_path = "example_input.png"
Image.new('RGB', (100, 100), color = 'red').save(img_path)
# Load the image
img = Image.open(img_path).convert("RGB")
# Pixelize the image with specified parameters
# pixels: size of pixelization blocks
# contrast: contrast awareness level
# outline: whether to include outlines
# levels: number of color levels to quantize to
out_img = pixeloe.pixelize(img, pixels=8, contrast=250, outline=True, levels=8)
# Save the output image
output_path = "pixelized_output.png"
out_img.save(output_path)
print(f"Original image saved to {img_path}")
print(f"Pixelized image saved to {output_path}")
# Clean up dummy image
os.remove(img_path)