kbarni Posted December 11, 2007 Posted December 11, 2007 (edited) 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. Edited June 20, 2020 by toe_head2001 Fixed attachment 2 Quote
Fisherman's Friend Posted December 11, 2007 Posted December 11, 2007 1.) You should consider to add example pics. They make it easier to speak about it. And people want to see what they will get. 2.) You have done it with codelab? How about providing the source code? I would be interested. 1 Quote
MadJik Posted December 11, 2007 Posted December 11, 2007 Yes, sure I may help you (if you want me to)... I already think about the IndirectUI features: ...Choose the center X,Y Offset, ...Keep background (yes/no, instead transparent) ...X,Y separated factors ...Limits +/- 500 (instead 50) : ok perhaps it's crazy, but just for the fun of distortion! Like I did here: viewtopic.php?f=5&t=21525 (you could use this source as a template by your own...) Let me(us) know... Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal
Rick Brewster Posted December 12, 2007 Posted December 12, 2007 Screenshots please! 1 Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
pyrochild Posted December 12, 2007 Posted December 12, 2007 Is there any reason why the left and right edges of the image are left intact? Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it!
Fisherman's Friend Posted December 12, 2007 Posted December 12, 2007 Screenshots please! I made some. @Pyro: This issue is occuring when I use it, too. Edit: Please note: I forgot to change the language to English. To prevent confusion, "Abbrechen" is not a weird plugin-related button, but means just "Cancel". :wink: And please forgive me the bad quality of the pictures, but I want them to be suitable for all bandwiths. Quote
kbarni Posted December 13, 2007 Author Posted December 13, 2007 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++; } } } Quote
kbarni Posted December 13, 2007 Author Posted December 13, 2007 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. Quote
MadJik Posted December 13, 2007 Posted December 13, 2007 Ok...This is the code with the new IndirectUIAdded:X,Y offset (strange effect)Quality levelChanged:Bug left/right seams solvedRange -/+ 500 Source : CameraLens.zipUpdated dll:CameraLens.zip Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal
kbarni Posted December 13, 2007 Author Posted December 13, 2007 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)! Quote
Rick Brewster Posted December 14, 2007 Posted December 14, 2007 There are some major rendering goof-ups if you move the center/offset around. It looks like the effect is not writing to every pixel in DstArgs, and so they just retain their old values. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
R3VENGE Posted January 1, 2008 Posted January 1, 2008 this will help making tv screens for my ut2k4 maps. im new to plugins but i have loads within one night lol. Quote psn id: R3V-fiR3
Red ochre Posted February 27, 2016 Posted February 27, 2016 I doubt kbarni is still visiting the forum, so not too much point in posting this?. (I was using it within a selection). Shame, as it is a useful effect. Thanks for posting the code, I may try to squash some bugs at some point. File: C:\Program Files\NEWpdn\Effects\kb_lens.dll Effect Name: PaintDotNet.Effects.UserScript Full error message: PaintDotNet.WorkerThreadException: Worker thread threw an exception ---> System.IndexOutOfRangeException: Index was outside the bounds of the array. Quote Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings
Herbii Posted June 20, 2020 Posted June 20, 2020 Hi there! Trying to download this plugin but nothing works. It doesn't even download as a .zip? Quote
toe_head2001 Posted June 20, 2020 Posted June 20, 2020 The file is a ZIP file, but was simply missing the .ZIP extension. I've fixed the attachment to resolve that. Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab
Haoto Posted August 12, 2023 Posted August 12, 2023 The plugin is not showing up. I can't find it in the Distortion section. I'm still on version 4.3.12; this could be the reason. Quote
Pixey Posted August 12, 2023 Posted August 12, 2023 26 minutes ago, Haoto said: I'm still on version 4.3.12; this could be the reason. Absolutely! You must update the latest version in order for the Plugins to work correctly. Quote How I made Jennifer & Halle in Paint.net My Gallery | My Deviant Art "Rescuing one animal may not change the world, but for that animal their world is changed forever!" anon.
Haoto Posted August 12, 2023 Posted August 12, 2023 (edited) 22 minutes ago, Pixey said: Absolutely! You must update the latest version in order for the Plugins to work correctly. Is there a way for me to download the older version of this plugin? The reason I'm not using the latest version of Paint.NET is because there are other plugins that won't work on the newer version. Also, some of BoltBait's plugins had changes I didn't like, so I stuck with the older version. Edited August 12, 2023 by Haoto Quote
Pixey Posted August 12, 2023 Posted August 12, 2023 6 minutes ago, Haoto said: Is there a way for me to download the older version of this plugin? No, one can't, sorry. The best way is to update to the latest version of paint.net. I'm afraid we can't give solutions, or help, with older versions. If you are having problems with newer Plugins, one has to 'bite the bullet' and learn how to use the newer Plugins If you have a particular problem with one of the newer ones, you can post an image of what you ae trying to accomplish and people on here, as well as the Plugin author, should be able to help you to get to your desired result. Quote How I made Jennifer & Halle in Paint.net My Gallery | My Deviant Art "Rescuing one animal may not change the world, but for that animal their world is changed forever!" anon.
toe_head2001 Posted August 12, 2023 Posted August 12, 2023 This plugin is absolutely ancient, and does not require the latest version of Paint.NET. Your problem lies elsewhere. You should use the latest version of Paint.NET anyways though. Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab
Haoto Posted August 12, 2023 Posted August 12, 2023 (edited) @toe_head2001 Is there another plugin that's up-to-date but does the same thing as this one? I'm still hesitant on using the new version of Paint.NET because the changes made to the plugins will ruin my consistency... All I wanted was text alignment, especially when there's multiple paragraphs. Edited August 12, 2023 by Haoto Quote
Red ochre Posted August 12, 2023 Posted August 12, 2023 1 hour ago, Haoto said: I can't find it in the Distortion section. It's under Effects/Photo not Distortion. Still working in 5.08 🙂 Quote Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings
Pixey Posted August 12, 2023 Posted August 12, 2023 @Haoto I tested it in both 4.3.12 and 5.0.9 an it is still working in both. Quote How I made Jennifer & Halle in Paint.net My Gallery | My Deviant Art "Rescuing one animal may not change the world, but for that animal their world is changed forever!" anon.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.