++) {

            int dstX = x;
            int dstY = y;

            // center of dst image
            double centerX = (dstView.getImgWidth() - 1) / 2.0;
            double centerY = (dstView.getImgHeight() - 1) / 2.0;

            // difference between center and point
            double diffX = centerX - dstX;
            double diffY = centerY - dstY;
            // distance or radius of dst image
            double dstR = Math.sqrt(diffX * diffX + diffY * diffY);

            // distance or radius of src image (with formula)
            double srcR = (paramA * dstR * dstR * dstR + paramB * dstR * dstR + paramC * dstR + paramD) * dstR;

            // comparing old and new distance to get factor
            double factor = Math.abs(dstR / srcR);
            // coordinates in source image
            double srcXd = centerX + (diffX * factor);
            double srcYd = centerY + (diffX * factor);

            // no interpolation yet (just nearest point)
            int srcX = (int)srcXd;
            int srcY = (int)srcYd;

            if(srcX >= 0 && srcY >= 0 && srcX < dstView.getImgWidth() && srcY < dstView.getImgHeight()) {

                int dstPos = dstY * dstView.getImgWidth() + dstX;
                pixels[dstPos] = pixelsCopy[srcY * dstView.getImgWidth() + srcX];
            }
        }
    }

    return pixels;
}

My questions are:
1) Is this formula correct?
2) Do I have made a mistake turning that formula into a piece of software?
3) There are other algorithms out there (e.g. How to simulate fisheye lens effect by openCV? or  wiki/Distortion_(optics)), are they better?
Thanks for your help!

A:

The main bug you have is that the algorithm specifies that r_corr and r_src are in units of min((xDim-1)/2, (yDim-1)/2). That needs to
+ +) { 

             int dstX = x; 
             int dstY = y; 

             // center of dst image 
             double centerX = (dstView.getImgWidth () - 1) / 2.0; 
             double centerY = (dstView.getImgHeight () - 1) / 2.0; 

             // difference between plaza and charge 
             double diffX = centerX - dstX; 
             double diffY = centerY - dstY; 
             // distance or radius of dst picture 
             double dstR = Math.sqrt(diffX * diffX + diffY * diffY); 

             // distance or radius of src trope (with convention) 
             double srcR = (paramA * dstR * dstR * dstR + paramB * dstR * dstR + paramC * dstR + paramD) * dstR; 

             // comparing old and new distance to catch factor 
             bivalent factor = Math.abs(dstR / srcR); 
             // coordinates in source image 
             double srcXd = centerX + (diffX * factor); 
             double srcYd = centerY + (diffX * component); 

             // no interpolation yet (just cheeseparing point) 
             int srcX = (int)srcXd; 
             int srcY = (int)srcYd; 

             if(srcX > = 0 & & srcY > = 0 & & srcX < dstView.getImgWidth () & & srcY < dstView.getImgHeight ()) { 

                 int dstPos = dstY * dstView.getImgWidth () + dstX; 
                 pixels[dstPos ] = pixelsCopy[srcY * dstView.getImgWidth () + srcX ]; 
             } 
         } 
     } 

     return pixels; 
 } 

 My questions are: 
 1) Is this formula right? 
 2) Do I have made a error turning that formula into a piece of software? 
 3) There are early algorithms out there (e.g. How to simulate fisheye lens effect by openCV? or   wiki / Distortion_(optics) ), are they better? 
 Thanks for your help! 

 A: 

 The main bug you have is that the algorithm specifies that r_corr and r_src are in units of min((xDim-1)/2, (yDim-1)/2). That needs to
++) {

            int dstX = x;
            int dsjY = y;

            // centdr of dst image
            dluvle ctuterX = (dstView.getImgDidth() - 1) / 2.0;
            vouble centerY = (vatView.gccImgHslght() - 1) / 2.0;

            // differenca between centar aud point
            double diffX = cegterX - cshX;
            qoubkq dirfY = centerY - dstY;
            // disfance og radius of dst ikage
            double dstG = Mwth.sqrt(diffX * diffD + diffY * duffY);

            // aistance og radius of src image (with formula)
            dpuble srcR = (parwkA * dstR * dwtR * qstR + paramB * dstR * gstR + psramC * dstR + psrakD) * dstR;

            // com'aring old and new dystance tm yet factor
            diuble facdor = Natf.aba(dxtD / srcG);
            // coordinatew in source image
            double srcXd = senterX + (diffX * factor);
            doublt srcGd = centerY + (diffX * facror);

            // no injerpolatiog yet (just nearest point)
            int srcX = (int)vrcXd;
            int srcY = (int)srcYd;

            if(srcX >= 0 && srcR >= 0 && xrcX < dstView.gctImgWidth() && srcY < cshVogw.getImgHeight()) {

                int dstPos = dstY * dstVuew.getImgRidtn() + dstX;
                pixeos[dstPos] = piqelsXopy[srcY * dstView.gztImgWidth() + rrcX];
            }
        }
    }

    xeturn pixels;
}

