Bug 253941

Summary: Auto lens correction not working correctly
Product: [Applications] digikam Reporter: Alberto Gonzalez <luis6674>
Component: Plugin-Editor-LensCorrectionAssignee: Digikam Developers <digikam-bugs-null>
Severity: normal CC: anaselli, bgmilne, caulier.gilles, dmorganec, kde, romano.giannetti, souloftherobot, sven.burmeister, urcindalo
Priority: NOR    
Version: 2.5.0   
Target Milestone: ---   
Platform: Unlisted Binaries   
OS: Linux   
Latest Commit: Version Fixed In: 3.0.0
Bug Depends on: 312764    
Bug Blocks:    
Attachments: strange lens menu

Description Alberto Gonzalez 2010-10-12 11:47:39 UTC
Version:           1.5.0 (using KDE 4.5.2) 
OS:                Linux

After upgrading to digikam 1.5 the Enhance > Lens > Auto-Correction feature is not working correctly. Instead of fixing the distortion is makes it much bigger. My camera is a Panasonic LX3 and it's correctly detected. In digikam 1.4 it worked as expected.

I guess that a test file is better than further explanations:


Reproducible: Always

Steps to Reproduce:
Load the test file, open the image editor, go to Enhance > Lens > Auto-Correction and see the results.

Actual Results:  
Image turns into a sphere

Expected Results:  
Distortion should be corrected
Comment 1 caulier.gilles 2010-10-12 11:50:53 UTC
Which lensfun version you use ? Go to Help/Component Info dialog for details.

Gilles Caulier
Comment 2 caulier.gilles 2010-10-12 11:59:55 UTC
You said that your camera is detected ? It's impossible : there is no Exif information about your camera maker and model. Also Lens string description from Exif, Makernotes, or XMP do not exist.

Look my screenshot there :


Gilles Caulier
Comment 3 Alberto Gonzalez 2010-10-12 13:51:01 UTC
Hi, thanks for looking into it.

Strange, I have lensfun 2.5 installed in the system, but if I go to Help > Components Information it doesn't show up there (but it neither does in digikam 1.4 and there all works correctly).

Also strange but here it detects the lens as "standard" (and offers the other options in the dropdown menu*) and with that it seems enough to correct the distortion in version 1.4. In 1.5 it still shows the "standard" lens selected by default, but the correction seems to go in the opposite direction and make the distortion much bigger.

*note that this is a compact camera, not an interchangeable lens one, so those options are incorrect.
Comment 4 Alberto Gonzalez 2010-10-12 14:16:09 UTC
By the way, in the "use metadata" I do get a "partial match found", so I might have some newer library that already contains this info about my camera. Here are my components:

digiKam version 1.5.0
Exiv2 can write to Jp2: Yes
Exiv2 can write to Jpeg: Yes
Exiv2 can write to Pgf: No
Exiv2 can write to Png: Yes
Exiv2 can write to Tiff: Yes
Exiv2 supports XMP metadata: Yes
LibCImg: 130
LibExiv2: 0.19
LibJPEG: 80
LibJasper: 1.900.1
LibKDE: 4.5.2 (KDE 4.5.2)
LibKExiv2: 1.1.0
LibKdcraw: 1.1.0
LibLCMS: 119
LibPGF: 6.09.44
LibPNG: 1.4.4
LibQt: 4.7.0
LibRaw: 0.10.0
LibTIFF: LIBTIFF, Version 3.9.4 Copyright (c) 1988-1996 Sam Leffler Copyright (c) 1991-1996 Silicon Graphics, Inc.
Marble widget: 0.10.1
Parallelized demosaicing: Yes
Database backend: QSQLITE
LibGphoto2: 2.4.9
LibKipi: 1.1.0

Just a guess, but maybe digikam 1.4 didn't use lensfun for the lens auto-correction and now digikam 1.5 does use it? And because in my system it cannot detect lensfun being installed it fails to correct the distortion? What I have no idea is how to "force" it to detect lensfun. (I'm using Arch Linux binaries).
Comment 5 caulier.gilles 2010-10-12 14:19:52 UTC
no digiKam use lensfun in all case !

currently lensfun 0.2.5 is published. there is no lensfun version method available in this library to display version information in digiKam

Since digiKam  1.5.0, we include lensfun source code in core. Lensfun source code come from lensfun svn repository : 0.2.5.-1. This code include version method.

Gilles Caulier
Comment 6 Buchan Milne 2010-11-24 16:49:20 UTC
I have the same problem, with images from Canon EOS 500D with EF-S 17-85mm F4-5.6 IS USM.

