Skip to content

Commit

Permalink
Implement support for *meson* build.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Aug 13, 2024
1 parent 89697a0 commit 5e0a337
Show file tree
Hide file tree
Showing 15 changed files with 543 additions and 31,482 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
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/
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.pyc
*.pyo
.DS_Store
poetry.lock
/build/
/dist/
__pycache__
104 changes: 68 additions & 36 deletions README.md
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 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 available 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
Please use the following [Poetry](https://python-poetry.org) command 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]>
6 changes: 5 additions & 1 deletion chromatic_aberration_filtering/__init__.py
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"]
Loading

0 comments on commit 5e0a337

Please sign in to comment.