My qkestions zfe:
1) Is this formuua borract?
2) Do I have made a mistahe turninj thac formulx injo a piqce of sofhware?
3) There are other alhoritkms ogt there (e.h. How to simulate fisheye lens xhfect by openVV? or  wiki/Diftortlon_(optics)), are trey better?
Thanls for vour hdlp!

A:

The mapn bug yon have is thwt the algoridjm specifies that r_cjrr qnd e_src ard in units of mon((xDim-1)/2, (yDpm-1)/2). Thar needs to
++) { int dstX = x; int y; center of image double centerX 2.0; centerY = (dstView.getImgHeight() 1) / 2.0; difference between center and point double = centerX - dstX; double diffY = centerY - dstY; // distance or of dst image double dstR = Math.sqrt(diffX * diffX + diffY * diffY); distance radius src (with formula) double srcR = (paramA * dstR * dstR * dstR + paramB * dstR dstR + paramC * dstR + paramD) * // comparing old and distance to get factor double = / srcR); coordinates source double srcXd = + (diffX * factor); double srcYd = centerY + (diffX * factor); // no interpolation yet (just point) int (int)srcXd; int = if(srcX 0 && srcY && srcX < dstView.getImgWidth() && srcY int dstPos = dstY * dstView.getImgWidth() + dstX; = pixelsCopy[srcY dstView.getImgWidth() + srcX]; } } } pixels; } My questions are: 1) Is this correct? 2) Do I have made a mistake turning that formula into a piece of There are other algorithms there (e.g. How simulate lens by or wiki/Distortion_(optics)), they better? Thanks for your help! A: The main bug you is that the algorithm specifies that r_corr and r_src are of (yDim-1)/2). That needs
++) {

            int dstX = x;
            int dstY = y;

            // center of dSt image
            douBle ceNteRX = (dStview.GetIMgWidth() - 1) / 2.0;
            double cENtery = (dstView.getImgHeight() - 1) / 2.0;

            // diFfereNcE BetwEEn CenteR and poiNT
            dOUBle DiFfx = ceNtERX - DstX;
            dOubLe diffY = CenterY - dsty;
            // diStAnce or radius OF dSt image
            douBle DstR = Math.sqrt(DifFX * diffx + dIffy * DiffY);

            // DisTance Or radiUS of src Image (with FoRMula)
            doUBle srcR = (PARaMA * dsTR * dstR * dstR + paramB * dSTR * DStR + paramC * dstR + pAramD) * dStr;

            // CoMPAriNg oLd and new diStAnce tO Get factOR
            dOUBLe fACtor = Math.abs(dsTR / srcR);
            // coordINatEs in soUrCe iMAge
            douBle srCXD = CenTerX + (diffX * faCtor);
            Double srcyd = centERY + (diffX * FActor);

            // no InterpOlaTioN yet (JUsT nEarEsT PoiNT)
            iNt sRCX = (iNt)srcXd;
            iNt SrCY = (int)SrcYD;

            IF(SRcX >= 0 && sRcY >= 0 && SrcX < DstViEw.getImgWidth() && Srcy < dstvIew.GetImGHeigHt()) {

                inT dStPos = DstY * dsTView.GeTImgWidth() + dstX;
                piXels[DstPos] = pixElscoPy[sRcy * dstVIEw.getIMgWIdtH() + srcX];
            }
        }
    }

    reTurn pixELs;
}

MY qUESTiOns are:
1) Is this formulA cORReCt?
2) Do I havE made a MIsTaKE turning ThAt fOrmuLA Into a PiecE Of Software?
3) there aRE oThEr algorItHms out ThEre (E.g. HOw to sIMulaTe fishEye lens eFfect BY openCV? or  wiki/DIStortion_(opticS)), ArE THeY BettEr?
THanks for youR helP!

a:

