Removing vignetting from images
Posted: Mon Feb 05, 2024 3:59 pm
I need a vignetting removal specially adapted for my camera.
Normally a radial brightening of the edges is sufficient, but my camera also has a bright spot in the centre.
When the images are stitched together to form a panorama, this is really noticeable:

I use Luminar Neo to process (RAW development) my photos. I can only use it to brighten the edges.
That's why I took a picture of a pure white surface to get a light map of the vignetting.

And now I would like to offset the brightness deviations with an image.

You can find the complete project here: https://u.pcloud.link/publink/show?code ... UMhVo2lD9k
How would you brighten the image using the "lightmap" image?
I tried it as follows, but I'm not satisfied with it.
In particular, if you offset the LightMap against itself, a homogeneous surface should be created.
be created. But it doesn't work as expected.
Normally a radial brightening of the edges is sufficient, but my camera also has a bright spot in the centre.
When the images are stitched together to form a panorama, this is really noticeable:

I use Luminar Neo to process (RAW development) my photos. I can only use it to brighten the edges.
That's why I took a picture of a pure white surface to get a light map of the vignetting.

And now I would like to offset the brightness deviations with an image.

You can find the complete project here: https://u.pcloud.link/publink/show?code ... UMhVo2lD9k
How would you brighten the image using the "lightmap" image?
I tried it as follows, but I'm not satisfied with it.
In particular, if you offset the LightMap against itself, a homogeneous surface should be created.
be created. But it doesn't work as expected.
Code: Select all
UseJPEGImageDecoder()
Global G_Lumo, G_Scale
Macro ColorLimit(Color, Minimum, Maximum)
If Color > Maximum
Color = Maximum
ElseIf Color < Minimum
Color = Minimum
EndIf
EndMacro
Procedure.l Luminosity(Color.l, Scale.f)
Red.l = (Color & $FF) * Scale
Green.l = (Color >> 8 & $FF) * Scale
Blue.l = (Color >> 16 & $FF) * Scale
ColorLimit(Red, 0, 255)
ColorLimit(Green, 0, 255)
ColorLimit(Blue, 0, 255)
ProcedureReturn (((Blue << 8 + Green) << 8) + Red)
EndProcedure
Procedure.l GrayCol ( rgb.l )
Protected b, r, g
rgb = Red(rgb) * 0.2989 + Green(rgb) * 0.5870 + Blue(rgb) * 0.1140
rgb = RGB(rgb, rgb, rgb)
ProcedureReturn rgb
EndProcedure
Procedure FilterCallback(x, y, QuellFarbe, ZielFarbe)
Protected Abw.f, f.f
; Quellfarbe = Brightness Map
; ZielFarbe = Drone Footage
QuellFarbe = Green(GrayCol(QuellFarbe))
Abw = G_Lumo - QuellFarbe
If QuellFarbe = 0
QuellFarbe = 1
EndIf
f = (G_Lumo / QuellFarbe)
ZielFarbe = Luminosity(ZielFarbe, f)
ProcedureReturn ZielFarbe
EndProcedure
file.s = "brightness_map.jpg"
foto.s = "Drone_footage.jpg"
;foto.s = "brightness_map.jpg"
LoadImage(1, foto)
LoadImage(0, file)
w = ImageWidth(0)
h = ImageHeight(0)
OpenWindow(0, 0, 0, 800, 600, "")
CanvasGadget(0, 0, 0, 800, 600)
If StartDrawing(ImageOutput(0))
; Get Reference Color
G_Lumo = Green(GrayCol(Point(w/3, h/2)))
min = 255
max = 0
For y = 0 To h - 1
For x = 0 To w - 1
c = Green(GrayCol(Point(x, y)))
If c > max
max = c
EndIf
If c < min
min = c
EndIf
Next
Next
Debug "Min: " + Str(min) + " - Max: " + Str(Max) + " Ref: " + Str(G_Lumo)
G_Scale = max - min
StopDrawing()
EndIf
If StartDrawing(CanvasOutput(0))
DrawImage(ImageID(1), 0, 0)
DrawingMode(#PB_2DDrawing_CustomFilter)
CustomFilterCallback(@FilterCallback())
DrawImage(ImageID(0), 0, 0)
StopDrawing()
EndIf
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow