[feat] lens correction#255
[feat] lens correction#255antond-weta wants to merge 3 commits intoAcademySoftwareFoundation:mainfrom
Conversation
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #255 +/- ##
==========================================
+ Coverage 90.22% 90.51% +0.29%
==========================================
Files 15 17 +2
Lines 2680 3312 +632
Branches 405 498 +93
==========================================
+ Hits 2418 2998 +580
- Misses 262 314 +52
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
| exiftool_to_oiio = { { "Make", { "cameraMake", false } }, | ||
| { "Model", { "cameraModel", false } }, | ||
| { "LensID", { "lensModel", false } }, | ||
| { "LensModel", { "lensModel", false } }, |
There was a problem hiding this comment.
Exiftool seems to be inconsistent with this field for some cameras. This makes it difficult to decide what to do when both LensID and LensModel are present and hold different value.
BTW I'm expecting this code to be tweaked a fair bit as this functionality gets more use. Collecting metadata from raw images is always a balancing act.
There was a problem hiding this comment.
I've refactored that further to make it a bit more robust. The lensModel thingy is back!
| fetch_lens_parameter( | ||
| lens_make, | ||
| src_spec, | ||
| "lenMake", |
| auto cam = cameras[0]; | ||
|
|
||
| const lfLens **lenses = | ||
| Database->FindLenses( cam, NULL, lens_model.c_str() ); |
There was a problem hiding this comment.
should lens_make be used here instead of NULL?
const char* lens_make_ptr =
lens_make.empty() ? nullptr : lens_make.c_str();
const lfLens** lenses =
Database->FindLenses(cam, lens_make_ptr, lens_model.c_str());
| { | ||
| if ( !apply_aberration_map( | ||
| dst, | ||
| src, |
There was a problem hiding this comment.
at each state of these three calls we give dst and src where is src is seem to be the same object that came in originally. The only reason it works if because our internal called uses same object for dst and src. But this is public API and hence we should handle the case where these two are not the same.
if ( &dst != &src )
dst.copy( src );
...
if ( !apply_vignette_map(
dst,
dst,
...
if ( !apply_aberration_map(
dst,
dst,
...
if ( !apply_distortion_map(
dst,
dst,
or some more robust way.
Also, it seems like you have tests void test_apply_lens_correction() where those two are not the same, so am I correct assuming the result would be only distortion map applied?
There was a problem hiding this comment.
good catch! fixed.
There was a problem hiding this comment.
not sure. I think I understand what LLM is saying, but I rather paste it as-is so nothing is lost in translation:
[image_converter.h (line 374)] documents apply_lens_correction(dst, src) as supporting distinct buffers, but the implementation starts with src_ptr = &src and only switches to dst after a prior stage succeeds [image_converter.cpp (line 1636)]. If the first enabled stage is distortion or aberration, the lower-level code depends on dst being already initialized: distortion takes its temp spec from dst_buffer.spec() [lens_correction.cpp (line 461)], and aberration actually warps from dst_buffer instead of src_buffer [lens_correction.cpp (line 600)], [lens_correction.cpp (line 612)]. Existing success-path tests are in-place for distortion/aberration [testLensCorrection.cpp (line 261)], [testLensCorrection.cpp (line 317)], while the only out-of-place success test is vignetting [testLensCorrection.cpp (line 466)].
Suggested fix: initialize a working buffer from src when dst != src, chain every enabled stage against the previous output, and add explicit out-of-place success tests for distortion-only, aberration-only, and combined correction.
| last_error_message ); | ||
| } | ||
|
|
||
| OIIO::ParamValueList options; |
| .value( | ||
| "CropApplicationError", | ||
| ImageConverter::Status::CropApplicationError ) | ||
| .value( "WriteError", ImageConverter::Status::WriteError ) |
There was a problem hiding this comment.
we need to add
.value(
"DatabaseNotFound", ImageConverter::Status::DatabaseNotFound )
src/docs/lens_correction.rst
Outdated
|
|
||
| rawtoaces \ | ||
| --lens-correction a \ | ||
| --require-lens correction \ |
There was a problem hiding this comment.
| --require-lens correction \ | |
| --require-lens-correction \ |
src/docs/lens_correction.rst
Outdated
| --custom-lens-model "RF 24-105mm F4L IS USM" \ | ||
| --custom-aperture 4.0 \ | ||
| --custom-focal-length 35.0 \ | ||
| --custom-focus_distance 240.0 \ |
There was a problem hiding this comment.
| --custom-focus_distance 240.0 \ | |
| --custom-focus-distance 240.0 \ |
tests/python/test_image_converter.py
Outdated
| converter.settings.custom_lens_make = "custom_lens_model" | ||
| assert converter.settings.custom_lens_make == "custom_lens_model" |
There was a problem hiding this comment.
| converter.settings.custom_lens_make = "custom_lens_model" | |
| assert converter.settings.custom_lens_make == "custom_lens_model" | |
| converter.settings.custom_lens_model = "custom_lens_model" | |
| assert converter.settings.custom_lens_model == "custom_lens_model" |
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
|
Do we want maybe separate status LensCorrectionError for when correction failed? |
| ImageConverter::Settings::LensCorrectionType::None ) | ||
| { | ||
| if ( settings.custom_lens_model.empty() ) | ||
| keys_to_check.push_back( "lensModel" ); |
There was a problem hiding this comment.
shuould we be doing same for lensMake?
| { "aperture", "FNumber" }, | ||
| { "focalLength", "FocalLength" } | ||
| { "cameraMake", "Make" }, { "cameraModel", "Model" }, | ||
| { "lensModel", "LensModel" }, { "lensID", "LensID" }, |
There was a problem hiding this comment.
do we need mapping for lensMake?
| { "Missing the camera model name in the file metadata.", | ||
| " You can provide a custom value using the --custom-camera-model " | ||
| "parameter." }, | ||
| { "Missing the lens model name in the file metadata.", |
There was a problem hiding this comment.
actual message is "Missing the <property> info in the file metadata."
| "Distortion", | ||
| ImageConverter::Settings::LensCorrectionType::Distortion ) | ||
| .value( | ||
| "Vignetting", |
There was a problem hiding this comment.
There is also None
enum class LensCorrectionType
{
None = 0,
Aberration = 1 << 0,
Distortion = 1 << 1,
Vignetting = 1 << 2
};
Description
Implements lens correction functionality
Tests
Checklist:
need to update the documentation, for example if this is a bug fix that
doesn't change the API.)
(adding new test cases if necessary).
already run clang-format before submitting, I definitely will look at the CI
test that runs clang-format and fix anything that it highlights as being
nonconforming.