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
539 additions
and
31,478 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,120 @@ | ||
name: Build | ||
|
||
on: [ push, pull_request ] | ||
|
||
jobs: | ||
linux: | ||
name: Build Wheels on Linux | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
include: | ||
- build: CPython 3.10 x86 64 bits | ||
python: cp310-manylinux_x86_64 | ||
arch: x86_64 | ||
- build: CPython 3.11 x86 64 bits | ||
python: cp311-manylinux_x86_64 | ||
arch: x86_64 | ||
- build: CPython 3.12 x86 64 bits | ||
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 | ||
shell: bash | ||
- name: Build Wheel | ||
run: python -m cibuildwheel --output-dir wheelhouse | ||
shell: bash | ||
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 | ||
|
||
macos: | ||
name: Build Wheels on macOS | ||
runs-on: macos-latest | ||
|
||
strategy: | ||
matrix: | ||
include: | ||
- build: CPython 3.10 ARM 64 bits | ||
python: cp310-macosx_arm64 | ||
arch: arm64 | ||
- build: CPython 3.11 ARM 64 bits | ||
python: cp311-macosx_arm64 | ||
arch: arm64 | ||
- build: CPython 3.12 ARM 64 bits | ||
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 | ||
shell: bash | ||
- name: Build Wheel | ||
run: python -m cibuildwheel --output-dir wheelhouse | ||
shell: bash | ||
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: | ||
needs: [linux, macos, 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 |
---|---|---|
|
@@ -6,54 +6,85 @@ | |
| <i>Aberrated image</i> | <i>Filtered result</i> | | ||
|
||
|
||
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. | ||
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. | ||
|
||
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 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> | ||
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](https://www.ipol.im/pub/art/2023/443/article.pdf). | ||
|
||
### News | ||
## News | ||
|
||
10/19: Try the <a href="https://ipolcore.ipol.im/demo/clientApp/demo.html?id=443">online demo</a> using this code! | ||
10/19: Try the [online demo](https://ipolcore.ipol.im/demo/clientApp/demo.html?id=443)> using this code! | ||
|
||
### Testing the code | ||
## Requirements | ||
|
||
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 | ||
### macOS | ||
|
||
To benefit from parallelism, [OpenMP](https://openmp.llvm.org) needs to be available alongside [LLVM](https://llvm.org). | ||
|
||
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 | ||
Assuming [Homebrew](https://brew.sh) is available, their installation is as follows: | ||
|
||
```bash | ||
brew install libomp llvm | ||
``` | ||
|
||
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. | ||
Please use the following [Poetry](https://python-poetry.org) command to install the remaining build requirements: | ||
|
||
### Requirements | ||
```bash | ||
pip install requirements.txt | ||
``` | ||
|
||
Please run the pip install command below to install the requirements: | ||
> pip install requirements.txt | ||
## Configuring | ||
|
||
### Description | ||
[Meson](https://mesonbuild.com/) is used to build the Cython extension, the project can be configured as follows: | ||
|
||
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). | ||
```bash | ||
poetry install | ||
poetry run meson build | ||
``` | ||
|
||
After installation/compilation, you can import in any project this code by importing the package | ||
> import chromatic_aberration_filtering | ||
## Building an Editable Build | ||
|
||
The actual function is | ||
> chromatic_aberration_filtering.chromatic_removal | ||
### macOS | ||
|
||
Please refer to main.py to see an example of use. | ||
```bash | ||
CC=$(brew --prefix llvm)/bin/clang poetry run pip install --no-build-isolation --editable . | ||
``` | ||
|
||
### Contact | ||
The **Cython** extension will be installed in the **Poetry** virtual environement and available for import. | ||
|
||
## Building a Wheel | ||
|
||
### macOS | ||
|
||
```bash | ||
CC=$(brew --prefix llvm)/bin/clang poetry run python -m build | ||
``` | ||
|
||
A **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 | ||
``` | ||
|
||
An example file is available in 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 contact me at <[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.