Beep6581 / RawTherapee

A powerful cross-platform raw photo processing program
https://rawtherapee.com
GNU General Public License v3.0
2.89k stars 323 forks source link

LCP (Lens Correction Profile) support #1327

Closed Beep6581 closed 9 years ago

Beep6581 commented 9 years ago

Originally reported on Google Code with ID 1343

Sorry, no patch yet, but following our new process of announcing when you begin a larger
endavour, I just want to mention that I'll try to develop a RT LCP profile engine.

There are not only Adobe official LCP profiles available, there also seem to be a community
of user generated profiles. There also is good tool support to generate these profiles
yourself.
http://labs.adobe.com/technologies/lensprofile_creator/

First version is planned to just cover automatic distortion correction. The UI will
be super simple, a selection of the LCP file in the style of the existing DCP profile
selection. The other corrections, auto-searching etc. will be kept up for later versions.

Will take a while though, no hurry.

Reported by oduis@hotmail.com on 2012-04-26 19:32:29

Beep6581 commented 9 years ago
There must be something very basic wrong. The lcms23 is distributed with all my official
builds for several month now, and now complains so far.

Reported by oduis@hotmail.com on 2012-05-19 08:08:44

Beep6581 commented 9 years ago
FYI, I use a rawtherapee_launcher.bat to startup RT, which makes sure there is no confusion
by wrong order of folders in path settings. I do not want to add MinGW & gtkmm to my
system path. This should make things less error prone.

set PATH=.;C:\MinGW64\bin;C:\gtkmm64\bin;%PATH%
.\rawtherapee

Reported by globetrotter.75d on 2012-05-19 08:16:27

Beep6581 commented 9 years ago
Ok, I recopied and repacked and reuploaded the Win64 dependencies, just to be sure (?)

However this does not explain why it doesn't work on Globetrotters machine but on mine.
I packed my build with the patch and the current runtime up here:
http://www.visualbakery.com/RawTherapee/Download/RTTest.7z
It works great on my machine, also using your test image.
Can you unpack that all (not just the exe) to a folder and fire up rawtherapee.exe?

Reported by oduis@hotmail.com on 2012-05-19 08:32:50

Beep6581 commented 9 years ago
Just to proove that I'm not dumb: this is your reference image with your PP3 developed
with the LCP profile:
http://www.visualbakery.com/RawTherapee/Download/MTE_2798.jpg
See how nicely it corrects the vignetting in the corners (espc. visible in the dark
right ones).

Reported by oduis@hotmail.com on 2012-05-19 08:40:22

Beep6581 commented 9 years ago
... and now the support for the Pentax and the likes profile type is also added.
Here is a demo correcting a Pentax image (left corrected) with that special profile
type using this patch:
http://www.visualbakery.com/RawTherapee/Download/LCPDemoPentax.jpg

Reported by oduis@hotmail.com on 2012-05-19 11:16:35