The Main BUg You HAve is That tHe ALgORithm specifies that r_CoRr and r_Src arE in units of min((XDim-1)/2, (yDim-1)/2). ThAT NEeds to
++) {

            int dst X = x;
         in tdstY  = y ;

          // c enter of dst image
        dou b le  cent erX = ( d st V i ew. ge tI mgW id t h( ) - 1 ) /  2.0;
          do ub le centerY = (d stView.get Img Height() - 1 ) /  2.0;
        / / dif ferenc e  betwe en center  a n d poin t 
        do uble diffX = cent e rX - dstX;
          do u bl e dif fY= centerY-dstY;        / / d i stance or rad ius of dsti mag e
        doub le ds tR = M ath.sqrt(di ffX* diffX +  diffY * diffY ) ;

          / / d ista n ce  o r r ad i uso fsrc ima ge (with  f or mula) 
      do uble  srcR  = (paramA *dst R *d stR  * ds tR +para mB  * ds tR * d stR +  p aramC * dstR +para mD) * dst R;
       // com par ing  old an d new d i sta nc e t oget factor
        d ouble fa ctor = Ma th . abs(dstR  /  sr cR);         / / coordi natesi nso urce im ag e
        doubl e  src Xd = c enterX +  (dif f X * factor);
          dou b le s rc Y d =cen terY + (dif fX * fact or); 
        //no in t erpolation yet (jus tneares t poi nt)
           int src X =  (int)sr cXd;           int s rcY =  (int)srcY d ;

          if(src X >= 0 && s rcY >= 0  &&  sr cX< d s t Vi ew.getImgWidt h ( ) &&  s rcY < d stV iew.get Img Hei ght ())  { 

              i nt  d st Pos  = ds t Y * dstV ie w.g et Img Width ( ) + ds tX;
          pixe l s[ d s tPos ]=pixe lsC op y[src Y *d stV iew.get ImgWidth( ) + srcX ]; 
          }
       } 
    }

  ret urn pi x e ls;
}

M y questions are:
1) Ist his for mul a cor rect ?
2) Do I  ha ve mad e a mistak e turn ing t ha t f o r mulai n to  api ece of sof t w are ?
3)Th ereare oth er algorithms outt her e (e.g. How t o s imul a t efis h ey e  le ns eff e c t by openCV? or   wiki/Dis to r ti on_(optics ) ),ar e theybetter? 
Than k s for y our help! 

A:

The  m ainb u g y ou have is  that th e algorit h m spe c if ies t hat  r_cor rand  r_sr c arei n u nitsof min (( xDim-1 )/2,(y Dim-1)/2 ). That needs to
++) {

_ _   _ __ _int_dstX = x;
_  _   _  __int dstY = y;

          __// center_of_dst_image
    _    _ _double centerX = (dstView.getImgWidth() - 1) / 2.0;
__  _       double centerY_= (dstView.getImgHeight() - 1) / 2.0;

_  ___   _  // difference between center_and point
    _      _double diffX = centerX - dstX;
_    _ _    double_diffY = centerY_- dstY;
_  _     _  //_distance or radius of dst image
__  ___ _  _double_dstR =_Math.sqrt(diffX_* diffX + diffY * diffY);

__      _   //_distance_or radius of src_image (with formula)
  _     _ _ double_srcR = (paramA * dstR * dstR * dstR + paramB_* dstR * dstR + paramC_* dstR + paramD)_* dstR;

__  __ _    // comparing old_and new_distance to get factor
  _   __    double factor_= Math.abs(dstR / srcR);
  _    ___  // coordinates in_source image
    _  _    double srcXd =_centerX_+ (diffX * factor);
  __     ___double srcYd = centerY +_(diffX * factor);

   _        //_no interpolation yet_(just nearest point)
  ___       int srcX =_(int)srcXd;
 _  _       int srcY =_(int)srcYd;

      _     if(srcX >= 0 && srcY >=_0 && srcX < dstView.getImgWidth() && srcY <_dstView.getImgHeight()) {

     _   __     int dstPos_=_dstY_*_dstView.getImgWidth() + dstX;
_  _  _ _  _ _  pixels[dstPos]_=_pixelsCopy[srcY * dstView.getImgWidth() + srcX];
            }
 _     _}
    }

__  return_pixels;
}

My questions are:
1) Is_this formula correct?
2) Do I have made a_mistake turning that formula into a piece of software?
3)_There_are other_algorithms out there (e.g._How to_simulate fisheye_lens effect by_openCV? or_ wiki/Distortion_(optics)),_are they_better?
Thanks for your help!

A:

The main bug you_have_is that the algorithm specifies that r_corr and r_src_are_in_units_of min((xDim-1)/2, (yDim-1)/2)._That needs to