pixelshop is a python fluent interface wrapper for image manipulation using the open-source Computer Vision library OpenCV.
This approach allows method chaining, making the code more legible. To avoid unwanted side effects a deep copy is created before each method call.
Warning
pixelshop is in development.
#!/usr/bin/env python3
from pixelshop.flags import ThresholdTypes
from pixelshop.image import DevelopedImage
bon = (
DevelopedImage.fromFile("examples/bon.jpg", proxyPixelCount=500 * 500)
.useProxy() # Proceed with a low resolution version to improve speed
.appendToFilename("small")
.saveImage()
.colorBGR2HSV() # Convert to HSV
.keepChannels(keepChannels=[1, 3, 3]) # Keep the average of channels 1, 3 and 3
.denoise(strength=15) # Denoise
.morphologicalTransformClosing(kernelSize=(3, 3), iterations=2) # Remove text
.adaptiveThreshold(
thresholdType=ThresholdTypes.THRESH_BINARY,
blockSize=1000,
C=-12,
) # Threshold the image to get silhouette
.morphologicalTransformClosing(kernelSize=(3, 3), iterations=3) # Final clean up
.appendToFilename("silhouette")
.saveImage()
.show() # Display result
)
original | silhouette |
---|---|
#!/usr/bin/env python3
from pixelshop.flags import ThresholdTypes
from pixelshop.image import DevelopedImage
bon = (
DevelopedImage.fromFile("examples/sudoku.png", proxyPixelCount=500 * 500)
.useProxy() # Proceed with a low resolution version to improve speed
.appendToFilename("small")
.saveImage()
.colorBGR2Gray() # Convert to gray
.show()
.denoise(strength=3)
.show()
.adaptiveThreshold(
thresholdType=ThresholdTypes.THRESH_BINARY, blockSize=250
) # Threshold the image to get grid
.appendToFilename("enhanced")
.saveImage()
.show() # Display result
)
original | silhouette |
---|---|
- Install
uv
by following Astral's Getting Started guide.- macOS: using Homebrew with
brew install uv
- macOS: using Homebrew with
-
Clone the repository using
git clone https://github.com/davidclemens/pixelshop.git <local-path-to-clone-to>
. -
Create a virtual python environment
-
cd
into the directory of the repository (<local-path-to-clone-to>
above) -
Create a virtual python 3.12 environment with
uv venv -p 3.12
-
-
Install Python dependencies
-
Activate the virtual environment with
source .venv/bin/activate
-
Install the requirements with
uv pip install -r requirements.txt
-
The method chaining without side effects is implemented in the @chainable
decorator.