forked from teboli/chromatic_aberration_filtering
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for *meson* build.
- Loading branch information
Showing
15 changed files
with
581 additions
and
31,482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
name: Build | ||
|
||
on: [ push, pull_request ] | ||
|
||
jobs: | ||
linux-x86_64: | ||
name: Build Wheels on Linux (x86_64) | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
include: | ||
- build: Python 3.10 x86_64 | ||
python: cp310-manylinux_x86_64 | ||
arch: x86_64 | ||
- build: Python 3.11 x86_64 | ||
python: cp311-manylinux_x86_64 | ||
arch: x86_64 | ||
- build: Python 3.12 x86_64 | ||
python: cp312-manylinux_x86_64 | ||
arch: x86_64 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
- name: Install cibuildwheel | ||
run: python -m pip install cibuildwheel==2.20.0 | ||
- name: Build Wheel | ||
run: python -m cibuildwheel --output-dir wheelhouse | ||
env: | ||
CIBW_BUILD: ${{ matrix.python }} | ||
CIBW_ARCHS: ${{ matrix.arch }} | ||
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux }} | ||
CIBW_BUILD_VERBOSITY: 1 | ||
CIBW_TEST_COMMAND: 'pip install "numpy>= 1.24, <2" && time python -c "import numpy as np;from chromatic_aberration_correction import correct_chromatic_aberration;RGB = np.random.random([2160, 3840, 3]).astype(np.float32);correct_chromatic_aberration(RGB, 4, 4, np.array([-0.25, 1.375, -0.125], np.float32), 15.0 / 255, 0.5, 1.0, 1.0, 0.25, 128.0 / 255, 64.0 / 255)"' | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: cibw-wheels-${{ matrix.python }} | ||
path: ./wheelhouse/*.whl | ||
|
||
linux-arm64: | ||
name: Build Wheels on Linux (ARM64) | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
include: | ||
- build: Python 3.10 ARM64 | ||
python: cp310-manylinux_aarch64 | ||
arch: aarch64 | ||
- build: Python 3.11 ARM64 | ||
python: cp311-manylinux_aarch64 | ||
arch: aarch64 | ||
- build: Python 3.12 ARM64 | ||
python: cp312-manylinux_aarch64 | ||
arch: aarch64 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
- name: Setup QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
with: | ||
platforms: all | ||
- name: Install cibuildwheel | ||
run: python -m pip install cibuildwheel==2.20.0 | ||
- name: Build Wheel | ||
run: python -m cibuildwheel --output-dir wheelhouse | ||
env: | ||
CIBW_BUILD: ${{ matrix.python }} | ||
CIBW_ARCHS: ${{ matrix.arch }} | ||
CIBW_MANYLINUX_AARCH64_IMAGE: ${{ matrix.manylinux }} | ||
CIBW_BUILD_VERBOSITY: 1 | ||
CIBW_TEST_COMMAND: 'pip install "numpy>= 1.24, <2" && time python -c "import numpy as np;from chromatic_aberration_correction import correct_chromatic_aberration;RGB = np.random.random([2160, 3840, 3]).astype(np.float32);correct_chromatic_aberration(RGB, 4, 4, np.array([-0.25, 1.375, -0.125], np.float32), 15.0 / 255, 0.5, 1.0, 1.0, 0.25, 128.0 / 255, 64.0 / 255)"' | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: cibw-wheels-${{ matrix.python }} | ||
path: ./wheelhouse/*.whl | ||
|
||
macos-arm64: | ||
name: Build Wheels on macOS (ARM64) | ||
runs-on: macos-latest | ||
|
||
strategy: | ||
matrix: | ||
include: | ||
- build: Python 3.10 ARM64 | ||
python: cp310-macosx_arm64 | ||
arch: arm64 | ||
- build: Python 3.11 ARM64 | ||
python: cp311-macosx_arm64 | ||
arch: arm64 | ||
- build: Python 3.12 ARM64 | ||
python: cp312-macosx_arm64 | ||
arch: arm64 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
- name: Install Dependencies | ||
run: | | ||
brew install libomp llvm | ||
- name: Environment Variables | ||
run: | | ||
echo "MACOSX_DEPLOYMENT_TARGET=14.0" >> $GITHUB_ENV | ||
echo "CC=$(brew --prefix llvm)/bin/clang" >> $GITHUB_ENV | ||
- name: Install cibuildwheel | ||
run: python -m pip install cibuildwheel==2.20.0 | ||
- name: Build Wheel | ||
run: python -m cibuildwheel --output-dir wheelhouse | ||
env: | ||
CIBW_BUILD: ${{ matrix.python }} | ||
CIBW_ARCHS: ${{ matrix.arch }} | ||
CIBW_BUILD_VERBOSITY: 1 | ||
CIBW_TEST_COMMAND: 'pip install "numpy>= 1.24, <2" && time python -c "import numpy as np;from chromatic_aberration_correction import correct_chromatic_aberration;RGB = np.random.random([2160, 3840, 3]).astype(np.float32);correct_chromatic_aberration(RGB, 4, 4, np.array([-0.25, 1.375, -0.125], np.float32), 15.0 / 255, 0.5, 1.0, 1.0, 0.25, 128.0 / 255, 64.0 / 255)"' | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: cibw-wheels-${{ matrix.python }} | ||
path: ./wheelhouse/*.whl | ||
|
||
sdist: | ||
name: Build Sdist | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
- name: Install Package Dependencies | ||
run: python -m pip install build twine | ||
- name: Build Sdist | ||
run: python -m build . --sdist | ||
- name: Check Sdist | ||
run: python -m twine check dist/* | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: cibw-sdist | ||
path: dist/*.tar.gz | ||
|
||
upload-pypi: | ||
name: Upload to Pypi | ||
needs: [linux-x86_64, linux-arm64, macos-arm64, sdist] | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v') | ||
steps: | ||
- uses: actions/setup-python@v5 | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
pattern: cibw-* | ||
path: dist | ||
merge-multiple: true | ||
- uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} | ||
repository-url: https://test.pypi.org/legacy/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.pyc | ||
*.pyo | ||
.DS_Store | ||
poetry.lock | ||
/build/ | ||
/dist/ | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,91 @@ | ||
|
||
# Blind Chromatic Aberration Correction with False Color Filtering | ||
|
||
| <img src="/images/teaser_blurry.png" width="230px"/> | <img src="images/teaser_restored.png" width="230px"/> | | ||
|:----------------------------------------------------:|:-----------------------------------------------------:| | ||
| <i>Aberrated image</i> | <i>Filtered result</i> | | ||
| <img src="https://raw.githubusercontent.com/colour-science/chromatic_aberration_filtering/feature/wheels/images/teaser_blurry.png" width="230px"/> | <img src="https://raw.githubusercontent.com/colour-science/chromatic_aberration_filtering/feature/wheels/images/teaser_restored.png" width="230px"/> | | ||
|:--------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------:| | ||
| <i>Aberrated image</i> | <i>Filtered result</i> | | ||
|
||
This repository contains a non-official [Cython](https://cython.org) implementation of the IEEE Transactions on Image Processing 2013 article [Correction of Axial and Lateral Chromatic Aberration With False Color Filter](https://ieeexplore.ieee.org/document/6357254) by Joonyoung Chang, Hee Kang and Moon Gi Kang. | ||
|
||
This is a repository containing a non-official Cython-based implementation of the IEEE Transactions on Image | ||
Processing 2013 article *Correction of Axial and Lateral Chromatic Aberration With False Color Filter* by | ||
Joonyoung Chang, Hee Kang and Moon Gi Kang. | ||
The method consists in a 1D filter independently run on the columns and rows of an image containing chromatic aberrations. Merging the horizontally and vertically filtered outputs yields the final restored image. Our implementation leverages the multi-threading abilities of Cython to achieve restoration on large images in less than 1 second. | ||
|
||
The method consists in a 1D filter independently run on the columns and rows of an image containing chromatic | ||
aberrations. Merging the horizontally and vertically filtered outputs yields the final restored image. Our | ||
implementation leverages the multi-threading abilities of Cython to achieve restoration on large images in less | ||
than 1 second. | ||
This implementation is part of an [IPOL](https://www.ipol.im) paper describing in the detail the method. If this code is useful to your research, please cite our paper [paper](https://www.ipol.im/pub/art/2023/443/article.pdf). | ||
|
||
This implementation is part of an IPOL paper describing in the detail the method. If this code is useful to your | ||
research please cite our paper [paper (to appear)]<a href="https://ipolcore.ipol.im/demo/clientApp/demo.html?id=443">[demo]</a> | ||
## News | ||
|
||
### News | ||
10/19: Try the [online demo](https://ipolcore.ipol.im/demo/clientApp/demo.html?id=443) using the code! | ||
|
||
10/19: Try the <a href="https://ipolcore.ipol.im/demo/clientApp/demo.html?id=443">online demo</a> using this code! | ||
## Requirements | ||
|
||
### Testing the code | ||
### macOS | ||
|
||
You can test the code with a test JPEG image containing chromatic aberrations. First, compile Cython code | ||
and install the python package with | ||
> bash compile_cython.sh | ||
To benefit from parallelism, [OpenMP](https://openmp.llvm.org) needs to be installed alongside [LLVM](https://llvm.org). | ||
|
||
Assuming [Homebrew](https://brew.sh) is available, their installation is as follows: | ||
|
||
```bash | ||
brew install libomp llvm | ||
``` | ||
|
||
This will create in the *chromatic_aberration_filtering* directory a filter_cython.c file. The file is already shipped with this code. If you do not want | ||
to run cython, simply set to False the *USE_CYTHON* argument in setup.py. Second, you can restore the image with the command line: | ||
> python main.py | ||
The following [Poetry](https://python-poetry.org) command can be used to install the remaining build requirements: | ||
|
||
This will save a 8-bit PNG file containing the restored image. The method can be also used on 16-bit TIFF images | ||
or straight after demosaicking/denoising in a typical ISP pipeline. | ||
```bash | ||
poetry install | ||
``` | ||
|
||
### Requirements | ||
## Configuring | ||
|
||
Please run the pip install command below to install the requirements: | ||
> pip install requirements.txt | ||
[Meson](https://mesonbuild.com/) is used to build the Cython extension, the project can be configured as follows: | ||
|
||
### Description | ||
```bash | ||
poetry run meson build | ||
``` | ||
|
||
The code contains two main modules: filter.py that is a numpy-pure implemention of the paper (and is extremely slow), | ||
and filter_cython.pyx that contains the sources for the Cython implementation (recommanded). | ||
## Building an Editable Build | ||
|
||
After installation/compilation, you can import in any project this code by importing the package | ||
> import chromatic_aberration_filtering | ||
### macOS | ||
|
||
The actual function is | ||
> chromatic_aberration_filtering.chromatic_removal | ||
```bash | ||
CC=$(brew --prefix llvm)/bin/clang poetry run pip install --no-build-isolation --editable . | ||
``` | ||
|
||
Please refer to main.py to see an example of use. | ||
The **Cython** extension will be installed in the **Poetry** virtual environement and available for import. | ||
|
||
### Contact | ||
## Building a Wheel | ||
|
||
If you encounter any problem with the code, please contact me at <[email protected]>. | ||
### macOS | ||
|
||
```bash | ||
CC=$(brew --prefix llvm)/bin/clang poetry run python -m build | ||
``` | ||
|
||
The **wheel** will be available in the `dist` directory. | ||
|
||
## Usage | ||
|
||
The **Cython** extension can be imported as follows: | ||
|
||
```python | ||
import chromatic_aberration_correction | ||
``` | ||
|
||
Then the function to correct chromatic aberration is available to use: | ||
|
||
```python | ||
chromatic_aberration_correction.correct_chromatic_aberration | ||
``` | ||
|
||
Examples are available in the examples directory: [examples/example_correction.py](examples/example_correction.py) | ||
|
||
Note that on macOS, for best performance, it is recommended to set the number of *OpenMP* threads to 1: | ||
|
||
```bash | ||
export OMP_NUM_THREADS=1 | ||
``` | ||
|
||
## Contact | ||
|
||
If you encounter any problem with the code, please use the following contacts: | ||
|
||
- <[email protected]> | ||
- <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
from .filter_cython import chromatic_removal | ||
from .chromatic_aberration_correction import correct_chromatic_aberration | ||
|
||
chromatic_removal = correct_chromatic_aberration | ||
|
||
__all__ = ["correct_chromatic_aberration"] |
Oops, something went wrong.