: RE LENS DISTORTION CORRECTION

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

: RE LENS DISTORTION CORRECTION

Goldsmith, Noel
Hi,
Having achieved the montaging of large areas using "exact" tiling, I now
find that the magnification of the microscope varies with the radius from
the center of the image. Some lenses produce pincushion and some produce
barrel distortion. It is only about 10 pixels out of position on the edge of
a 2048x2048 image. But this is enough to make the montages look like a tiled
image complete with grout. (If you look really hard).
This distortion explains my frustration with achieving a truly precise
magnification, the variation across the image means that an "average" value
will be obtained. So correction for the distortion will allow more precise
calibrations to be obtained and applied. Although I am not looking forward
with joy to getting the numbers for every microscope lens in the lab.
I have now established a method to measure the distortions across the field,
using a precise square grid. Which was selected after doing a bit of a
search on the web.
My question, before I re-invent the wheel, (write a plug-in), is has anyone
written a plug-in for ImageJ to do the correction of barrel or pincushion
distortion?
 And if so would they share it?
I can generate fits to the difference between the actual grid positions and
the imaged grid positions to any suitable function.
A straight line is simple but only crosses the curve at a few points.
A polynomial with a +bx +cx^2 +dx^3 is nearly perfect (where a ,b,c d are
constants and x is the difference between the actual distance of the grid
crossing from the middle of the image and the same point in the imaged grid.
And if you use more terms it might be just over fitting.

TIA
Noel Goldsmith

--
Noel Goldsmith
Air Vehicles Division
DSTO
506 Lorimer Street
Port Melbourne
Vic 3207
AUSTRALIA
Reply | Threaded
Open this post in threaded view
|

Re: : RE LENS DISTORTION CORRECTION

Jose A. Jimenez-Berni
Hi Noel,

I have some experience calibrating cameras, but what I've using until
now is the Camera Calibration Toolbox for Matlab written by Bouget:

http://www.vision.caltech.edu/bouguetj/calib_doc/

Basically what you do is to use a chessboard with known dimensions and
then extract the corners from the squares. This module can automatically
extract those corners and then taking several images at different
positions you can estimate the internal parameters of your camera, as
well as distortion coefficients. It also allows you to rectify the image
from those distortions.

I think that it may be a good starting point if you plan to write a
plugin. I will be happy to collaborate with you since I will also need
this plugin in the future. I'm taking aerial pictures with a UAV and I'm
planning to make mosaicking and ortho rectification and for sure I will
need to correct the image from this aberrations.

Berni

Goldsmith, Noel escribió:

> Hi,
> Having achieved the montaging of large areas using "exact" tiling, I now
> find that the magnification of the microscope varies with the radius from
> the center of the image. Some lenses produce pincushion and some produce
> barrel distortion. It is only about 10 pixels out of position on the edge of
> a 2048x2048 image. But this is enough to make the montages look like a tiled
> image complete with grout. (If you look really hard).
> This distortion explains my frustration with achieving a truly precise
> magnification, the variation across the image means that an "average" value
> will be obtained. So correction for the distortion will allow more precise
> calibrations to be obtained and applied. Although I am not looking forward
> with joy to getting the numbers for every microscope lens in the lab.
> I have now established a method to measure the distortions across the field,
> using a precise square grid. Which was selected after doing a bit of a
> search on the web.
> My question, before I re-invent the wheel, (write a plug-in), is has anyone
> written a plug-in for ImageJ to do the correction of barrel or pincushion
> distortion?
>  And if so would they share it?
> I can generate fits to the difference between the actual grid positions and
> the imaged grid positions to any suitable function.
> A straight line is simple but only crosses the curve at a few points.
> A polynomial with a +bx +cx^2 +dx^3 is nearly perfect (where a ,b,c d are
> constants and x is the difference between the actual distance of the grid
> crossing from the middle of the image and the same point in the imaged grid.
> And if you use more terms it might be just over fitting.
>
> TIA
> Noel Goldsmith
>
>  

--
=======================================================
Jose A. Jimenez-Berni
Instituto de Agricultura Sostenible (IAS)
Consejo Superior de Investigaciones Científicas (CSIC)
Alameda del Obispo, s/n
14004 - Córdoba
Spain

Apdo. de Correos 4084
14080 - Córdoba
Spain

Tel: +(34) 957 499 258
Fax: +(34) 957 499 252
e-mail: [hidden email]
=======================================================
Reply | Threaded
Open this post in threaded view
|

Antwort: : RE LENS DISTORTION CORRECTION

Joachim Wesner
In reply to this post by Goldsmith, Noel
Hi,

I once wrote a simple macro to do that, in the moment it has only 2nd and
4th order correction, not third, but you can easily change that.
Unfortunatelly I can in the moment not continue work that I started on
several (useful?) public ImageJ plugins, so I hope it helps AS IS:

Joachim Wesner

// Simple distortion compensation macro, using 2nd and 4th order distortion
// models. Positive numbers will cause barrel distortion

// @author Joachim Wesner 2006/06/29, [hidden email]

//TODO: Rescaling on/off

// Amount of distortion in percent for the (half) diagonal of the image
  dist2 = 5.;
  dist4 = 0.0;

  width = getWidth();
  height = getHeight();
  getStatistics(area, mean);

  cx = width/2;
  cy = height/2;

  Dialog.create("Distortion compensation");
  Dialog.addMessage("Coefficient in % at half image diagonal \n(+ causes
barrel distortion)");
  Dialog.addNumber("2nd order distortion (%):", dist2);
  Dialog.addNumber("4th order distortion (%):", dist4);
  Dialog.show();
  dist2 = Dialog.getNumber();
  dist4 = Dialog.getNumber();

  rmax = sqrt(cx*cx+cy*cy);
  c2 = dist2/100/(rmax*rmax);
  c4 = dist4/100/(rmax*rmax*rmax*rmax);
  scal = 1 + c2*rmax*rmax + c4*rmax*rmax*rmax*rmax;

  inp = newArray(width*height);

  showStatus("Busy");
  showProgress(0.);

  for (iy = 0; iy < height; iy++) {
    base = iy*width;
    for (ix = 0; ix < width; ix++)
      inp[base+ix] = getPixel(ix, iy);
  }

  depth = bitDepth();
  if (depth != 24)
    newImage("Distortion compensation", ""+depth+"-bit black", width,
height, 1);
  else
    newImage("Distortion compensation", "RGB black", width, height, 1);

  for (iy = 0; iy < height; iy++) {
    showProgress((iy+0.5)/height);
    for (ix = 0; ix < width; ix++) {
      dx = ix-cx;
      dy = iy-cy;
      r = sqrt(dx*dx+dy*dy);
      nx = dx/r;
      ny = dy/r;
      r2 = r*r;
      r4 = r2*r2;
      r *= (1+c2*r2+c4*r4)/scal;
//TODO: Better rounding?
      jx = round(cx+nx*r);
      jy = round(cy+ny*r);
      if (jx < 0 || jx > width-1)
        val = mean;
      else if (jy < 0 || jy > height-1)
        val = mean;
      else
        val = inp[jy*width+jx];
      setPixel(ix, iy, val);
    }
  }

  showProgress(1.0);
  showStatus("Done");

  resetMinAndMax();



                                                                                                                                               
                      "Goldsmith, Noel"                                                                                                        
                      <[hidden email]         An:      [hidden email]                                                            
                      NCE.GOV.AU>                       Kopie:   (Blindkopie: Joachim Wesner/DEWET/LMSCentral/Leica)                            
                      Gesendet von: ImageJ              Thema:   : RE LENS DISTORTION CORRECTION                                                
                      Interest Group                                                                                                            
                      <[hidden email]>                                                                                                    
                                                                                                                                               
                                                                                                                                               
                      19.09.2006 09:50                                                                                                          
                      Bitte antworten an ImageJ                                                                                                
                      Interest Group                                                                                                            
                                                                                                                                               




Hi,
Having achieved the montaging of large areas using "exact" tiling, I now
find that the magnification of the microscope varies with the radius from
the center of the image. Some lenses produce pincushion and some produce
barrel distortion. It is only about 10 pixels out of position on the edge
of
a 2048x2048 image. But this is enough to make the montages look like a
tiled
image complete with grout. (If you look really hard).
This distortion explains my frustration with achieving a truly precise
magnification, the variation across the image means that an "average" value
will be obtained. So correction for the distortion will allow more precise
calibrations to be obtained and applied. Although I am not looking forward
with joy to getting the numbers for every microscope lens in the lab.
I have now established a method to measure the distortions across the
field,
using a precise square grid. Which was selected after doing a bit of a
search on the web.
My question, before I re-invent the wheel, (write a plug-in), is has anyone
written a plug-in for ImageJ to do the correction of barrel or pincushion
distortion?
 And if so would they share it?
I can generate fits to the difference between the actual grid positions and
the imaged grid positions to any suitable function.
A straight line is simple but only crosses the curve at a few points.
A polynomial with a +bx +cx^2 +dx^3 is nearly perfect (where a ,b,c d are
constants and x is the difference between the actual distance of the grid
crossing from the middle of the image and the same point in the imaged
grid.
And if you use more terms it might be just over fitting.

TIA
Noel Goldsmith

--
Noel Goldsmith
Air Vehicles Division
DSTO
506 Lorimer Street
Port Melbourne
Vic 3207
AUSTRALIA



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________