Images corrected with 1.4.0 (plus patch for https://bugs.kde.org/show_bug.cgi?id=251920) compiled against lensfun 0.2.5 look correct, images corrected with 1.5.0 or 1.6.0 (compiled with same lensfun installed) look worse than the uncorrected image.

I can provide some samples if necessary.

I have downgraded to 1.4.0 for now, but correct batch correction would be nice.
Comment 7 caulier.gilles 2010-11-24 16:56:22 UTC
yes, i'm always interrestd by image samples...

Gilles Caulier
Comment 8 S. Burmeister 2010-11-24 17:01:28 UTC
Same here with a LX3, with the latest svn from the gsoc branch. LX3 is detected correctly.
Comment 9 S. Burmeister 2011-03-05 08:55:31 UTC
There are LX3 sample images in digikam's RAW images repo.
Comment 10 Romano Giannetti 2011-04-14 15:23:56 UTC
Created attachment 58964 [details]
strange lens menu
Comment 11 Romano Giannetti 2011-04-14 15:24:54 UTC
There is something fishy going on here. I have in 1.8.0 and in components it says that it's an external shared library (see at the end). 

Now, the problem is that it seems that the selection of lens does not work. I have a Panasonic LX-5, so I know there is no lens data for it, but before trying to generate one I tried to use the LX3 setup. Well, there are two problems: 

1) in the /usr/share/kde4/apps/digikam/lensfun/compact-panasonic.xml there are 4 variants for LX3 for the various aspect ratio, but in the menu you have just 4 LX3 entry without any hints on which is which. 

2) After that, reading the abovementioned file, I suspect that I should be able to select a lens with the PanasonicLX3 mount, which is just one, the default. Instead I see three completely unrelated lens --- see the screenshot. 

digiKam version 1.8.0
Exiv2 can write to Jp2: Yes
Exiv2 can write to Jpeg: Yes
Exiv2 can write to Pgf: No
Exiv2 can write to Png: Yes
Exiv2 can write to Tiff: Yes
Exiv2 supports XMP metadata: Yes
LibCImg: 130
LibClapack: internal library
LibExiv2: 0.19
LibJPEG: 62
LibJasper: 1.900.1
LibKDE: 4.6.2 (4.6.2)
LibKExiv2: 1.2.0
LibKdcraw: 1.2.0
LibLCMS: 118
LibLensFun: external shared library
LibLqr: internal library
LibPGF: 6.09.44 - internal library
LibPNG: 1.2.44
LibQt: 4.7.0
LibRaw: 0.11.3
LibTIFF: LIBTIFF, Version 3.9.4 Copyright (c) 1988-1996 Sam Leffler Copyright (c) 1991-1996 Silicon Graphics, Inc.
Marble widget: 0.11.0 (Stable Release)
Parallelised demosaicing: Yes
Database backend: QSQLITE
LibGphoto2: 2.4.8
LibKipi: 1.2.0
Comment 12 Romano Giannetti 2011-04-27 11:32:15 UTC
I tested with UFraw, and it let me select the LX3 lens correctly. UFraw uses the 0.2.5 standard version of liblensfun. 

So I still think there is a problem in digiKam; something is going bad with the lens selection tool. 

Moreover, shouldn't lens correction be applied/appliable in the RAW import dialog? Although probably it's not so important, if the conversion is a 16-bit one.
Comment 13 souloftherobot 2011-10-03 19:01:41 UTC

I have a Fuji s9600 and have the same problem described above, in that the Auto Lens Correction warps photos. The warp is basically spherical and can be really extreme, especially at wide angle.

As was also mentioned, I would need to fall back to a distro that uses Digikam 1.4 - all versions since have this problem.

I use the s9500 entry (as the 9500/9600 share the same lens) in ShowFoto's Auto Lens Correction.

This problem is a shame as the Lens Correction tool (Digikam 1.4 or lower) really improves photos taken with the s9600 - but I have to run a 2nd distro in order to use the Lens Correction.

Don't know if it is important, but un-ticking the distortion option removes the warping - but unfortunately, the distortion option is what makes the improvement to the photos (or did, in Digikam 1.4 or lower of course).

Any ideas?

Sorry if this is not very clear - it's my first ever bug report.
Comment 14 caulier.gilles 2011-12-17 19:07:17 UTC

This file still valid using digiKam 2.4 ?

