Removing complex vighetting

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
olegk
Posts: 37
Joined: 2013-08-16T11:31:10-07:00
Authentication code: 6789

Removing complex vighetting

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Removing complex vighetting

Post 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".
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Removing complex vighetting

Post 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?
Last edited by fmw42 on 2013-08-16T16:47:20-07:00, edited 1 time in total.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Removing complex vighetting

Post 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.
olegk
Posts: 37
Joined: 2013-08-16T11:31:10-07:00
Authentication code: 6789

Re: Removing complex vighetting

Post 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 :).
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Removing complex vighetting

Post 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.
olegk
Posts: 37
Joined: 2013-08-16T11:31:10-07:00
Authentication code: 6789

Re: Removing complex vighetting

Post 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.
olegk
Posts: 37
Joined: 2013-08-16T11:31:10-07:00
Authentication code: 6789

Re: Removing complex vighetting

Post 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
Post Reply