Jump to content

kbarni

Newbies
  • Posts

    4
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

kbarni's Achievements

Newbie

Newbie (1/14)

  • First Post
  • Conversation Starter
  • Week One Done
  • One Month Later
  • One Year In

Recent Badges

1

Reputation

  1. I updated the original plugin, still using my codelabs version. You can download it in the original post! This fixes just the nasty edge bug, there is no other change. Thanks for the quick modification, MadJik, I think I'll modify your version too (when i'll have time)!
  2. And sorry I didn't post any screenshots, here's mine, a real example with lens distortion: On the original I marked the distorted edgees with red dotted line. There are lenses with even stronger distortions (especially the wide angle zoom lenses). I hope you find this plugin usefull.
  3. Good people, here's the code for CodeLabs! Have fun playing with it, I hope you'll make it even cooler! int Amount1=-20; //[-50,50] Amount per thousand(°/oo) float [] rd = null; int Achange=0; //To verify if there is a slider change void Render(Surface dst, Surface src, Rectangle rect) { float Percent= (float)(Amount1 / 500.0f); // Distortion percent PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); int w,h,x0,y0,w2,h2,raymax; float xd,yd,rdcur,ru; w = selection.Right - selection.Left; h = selection.Bottom - selection.Top; x0=selection.Bottom;y0=selection.Right; h2=h/2;w2=w/2; raymax=(int)Math.Sqrt(h2*h2+w2*w2)+1; if(rd == null){ //first run->alloc and init rd = new float[raymax]; Init(raymax,Percent,w,h); }else if(Achange!=Amount1){ //slider change->reinit Achange=Amount1; Init(raymax,Percent,w,h); } for(int y = rect.Top; y < rect.Bottom; y++){ for (int x = rect.Left+1; x < rect.Right/2+1; x++){ //BUG: if it goes from rect.Left it gives an exception ru=(float)Math.Sqrt((float)((w2-x)*(w2-x)+(h2-y)*(h2-y))); rdcur=rd[(int)ru]*(1-ru+(float)Math.Floor(ru)) + rd[(int)ru+1]*(ru-(float)Math.Floor(ru)); rdcur/=ru; xd=(w2-x)*rdcur;yd=(h2-y)*rdcur; dst[x,y] = src.GetBilinearSample(w2-xd,h2-yd); dst[w-x,y] = src.GetBilinearSample(w2+xd,h2-yd); } //idea of optimisation: the function is symmetrical horizontally and vertically, //so at the same moment (x,y),(w-x,y),(x,h-y),(w-x,h-y) can be calculated } } void Init(int raymax, float percent, int w, int h) { //We precalculate the distortion function in rd double k,r,inc,ru1,ru0,m; int l; // *** Calculate K *** (k is the distortion constant based on the distortion %) double yd1,yd2,rd2,alfa; yd1=h/2; yd2=yd1*(1-percent); alfa=Math.Atan2(h,w); rd2=yd2/Math.Sin(alfa); k=(yd1-yd2)/(rd2*rd2*yd2-yd1*yd1*yd1); r=0; inc=0.1; l=1;rd[0]=0; while(l ru0=r+r*r*r*k; r+=0.1; ru1=r+r*r*r*k; if(Math.Floor(ru0)!=Math.Floor(ru1)){ m=(ru1-ru0)/inc; rd[l]=(float)(r-(ru1-Math.Floor(ru1))/m); l++; } } }
  4. Hello, Here is a simple plugin to correct the barrel or pincushion distortions in digital photos. (More information about these distortions in wikipedia article) You can download the plugin here: kb_lens.zip To use it simply unzip it to c:/Program Files/Paint.NET/Effects/, the plugin is in Filters->Photo->Distortion Here is an example of the plugin usage. On the first photo you can see the effect of the lens distortion (I traced it with dotted red line), which was eliminated in the second image using the plugin: This effect is even stronger with macro shots, cheaper lenses on compact cameras and ultra-wide (fisheye) lenses. I wrote the plugin using Codelabs, if there is someone who would like to implement it in C# (in order to give a nice interface or to optimize it), i can post the source code.
×
×
  • Create New...