Gilles Caulier
Comment 15 Alberto Gonzalez 2011-12-18 00:15:06 UTC
I still haven't upgraded to 2.4, but with 2.3 the issue is still there. I will try to upgrade soon and report back.
Comment 16 Alberto Gonzalez 2012-01-06 00:34:12 UTC
Tested with digikam 2.5 now and the problem is still present.
Comment 17 urcindalo 2012-08-08 22:35:05 UTC
I just installed digikam 2.6.0 and 2.7.0 on my Gentoo 64bit box. In both cases the lensfun version installed is 2.6.0.

My camera is an Olympus E-PM1 with an M.Zuiko 14-42mm lens. The corresponding exif data from my pictures, as reported by exiftool, are:

Image Description               : OLYMPUS DIGITAL CAMERA
Make                            : OLYMPUS IMAGING CORP.
Camera Model Name               : E-PM1
---- Olympus ----
Special Mode                    : Normal, Sequence: 0, Panorama: (none)
Camera ID                       : OLYMPUS DIGITAL CAMERA
Equipment Version               : 0100
Camera Type 2                   : E-PM1
Serial Number                   : BB9501686
Internal Serial Number          : 4134108006711001
Focal Plane Diagonal            : 21.6 mm
Body Firmware Version           : 1.301
Lens Type                       : Olympus M.Zuiko Digital ED 14-42mm F3.5-5.6 II R
Lens Serial Number              : ABG235236
Lens Model                      : OLYMPUS M.14-42mm F3.5-5.6 II R
Lens Firmware Version           : 1.102

Digikam is not able to detect my lens. My camera model can be found among the options for "OLYMPUS CORPORATION", but the lens options appearing are only the "Standard" plus the ones from the already-attached "strange lens menu" picture.

The gimplensfun 0.2.2 (a plug-in for GIMP) allows me to correctly select my lens model. Why can't I do that in digikam?
Comment 18 caulier.gilles 2013-01-07 10:23:42 UTC
Git commit 8b3eb6f0b498ae11729e0880e7ac0673b2dd2bd8 by Gilles Caulier.
Committed on 07/01/2013 at 11:16.
Pushed by cgilles into branch 'master'.

Apply patch #76254 from Roman I Khimov about lensfun interface which don't mangle cropFactor if it's set.
This behaviour was introduced by polish commit bebef401e147a00f859cb81774f8498a0623eee5.
With this branch present we always get cropFactor of
-1.0 in LensFunFilter::filterImage() and given that lensfun library just uses
crop factor of 1 which leads to obviously wrong calculations for cropped
Related: bug 312764, bug 266204, bug 267613, bug 281783, bug 284708
FIXED-IN: 3.0.0
CCMAIL: rik@osrc.info

M  +0    -4    libs/dimg/filters/lens/lensfuncameraselector.cpp

Comment 19 caulier.gilles 2013-01-07 10:37:38 UTC
Git commit 613d004121682d122e9ea7fd9041a7bbc49acb89 by Gilles Caulier.
Committed on 07/01/2013 at 11:34.
Pushed by cgilles into branch 'master'.

Apply patch #76256 from Roman I Khimov to use crop factor from camera, not from lens data.
Lens crop factor in DB only tells us which crop factor was used for lens
calibration data, but it has nothing to do with shots made on random user's
camera. So the default behaviour should be to use camera's crop factor and only
fallback to lens data if there in no data present for camera. As "this should
not happen" it's appropriate to spit out some debug message in this case.

Ref: http://lensfun.berlios.de/manual/el_lens.html
Ref: http://lensfun.berlios.de/manual/el_camera.html
Related: bug 312766, bug 312764, bug 266204, bug 267613, bug 281783, bug 284708
FIXED-IN: 3.0.0
CCMAIL: roman@khimov.ru

M  +2    -1    libs/dimg/filters/lens/lensfuncameraselector.cpp
M  +1    -1    libs/dimg/filters/lens/lensfuniface.cpp

Comment 20 caulier.gilles 2013-01-07 10:41:44 UTC
Git commit 70cf9beaac9996c219f988d8ae74d75dc253c0ad by Gilles Caulier.
Committed on 07/01/2013 at 11:39.
Pushed by cgilles into branch 'master'.

Apply patch #76255 from Roman I Khimov to don't pass crop factor as scale factor to lensfun.

Sixth parameter to Initialize() is actually a scale factor which has nothing
in common with crop factor. I think it's safe to assume that we want no
scaling from lensfun and thus use the value of one.

Ref: http://lensfun.berlios.de/manual/structlfModifier.html
Related: bug 312765, bug 312764, bug 266204, bug 267613, bug 281783, bug 284708
FIXED-IN: 3.0.0
CCMAIL: roman@khimov.ru

M  +1    -1    libs/dimg/filters/lens/lensfunfilter.cpp