Page 1 of 1

Removing complex vighetting

Posted: 2013-08-16T13:19:50-07:00
by olegk
I'm experimenting with single-lens 3D photography; this technique introduces heavy color vignetting. E.g. the closer you are to the left, the stronger is cyan cast; the closer you are to the right, the stronger is red cast.
I'm trying to fix this by subtracting a photo of white wall (ColorVign_dark_1s.tif) from the original.
Here is the command that mostly works - except for some pixels fall out of range and become clipped:
for %f in (IN\*s.tif) DO convert %f ColorVign_dark_1s.tif -fx "u+v.p{w/2,h/2}-v" -quality 90 OUT\%~nf_fx_11.jpg

I've been advised to use subtraction and not division for color-processed images, and this seems to be correct.

But there are two problems:
1) The fx operator is unusably slow for 16 Mix images; is there any built-in function that does the job?
2) Could the clipping be avoided?

Regards,
Oleg.

Re: Removing complex vighetting

Posted: 2013-08-16T13:30:02-07:00
by snibgo
Your fx can be replaced by suitable composites. See http://www.imagemagick.org/Usage/compose/

One way around clipping is to use HDRI, then "-auto-level".

Re: Removing complex vighetting

Posted: 2013-08-16T13:38:53-07:00
by fmw42
Just to add a little detail to what snibgo says, use IM compiled in HDRI mode (and possibly suitable image formats that support floats and negative values such as Tiff, NetPBM PFM, MPC) and use -compose minus -composite.

see
http://www.imagemagick.org/script/high- ... -range.php
http://www.imagemagick.org/script/formats.php#supported
http://www.imagemagick.org/script/comma ... php#define (see -define quantumformat if using TIFF or MIFF)
http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/compose/#minus


PS. What version of IM are you using and what platform?

Re: Removing complex vighetting

Posted: 2013-08-16T14:23:02-07:00
by GreenKoopa
olegk wrote:-fx "u+v.p{w/2,h/2}-v"
That puts a lot of weight on an individual pixel. Make sure the center one is a good one. It might help to blur ColorVign.tif slightly.

HDRI is best. An alternative is to de-contrast using +level, do your correction, then re-contrast. -auto-level is ideal, but play with other options, especially if you image began with clipped colors.

-compose Mathematics is one possible replacement for your -fx. It could handle the initial de-contrast, the +v.p{w/2,h/2} (a constant), and the -v in a single operation.

Re: Removing complex vighetting

Posted: 2013-08-16T23:30:01-07:00
by olegk
Thanks!

Regarding the version:
I started with the latest - ImageMagick-6.8.6-8, but the fx operator didn't work. I then switched to ImageMagick-6.7.1-6 and found the same problem. The reason: fx expects expression in double quotes, while the examples use single quotes.
My platform is Windows, which is the reason for the above.

Regarding HDRI, I need to schedule the build effort, but seems like I have no choice anyway :).

Re: Removing complex vighetting

Posted: 2013-08-16T23:41:21-07:00
by GreenKoopa
olegk wrote:fx expects expression in double quotes, while the examples use single quotes. My platform is Windows, which is the reason for the above.
I don't think IM or fx care, but it does want one parameter. Windows breaks at spaces unless inside double quotes. Most examples need to be converted for Windows. I stumbled over several of these issues at first too. See http://www.imagemagick.org/Usage/windows/#conversion
olegk wrote:Regarding HDRI, I need to schedule the build effort, but seems like I have no choice anyway :).
The 7.0 alpha enables HDRI by default.

Re: Removing complex vighetting

Posted: 2013-08-17T05:26:39-07:00
by olegk
So, I downloaded Fred's HDR-enabled IM from .
======
D:\Photo\SL3D_35_2d8\TRY>convert -version
Version: ImageMagick 6.7.6-1 2012-03-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: HDRI
======

But my -fx "u+v.p{w/2,h/2}-v" command still produces clipped shadows. Well, now I understand that it should do so.
And anyway I need something that's much faster. Will read the doc on -composite and come back with more questions.

Re: Removing complex vighetting

Posted: 2013-08-31T07:28:04-07:00
by olegk
Ok,
here is the solution I adopted. The idea is to use Plus and Minus operators sequentially instead of fx operator.

I start with a photo of the (undesired) vignette when impact I want to compensate. It's neutral in the center and has color casts growing towards sides. I make a one-color image with the color from the centre of the vignette, then subtract the vignette from it. The resulting image in added to the photos that I want to color-correct. I apply some desaturation too.
Here are the commands; just in case:

@Rem Make 16-bit correction image - max exposure
"c:\Program Files\ImageMagick-6.8.6-8\convert.exe" ..\TIFF16\DSC02119_16_max.tif -strip -depth 16 -compress LZW ColorVign_16_bright.tif
convert ColorVign_16_bright.tif -gravity center -crop 320x320+0+0 -depth 16 -compress LZW crop320_16_bright.tif

convert crop320_16_bright.tif -blur 0x3 -depth 16 -compress LZW crop320_16_bright_blur.tif
identify ColorVign_16_bright.tif
@Rem 4912x3264
convert crop320_16_bright_blur.tif -resize 4912x3264! -blur 0x3 -depth 16 -compress LZW CentralColor_16_bright.tif
convert CentralColor_16_bright.tif ColorVign_16_bright.tif -compose Minus_Src -composite -blur 0x3 -depth 16 -compress LZW ColorAdd_16_bright.tif

@Rem Use 16-bit correction image
for %f in (IN\*.TIF) do convert %f ColorAdd_16_bright.tif -compose Plus -composite -depth 8 -quality 90 OUT\%~nf_fxAdd_b.JPG