FishEye Picture Effect (Barrel Distortion) Algorithm (with Java)?

放肆的年华 提交于 2019-12-21 02:56:56

问题


I'm looking for the algorithm (bitmap pixel manipulation) to simulate the fisheye lens (Barrel Distortion) from normal pictures. So far I've found implementation involving external libraries like OpenCV, OpenGL or jhlabs. Since I'm taking a class in Digital Image Processing and I'm making a course assessment project, I'm not sure whether using any external lib will earn me a good grade. So would anyone give me the reference to such algorithm?

Ps. I'm asked to implement it in Java, but example from any language would do.


回答1:


It's good that you've been able to find examples that do what you want. It's helpful to include them in your question -- it makes sure that people that read it are on the same page as you are. So here's a link.

It's also good that you want to do things by yourself, without relying on some library to do the hard work for you. But that doesn't mean you have to ignore such solutions. Here's why.

Look at what OpenCV is actually being used for in that link. These are functions that start with cv:

$ grep -o "cv\\w*" barrel.cpp | sort | uniq
cv
cvCreateImage
cvGet2D
cvGetSize
cvLoadImage
cvNamedWindow
cvSaveImage
cvSet2D
cvShowImage
cvWaitKey

If you look at the OpenCV API, all of these functions just handle mundane tasks like image creation, deletion, display, setting of pixels, etc. None of these tasks are particular to barrel distortion. As far as barrel distortion goes, that solution is not OpenCV specific.

Indeed, the heart of the program is here:

float getRadialX(float x,float y,float cx,float cy,float k){
  x = (x*xscale+xshift);
  y = (y*yscale+yshift);
  float res = x+((x-cx)*k*((x-cx)*(x-cx)+(y-cy)*(y-cy)));
  return res;
}

float getRadialY(float x,float y,float cx,float cy,float k){
  x = (x*xscale+xshift);
  y = (y*yscale+yshift);
  float res = y+((y-cy)*k*((x-cx)*(x-cx)+(y-cy)*(y-cy)));
  return res;
}

Which is just the radial transform formula -- this is the bit that you need to understand. As you can see, there's no OpenCV calls in there.




回答2:


I wrote an article about it in http://www.helviojunior.com.br/fotografia/barrel-and-pincushion-distortion/




回答3:


https://android.googlesource.com/platform/frameworks/base/+/ac39c604d6df8631922c2295b3341cd561f172a5/media/mca/filterpacks/java/android/filterpacks/imageproc/FisheyeFilter.java

this should be what you want.

look at the shader mFishEyeShader and updateProgramParams()



来源:https://stackoverflow.com/questions/4978039/fisheye-picture-effect-barrel-distortion-algorithm-with-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!