Spherical Filter in Android

I need to apply a spherical filter on the image in android, I added the input and expected output images. The output image will be processed from a square centered in the input image area and displayed in a sphere. Any idea how to do this in Android. Should I use openGL for this, or will 2D-trasformation do this task myself.

Input image
Output image

+5
source share
4 answers

the following code The Fish Eye lens to create a sphere and apply some changes to scale the sphere and generate the background, it will work mainly for square images.

+2
source

OpenGL ES 2.0 iOS:

Spherical refraction example

iOS, , , Android. :

 varying highp vec2 textureCoordinate;

 uniform sampler2D inputImageTexture;

 uniform highp vec2 center;
 uniform highp float radius;
 uniform highp float aspectRatio;
 uniform highp float refractiveIndex;

 void main()
 {
     highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
     highp float distanceFromCenter = distance(center, textureCoordinateToUse);
     lowp float checkForPresenceWithinSphere = step(distanceFromCenter, radius);

     distanceFromCenter = distanceFromCenter / radius;

     highp float normalizedDepth = radius * sqrt(1.0 - distanceFromCenter * distanceFromCenter);
     highp vec3 sphereNormal = normalize(vec3(textureCoordinateToUse - center, normalizedDepth));

     highp vec3 refractedVector = refract(vec3(0.0, 0.0, -1.0), sphereNormal, refractiveIndex);

     gl_FragColor = texture2D(inputImageTexture, (refractedVector.xy + 1.0) * 0.5) * checkForPresenceWithinSphere;     
 }

center ( 0.0 - 1.0 ), radius - , refractiveIndex - / , aspectRatio - ( , ​​ ).

GLSL refract() .

, , .

, iPhone, Android-. GPUImageSphereRefractionFilter GPUImage.

+4

I agree with Tim. Converting one raster image to another does not require three-dimensional points, neither Ray-trace, nor forget it at all, its just 2d. I don't know if opengl has something built-in, but I have enough 3D experience to point you in the right direction. You have to iterate over all the points inside the * region of the circle that you select - this is the key, and find the color using the FISH-EYE transform. You have a lot on the net. hope this helps

0
source

All Articles