Beep6581 commented 9 years ago
Tested a while myself now, added some tweaks but could not repro Globetrotters massive
brightness problems. All good with the patch :-(

Reported by oduis@hotmail.com on 2012-05-19 12:47:07


Beep6581 commented 9 years ago
Globetrotter you used the Default profile which has auto exposure enabled. There is
an issue with some specific images causing AE to go wild. Perhaps this was what you
experienced, and not an LCP bug? Test with Neutral to confirm.

Reported by entertheyoni on 2012-05-19 16:46:28

Beep6581 commented 9 years ago
DrSlony, does the patch work on your set then? Or is it a general problem that there
is something magic that it just works on my machine?

Reported by oduis@hotmail.com on 2012-05-19 19:21:56

Beep6581 commented 9 years ago
#54
seem to have no chance on all my Nikon images made with these 4 lenses, settings must
be correct now, as you can see even path is set to only "." (i.e., independent of x64
dependency distro) for your RTTest baseline
http://minus.com/mbnXBdyKfq/1f
Also still crashes on Sigma 30 f1.4 images.

#58
no, always tried with my own standard profile (which has auto exposure switched off),
default and neutral --> same problem always

Now I'm clueless ...

Reported by globetrotter.75d on 2012-05-19 22:01:53

Beep6581 commented 9 years ago
And it seems not to be a German/US format issue, tried US region settings, problem still
persists.
http://minus.com/mV8tB2cWv/1f

Reported by globetrotter.75d on 2012-05-19 22:15:07

Beep6581 commented 9 years ago
Downloaded some raw images from google and tested with RTTest, looks the same --> vignetted
;(
- Nikon D800 .nef (two different lenses)
- CANON 60D .cr2 --> have to admin that the output looks very creative
  http://minus.com/mbjwGdXERM/1f (see the "foclen 250/0" in the command line?)

No one else here having W7 x64 to test? 3rd PC would be helpful ...

Reported by globetrotter.75d on 2012-05-20 00:39:05

Beep6581 commented 9 years ago
Hi Globetrotter,
To check what’s different on your machine the RTTest (same link as above) now contains
a version that throws out some debug information about the parameters being used.
It gives something like:
foclen 85.000000 / 127.000000
Mapping Dmax=239 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0
Can you try on your reference pictures only (the sign with the Fachwerkhäuser) and
see what the params look for you.
Again, no need to test dozens of pictures, it’s a general problem on your machine that
won’t change.

> And it seems not to be a German/US format issue
There was an issue, however it is already fixed with this patch. Same goes for a file
browser hang when you’d remove an LCP file when a PP3 was still pointing to it.
Since these are more critical problems I’d like to commit the current patch after the
24h period since so far only your machine has some problems reported, so it’s not a
general issue with this patch it seems from the feedback. We’ll continue to investigate
your issue of course.

Reported by oduis@hotmail.com on 2012-05-20 09:56:38

Beep6581 commented 9 years ago
(rawtherapee.exe:7344): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to a
llocate widget with width -5 and height 15
Mapping Dmax=4320 using
focLen 2.97934/2.97934; imgCenter 0.5/0.5; scale 1
param: -11.3136/408.038/-9061.23/0/0
Mapping Dmax=432 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0
Mapping Dmax=1078 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0

(rawtherapee.exe:7344): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to a
llocate widget with width -5 and height 15
foclen 85.000000 / 127.000000
Mapping Dmax=216 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0

Reported by globetrotter.75d on 2012-05-20 10:03:27

Beep6581 commented 9 years ago
That's the output for ONCE setting the lcp profile. No idea why it repeats debug info.

Reported by globetrotter.75d on 2012-05-20 10:07:53

Beep6581 commented 9 years ago
Thanks, getting strager by the minute, the correction parameters are the same as mine,
so the profile is parsed correctly.
RTTest now contains some more debug message, it now says what minimum and maximum vignetting
factors it calculated, and what foclengths were put in.
No need to reselect the profile, you can also just toggle "hot dead pixel correction".

Will look something like this if correct.
Since you report to have an overbright image, the vignetting correction is interesting.

Mapping Dmax=4320 f=85/f35=127 vignette=1 using
focLen 2.97934/2.97934; imgCenter 0.5/0.5; scale 1
param: -11.3136/408.038/-9061.23/0/0
Vignetting correction facs min/max: 1 / 1.71015

Mapping Dmax=432 f=85/f35=127 vignette=0 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0

Mapping Dmax=1078 f=85/f35=127 vignette=0 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0

Reported by oduis@hotmail.com on 2012-05-20 10:38:27

Beep6581 commented 9 years ago
using RTtest, image is not extrabright, just vignetted

Reported by globetrotter.75d on 2012-05-20 10:44:38

Beep6581 commented 9 years ago
(rawtherapee.exe:7260): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to a
llocate widget with width -5 and height 15

Mapping Dmax=4320 f=85/f35=127 vignette=1 using
focLen 2.97934/2.97934; imgCenter 0.5/0.5; scale 1
param: -11.3136/408.038/-9061.23/0/0
Vignetting correction facs min/max: 1 / 1.71015

Mapping Dmax=432 f=85/f35=127 vignette=0 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0

Mapping Dmax=1078 f=85/f35=127 vignette=0 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0

(rawtherapee.exe:7260): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to a
llocate widget with width -5 and height 15
foclen 85.000000 / 127.000000

Mapping Dmax=216 f=85/f35=127 vignette=0 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0

Reported by globetrotter.75d on 2012-05-20 10:48:05

Beep6581 commented 9 years ago
Ok, as you see the vignette correction is definitly working, scaling nicely form 1..
1.7
Maybe the distortion introduces the problem. Here is just the EXE:
http://www.visualbakery.com/RawTherapee/Download/rawtherapee.7z
which disable distortion completely. Expected would be a vignette corrected but still
distorted picture.

Reported by oduis@hotmail.com on 2012-05-20 11:02:54

Beep6581 commented 9 years ago
Sorry to disappoint you ...

(rawtherapee.exe:4848): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to a
llocate widget with width -5 and height 15

Mapping Dmax=4320 f=85/f35=127 vignette=1 using
focLen 2.97934/2.97934; imgCenter 0.5/0.5; scale 1
param: -11.3136/408.038/-9061.23/0/0
Vignetting correction facs min/max: 1 / 1.71015

Mapping Dmax=432 f=85/f35=127 vignette=0 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0

Mapping Dmax=1078 f=85/f35=127 vignette=0 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0

(rawtherapee.exe:4848): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to a
llocate widget with width -5 and height 15
foclen 85.000000 / 127.000000

Mapping Dmax=216 f=85/f35=127 vignette=0 using
focLen 2.98079/2.98079; imgCenter 0.499393/0.476738; scale 1
param: 0.041889/0/0/0/0

http://minus.com/mbqXYgcb0z/

Reported by globetrotter.75d on 2012-05-20 11:10:34

Beep6581 commented 9 years ago
Very, very strange. What did it look like before? Just vignetted?

Reported by oduis@hotmail.com on 2012-05-20 11:14:51

Beep6581 commented 9 years ago
At least there was a change.
Exe now updated to show you how much the distortion corrected the pixels at max.
To verify the distortion is not running wild. Should look like this:

Distortion delta max: 0.374091 pixels
Distortion delta max: 0.374091 pixels

(rawtherapee.exe:3752): Gtk-WARNING **:
Distortion delta max: 0.206894 pixels
Distortion delta max: 0.938315 pixels

(rawtherapee.exe:3752): Gtk-WARNING **:
Distortion delta max: 0.206894 pixels

Reported by oduis@hotmail.com on 2012-05-20 11:30:58

Beep6581 commented 9 years ago
Using your second patch file on repository files --> overexposed
Using your distribution RTtest --> only vignetted, exposures from all three RTtest
downloads look the same to me.
Is it possible that distortion does not work at all? Looking at your image (#55) and
the raw opened with default profile, they look the "same". I do not see any distortion.
Using RT with lcp on my Fisheye shows heavy distortion, as should be.

Reported by globetrotter.75d on 2012-05-20 11:38:10

Beep6581 commented 9 years ago
The Fachwerkhaus image does not contain much distortion in the first place, so you won't
see much difference (0.9 pixels max correction as the output says).

However since we now tested that vignette corrections is working correctly, we now
try to check if the distortion correction is running wild for some reason. Would also
explain some of your samples that looked like a hole on black (happens with wildly
wrong distortion params).

So what does the latest RTTest I uploaded show as distortion max? Something in that
ballpark?

Reported by oduis@hotmail.com on 2012-05-20 11:47:43

Beep6581 commented 9 years ago
Aha! Now we get a difference. Also you got 5 distortion lines, me only 3.

(rawtherapee.exe:876): Gtk-WARNING **: 
Distortion delta max: 0.374091 pixels
Distortion delta max: 0.938315 pixels

(rawtherapee.exe:876): Gtk-WARNING **: 
Distortion delta max: 0.187083 pixels

Reported by globetrotter.75d on 2012-05-20 11:50:13

Beep6581 commented 9 years ago
No, still all correct. The smaller distoritions are for the thumbs (having different
sizes on systems), and it's also dependend on preview size.
If would have been a problem if they were wildly different (e.g. because of number
overflows during calculation etc.), but they aren't, engine is running good.

Im running out of ideas currently. It might be a general problem with threads or something
that just surfaces with LCPs.

Michael, could you check if the EXE shows weired effects using Adobes LCPs on your
Win64?
http://www.visualbakery.com/RawTherapee/Download/rawtherapee.7z

Reported by oduis@hotmail.com on 2012-05-20 12:03:09

Beep6581 commented 9 years ago
Hi Olli, here is some testing feedback using exe from comment 69 (downloaded 7:36 AM
EST):

1. Name in History entry for LCP = "Wavelet coefficients", should be "Lens correction
profile"

2. Select LCP in editor. 
2.a Go back in history. 
This does not (not always) remove vignetting correction. Distortion correction is removed.
2.b After that, in history - select last entry where LCP was assigned ("Wavelet coefficients")
Distortion correction IS applied
Vignetting correction is NOT applied

3. Thumbnails:
3.a vignetting correction is NOT applied
3.b Distortion correction IS applied

About variances in the number of lines printed - is that possibly because of the interpolation
between *multiple* lcp corrections?

To identify platform variances - are three of us supposed to use the same raw and lcp
file? which ones?

Reported by michaelezra000 on 2012-05-20 12:11:25

Beep6581 commented 9 years ago
see Comment 39, please
I only started correction once, produced 5 lines

Reported by globetrotter.75d on 2012-05-20 12:21:54

Beep6581 commented 9 years ago
The only weird problem I see at the moment is that vignetting correction has 2 issues
for some profiles:
A. the entire image becomes brighter
B. strong magenta cast is added in vignetting corrected areas - stronger in corners

However, this is not happening with ALL lcp profiles. One example would be Canon S90
raw with Adobe's LCP.

Here is illustration with "blue horse" NEF:
http://www.michaelezra.com/Projects/RT/images_shared/LCP_01.jpg

Reported by michaelezra000 on 2012-05-20 12:31:49


Beep6581 commented 9 years ago
To me this looks like same source of problem. It's also right about getting lighter.

Reported by globetrotter.75d on 2012-05-20 12:38:16

Beep6581 commented 9 years ago
Here is a good result with Lens_Nikon_16-85mm_f3.5-5.6G_ED_VR_DX_AF-S_Nikkor.lcp:
http://www.michaelezra.com/Projects/RT/images_shared/LCP_02.jpg

Reported by michaelezra000 on 2012-05-20 12:42:30

Beep6581 commented 9 years ago
Michael, you say that vignetting is not applied, though on your image it looks like
it is. What do you mean by that?
Don't focus on the number of lines by the way, it's not important, just the range of
the numbers, and they look OK.

Then the horse picture you display as test, that's not an official profile I guess
(at least there does not seem to be an adobe 28-70 profile). Don't test with non-Adobes
at all! It's also not guaranteed that every profile delivers excellent results, so
I don't care for small inaccuracies.

But Globetrotters results show very big bugs, like these:
http://minus.com/mbjwGdXERM/1f
Can you reproduce these?

I'll look for the history stuff.

Reported by oduis@hotmail.com on 2012-05-20 12:49:04

Beep6581 commented 9 years ago
RT: Single Tab mode.

ACTION: Started Rt with a single raw file (MTE_2798.NEF) in directory, with LCP assigned

CONSOLE: 
  Distortion delta max: 0.127959 pixels

ACTION: Double-clicked on thumbnail
CONSOLE:
  Distortion delta max: 0.374091 pixels
  Distortion delta max: 0.285071 pixels
  Distortion delta max: 0.285071 pixels
  Distortion delta max: 0.127959 pixels
  Distortion delta max: 0.127959 pixels    

ACTION: Hid the thumbnail ribbon
CONSOLE:
  Distortion delta max: 0.374091 pixels
  Distortion delta max: 0.127959 pixels  

ACTION: Expanded the thumbnail ribbon
CONSOLE:
  Distortion delta max: 0.285071 pixels
  Distortion delta max: 0.127959 pixels

Reported by michaelezra000 on 2012-05-20 12:53:42

Beep6581 commented 9 years ago
Thanks Michael, looks normal. Also the last test image looks normal (a bit brighter
in total is normal, since LCPs just increase brightness).

Means we still need to find out whats different on Globetrotters setup (?)

Reported by oduis@hotmail.com on 2012-05-20 12:56:19

Beep6581 commented 9 years ago
About http://minus.com/mbjwGdXERM/1f
Can raw file & lcp be shared?

The only times when I I saw image preview showing extreme artifacts is when fish eye
lcp is applied to not fish eye lens.

Reported by michaelezra000 on 2012-05-20 13:04:46

Beep6581 commented 9 years ago
Incorrectly matching different lenses to different images should naturally look distorted.

BTW: Just saw that DrSlony already reported the history problem. Sorry, I got a bit
underwater trying to reproduce Globetrotters weired problems.

Reported by oduis@hotmail.com on 2012-05-20 13:14:20

Beep6581 commented 9 years ago
Sure, while I was google-ing for raw images I found this one (it does NOT belong to
me!)
http://min.us/mjWDplFP1

Reported by globetrotter.75d on 2012-05-20 13:19:52

Beep6581 commented 9 years ago

Reported by globetrotter.75d on 2012-05-20 13:21:17

Beep6581 commented 9 years ago
I always used profiles for the respective lenses, only.

Reported by globetrotter.75d on 2012-05-20 13:22:15

Beep6581 commented 9 years ago
http://www.michaelezra.com/Projects/RT/images_shared/LCP_03.jpg

Reported by michaelezra000 on 2012-05-20 13:46:23

Beep6581 commented 9 years ago
This fixes the history.

Reported by oduis@hotmail.com on 2012-05-20 13:53:17

Beep6581 commented 9 years ago
Ok, loading down that file. Will have to see if it is a problem that the LCP is for
a different camera with different megapixel size (Canon 60D vs. Canon 50D)

Reported by oduis@hotmail.com on 2012-05-20 13:58:36

Beep6581 commented 9 years ago
THanks, can repro on that picture, will have a look.
(Will be out for some hours though)

Reported by oduis@hotmail.com on 2012-05-20 14:16:03

Beep6581 commented 9 years ago
Great, tested lcpcorr2.patch; history is OK.
Heads up to hg pull before committing this one: I just committed revision 506dd02c3789
(issue 227)

Reported by michaelezra000 on 2012-05-20 15:28:34

Beep6581 commented 9 years ago
There is an issue in History in the filebrowser tab:
1.click on thumb without lcp
2. assign lcp: see distortion correction in thumb
3. in history click on 1-st step in history (Photo Loaded): distortion correction removed
4. click on the "Lens Correction Profile" in history: PROBLEM - distortion correction
is NOT re-applied.

Reported by michaelezra000 on 2012-05-20 16:00:55

Beep6581 commented 9 years ago
Maybe we made an error in reasoning. 

(1) When you install Adobe DNG Converter, you'll find a huge bunch of lcp (and dcp)
profiles on your system.
(2) With Adobe Lens Profile Downloader you can download further lcp profiles.

BOTH sources have profiles which mention mostly camera model AND lens type, e.g.

from (1)
Canon EOS 50D (Sigma DC 4.5mm f2.8 HSM).lcp
Canon EOS 5D Mark II (Canon EF 100-400mm f4.5-5.6L IS USM) - RAW.lcp
NIKON D3 (Nikon AF-S VR Micro-Nikkor 105mm f2.8G IF-ED) - RAW.lcp
NIKON D300S (Nikon AF-S DX Zoom-Nikkor 18-70mm f3.5-4.5G IF-ED) - RAW.lcp
NIKON D3X (Nikon AF DC-NIKKOR 105mm f2D) - RAW.lcp

from (2)
NIKON D300 - Nikkor 16.0-85.0 mm f3.5-5.6.lcp
NIKON D300S - Nikkor 70.0-300.0 mm f4.5-5.6.lcp

Tried our reference image (16-85mm) and a 70-300mm image. Sigma still crashing RT.
http://vwlnt7vw4897.minus.com/mkkE5MydL/

Now we can see that at least one more lens (70-300mm) works. Both images have black
pixels around them.

Reported by globetrotter.75d on 2012-05-20 19:17:06

Beep6581 commented 9 years ago
How to find the profiles from (1) and (2)on your system:
http://labs.adobe.com/technologies/lensprofile_creator/faq.html
--> Question "Where should I place my LCP file"

Reported by globetrotter.75d on 2012-05-20 19:27:00

Beep6581 commented 9 years ago
The black pixels are normal, it's even good in that the distortion correction works.
However great you found that the LCP profiles already come with with free DNG converter,
and not only with Camera Raw.

You system is still a different animal, since the Fachwerkhäuser are correct at Michael
and my system. However I hope that I can get near the problem with the reddish image.

Michael, You got camera raw, don't you? Does the reddish circled image open correctly
with the profile there? (to rule out it's a profile problem)

Reported by oduis@hotmail.com on 2012-05-20 20:24:13

Beep6581 commented 9 years ago
Ok, found the problem with the wood image, no more red circles any more (and Michael,
might also improve on some red casts a bit).
However I cannot repro the history go back/forth problem. Works nice here.

Reported by oduis@hotmail.com on 2012-05-20 20:37:31

Beep6581 commented 9 years ago
Just tested in ACR - lcp is ok. will recompile with latest patch

Reported by michaelezra000 on 2012-05-20 20:44:42

Beep6581 commented 9 years ago
Nice, magenta cast is gone. 
My Canon S90 custom profile works. 

In the house picture there is some abundant vignetting correction (corners too bright)
in RT. In ACR lcp makes very uniform image.

Reported by michaelezra000 on 2012-05-20 21:16:45