FixChromaticAberration: Difference between revisions

From Avisynth wiki
Jump to navigationJump to search
No edit summary
Yakub2.X (talk | contribs)
No edit summary
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
copy the code below into a file 'FixChromaticAberration.avsi' in your AviSynth plugins directory or directly into your script:
{{FilterCat4|External_filters|Scripts|Restoration_filters|Chroma correction}}
{{Filter3
|martin53 at doom9
|04/09/2007
|3=[[Media:FixChromaticAberration.avsi|FixChromaticAberration.avsi]]
|4=Chroma Correction
|5=
|6=[http://forum.doom9.org/showthread.php?t=162286 Doom9 Thread]}}


  ###################################################################################
<br>
  #
== Description ==
  # This AviSynth function stretches the red, green and/or blue channel according to
A script to reduce [http://en.wikipedia.org/wiki/Chromatic_aberration chromatic aberration]. This function stretches the red, green and/or blue channel according to a given factor symmetrically around the center of the frame and crops it afterwards. Note that chromatic aberration also smears the image a bit, which is not compensated by this function.
  # a given factor symmetrically around the center of the frame and crops it afterwards.
  #
  # Parameters: clip, red, green, blue.
  # red, green and blue are stretching (resizing) factors against the original clip size.
  # The function returns the clip in RGB24 colorspace.
  #
  # Factors of e.g. red=1.015, green=1.01 allow to compensate the colored edges near the
  # corners of the image which appear from lenses with 'chromatic aberration'.
  #
  # If a factor is below 1.0, a that color will be fitted with black corners into the frame.
  #
  # x and y allow to set the center of the aberration circle. It defaults to the center
  # of the image.
  #
  # Note that chromatic aberration also smears the image a bit, which is not compensated
  # by this function.
  #
  # Martin Wagener at gmx.de, 04/09/2007
  #
  ###################################################################################
 
  function FixChromaticAberration(clip "clip", val "red", val "green", val "blue", val "x", val "y")
  {
      r= default(red,1)
      g= default(green,1)
      b= default(blue,1)
      c= (IsRGB(clip)) ? clip : ConvertToRGB(clip)
      w= c.Width()
      w2= round(w*0.5)
      h= c.Height()
      h2= round(h*0.5)
      xi= default(x,w*0.5)
      xi= (xi<0)?0:xi
      xi= (xi>=w)?w-1:xi
      yi= default(y,h*0.5)
      yi= (yi<0)?0:yi
      yi= (yi>=h)?h-1:yi
      rw= round(r*w)
      rh= round(r*h)
      rl= round((r-1)*xi)
      rt= round((r-1)*yi)
      gw= round(g*w)
      gh= round(g*h)
      gl= round((g-1)*xi)
      gt= round((g-1)*yi)
      bw= round(b*w)
      bh= round(b*h)
      bl= round((b-1)*xi)
      bt= round((b-1)*yi)
      rc= (r>1) ? LanczosResize(c,rw,rh).Crop(rl,rt,w,h) : c
      gc= (g>1) ? LanczosResize(c,gw,gh).Crop(gl,gt,w,h) : c
      bc= (b>1) ? LanczosResize(c,bw,bh).Crop(bl,bt,w,h) : c
      rcs= (r<1) ? LanczosResize(c.AddBorders(-rl,-rt,w-rw+rl,h-rh+rt),w,h) : rc
      gcs= (g<1) ? LanczosResize(c.AddBorders(-gl,-gt,w-gw+gl,h-gh+gt),w,h) : gc
      bcs= (b<1) ? LanczosResize(c.AddBorders(-bl,-bt,w-bw+bl,h-bh+bt),w,h) : bc
      MergeRGB(rcs, gcs, bcs)
  }


Back to [[Shared functions]].
<br>
== Requirements ==
* AviSynth 2.5.8 or [http://sourceforge.net/projects/avisynth2/ greater]
* Supported color formats: [[RGB32]], [[RGB24]]


[[Category:Shared_functions]]
<br>
[[Category:External filters]]
== [[Script variables|Syntax and Parameters]] ==
:{{Template:FuncDef|FixChromaticAberration (clip clip, val "red", val "green", val "blue", val "x", val "y")}}
<br>
::{{Par2| |clip| }}
:::Input clip.
<br>
::{{Par2|red|val|1}}
::{{Par2|green|val|1}}
::{{Par2|blue|val|1}}
:::{{Template:FuncDef3|red}}, {{Template:FuncDef3|green}} and {{Template:FuncDef3|blue}} are stretching (resizing) factors against the original clip size. Factors of e.g. <code>{{Template:FuncDef3|red}}=1.015</code>, <code>{{Template:FuncDef3|green}}=1.01</code> allow to compensate the colored edges near the corners of the image which appear from lenses with 'chromatic aberration'.
<br>
::{{Par2|x|val| }}
::{{Par2|y|val| }}
:::{{Template:FuncDef3|x}} and {{Template:FuncDef3|y}} allow to set the center of the aberration circle. It defaults to the center of the image.
 
<br>
== Examples ==
FixChromaticAberration with default settings:
[[AviSource]]("Blah.avi")
FixChromaticAberration(red=1, green=1, blue=1)
 
<br>
== Changelog ==
Version      Date(D/M/Y)      Changes<br>
              04/09/2007      - Initial release
 
<br>
-----------------------------------------------
'''Back to [[External_filters#Chroma_correction|External Filters]] &larr;'''

Latest revision as of 00:39, 25 June 2018

Abstract
Author martin53 at doom9
Version 04/09/2007
Download FixChromaticAberration.avsi
Category Chroma Correction
License
Discussion Doom9 Thread


Description

A script to reduce chromatic aberration. This function stretches the red, green and/or blue channel according to a given factor symmetrically around the center of the frame and crops it afterwards. Note that chromatic aberration also smears the image a bit, which is not compensated by this function.


Requirements


FixChromaticAberration (clip clip, val "red", val "green", val "blue", val "x", val "y")


clip   =
Input clip.


val  red = 1
val  green = 1
val  blue = 1
red, green and blue are stretching (resizing) factors against the original clip size. Factors of e.g. red=1.015, green=1.01 allow to compensate the colored edges near the corners of the image which appear from lenses with 'chromatic aberration'.


val  x =
val  y =
x and y allow to set the center of the aberration circle. It defaults to the center of the image.


Examples

FixChromaticAberration with default settings:

AviSource("Blah.avi")
FixChromaticAberration(red=1, green=1, blue=1)


Changelog

Version      Date(D/M/Y)      Changes
04/09/2007 - Initial release



Back to External Filters