First, checkout the repository:
git clone https://github.com/afichet/camera-calibration.git
cd camera-calibration
git submodule init
git submodule updateOn all platforms, you need CMake, a C and a C++ compiler.
We compile levmar without BLAS / LAPACK to have simple compilation
pipeline on those platforms. You can re-enable it in the
external/levmar-2.6/CMakeLists.txt for better performances.
You need f2c (libf2c2-dev on Ubuntu 20.04LTS), BLAS / LAPACK. See
http://users.ics.forth.gr/~lourakis/levmar/
mkdir build
cd build
cmake ..
makeWe currently support TIFF and EXR images for reading and
writting. TIFF are supported only if libtiff is available on the
system.
Colourotron is a GUI application to fit a correction matrix from a shot of a
Macbeth colourchecker. The source code is in the app/gui folder.
extract-patches is used for creating a CSV file from an image and a
CSV containing the areas to average. The CSV file contains the top
left pixel and bottom right pixel for the box to extract.
<top left x>, <top left y>, <bottom left x>, <bottom right y>
...You can control which area are averaged using the overlay-areas
utility.
overlay-areas is used to display an overlay of the area that are
going to be averaged by extract-patches utility.
gen-ref-colorchart is used to create a CSV file containing the XYZ
values of each color patch from reference measured data (available
here: https://www.babelcolor.com/colorchecker-2.htm) given an
illuminant and color matching functions (CMFs).
gen-colorchart-image creates a PNG preview of a given CSV file
containing color values of each patch of a Macbeth colorchecker.
extract-matrix fits a transformation matrix from a measured set of
colors to a reference set of colors.
correct-patches corrects color values of each patches contained in a
CSV file using the provided transformation matrix.
correct-image corrects color values of each pixel from a TIFF or EXR
file using the provided transformation matrix.
raw-to-dng handles the propriatery RAW format this application targets and
outputs a standard DNG file. It requires a calibration matrix that can be
extracted using Colourotron fitting feature.
We provide a pipeline example in run.sh script.
This is the recommended solution.
Open your image with Colourotron.
1- Move the Macbeth outline to match the captured Macbeth.
2- Click on Fit....
3- Click on Apply.
4- Save the matrix with File -> Save correction matrix...
This matrix can then be used with the command line tools.
To perform colour correction, you either can convert the propriatery RAW to DNG
or first debayer the image and apply the correction matrix. To debayer the
image, use derawzinator:
./build/bin/derawzinator \
raw_image_INFO.txt \
raw_image.exrWe can correct any given RGB image using the matrix:
./build/bin/correct-image \
data/measurements/Colors_0000000320_dem.tiff \
output/matrix.csv \
output/corrected_image.tiffYou can also convert the propriatery RAW format to DNG:
./build/bin/raw-to-dng \
raw_image_INFO.txt \
output/matrix.csv \
output/output.dngFirst, you need to extract from a TIFF file the values of the Macbeth color checker. You need as well a CSV file (comma separated) describing each area to average.
mkdir output
./build/bin/extract-patches
data/measurements/Colors_0000000320_dem.tiff \
data/measurements/boxes.csv \
output/patches.csvThen, you need to generate a reference set of Macbeth patches given an illuminant and color matching functions:
./build/bin/gen-ref-colorchart \
data/D65.csv \
data/XYZ.csv \
output/reference.csvNow, let's see how this reference colour chart looks like:
./build/bin/gen-colorchart-image \
output/reference.csv \
output/reference.exrAnd how the averaged measured one looks like:
./build/bin/gen-colorchart-image \
output/patches.csv \
output/orig_measured.exr \
trueNow, we want to find the matrix which transform the measured color to the reference colors:
./build/bin/extract-matrix \
output/reference.csv \
output/patches.csv \
output/matrix.csvFinally, we correct the measured patches:
./build/bin/correct-patches \
output/patches.csv \
output/matrix.csv \
output/corrected_patches.csvAnd, create an image of the corrected patches:
./build/bin/gen-colorchart-image \
output/corrected_patches.csv \
output/corrected_measured.exrWe also can correct any given image using the matrix, here the input image:
./build/bin/correct-image \
data/measurements/Colors_0000000320_dem.tiff \
output/matrix.csv \
output/corrected_image.tiffYou can also convert the propriatery RAW format to DNG:
./build/bin/raw-to-dng \
raw_image_INFO.txt \
output/matrix.csv \
output/output.dng