Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7527575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:08:27+00:00 2026-05-30T04:08:27+00:00

How can I perform the following image processing tasks using OpenGL ES 2.0 shaders?

  • 0

How can I perform the following image processing tasks using OpenGL ES 2.0 shaders?

  • Colorspace transform ( RGB/YUV/HSL/Lab )
  • Swirling of the image
  • Converting to a sketch
  • Converting to an oil painting
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:08:28+00:00Added an answer on May 30, 2026 at 4:08 am

    I just added filters to my open source GPUImage framework that perform three of the four processing tasks you describe (swirling, sketch filtering, and converting to an oil painting). While I don’t yet have colorspace transforms as filters, I do have the ability to apply a matrix to transform colors.

    As examples of these filters in action, here is a sepia tone color conversion:

    Sepia tone image

    a swirl distortion:

    Swirl distortion image

    a sketch filter:

    Sketch filter

    and finally, an oil painting conversion:

    Oil painting conversion

    Note that all of these filters were done on live video frames, and all but the last filter can be run in real time on video from iOS device cameras. The last filter is pretty computationally intensive, so even as a shader it takes ~1 second or so to render on an iPad 2.

    The sepia tone filter is based on the following color matrix fragment shader:

     varying highp vec2 textureCoordinate;
    
     uniform sampler2D inputImageTexture;
    
     uniform lowp mat4 colorMatrix;
     uniform lowp float intensity;
    
     void main()
     {
         lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
         lowp vec4 outputColor = textureColor * colorMatrix;
    
         gl_FragColor = (intensity * outputColor) + ((1.0 - intensity) * textureColor);
     }
    

    with a matrix of

    self.colorMatrix = (GPUMatrix4x4){
            {0.3588, 0.7044, 0.1368, 0},
            {0.2990, 0.5870, 0.1140, 0},
            {0.2392, 0.4696, 0.0912 ,0},
            {0,0,0,0},
        };
    

    The swirl fragment shader is based on this Geeks 3D example and has the following code:

     varying highp vec2 textureCoordinate;
    
     uniform sampler2D inputImageTexture;
    
     uniform highp vec2 center;
     uniform highp float radius;
     uniform highp float angle;
    
     void main()
     {
         highp vec2 textureCoordinateToUse = textureCoordinate;
         highp float dist = distance(center, textureCoordinate);
         textureCoordinateToUse -= center;
         if (dist < radius)
         {
             highp float percent = (radius - dist) / radius;
             highp float theta = percent * percent * angle * 8.0;
             highp float s = sin(theta);
             highp float c = cos(theta);
             textureCoordinateToUse = vec2(dot(textureCoordinateToUse, vec2(c, -s)), dot(textureCoordinateToUse, vec2(s, c)));
         }
         textureCoordinateToUse += center;
    
         gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse );
    
     }
    

    The sketch filter is generated using Sobel edge detection, with edges shown in varying grey shades. The shader for this is as follows:

     varying highp vec2 textureCoordinate;
    
     uniform sampler2D inputImageTexture;
    
     uniform mediump float intensity;
     uniform mediump float imageWidthFactor; 
     uniform mediump float imageHeightFactor; 
    
     const mediump vec3 W = vec3(0.2125, 0.7154, 0.0721);
    
     void main()
     {
        mediump vec3 textureColor = texture2D(inputImageTexture, textureCoordinate).rgb;
    
        mediump vec2 stp0 = vec2(1.0 / imageWidthFactor, 0.0);
        mediump vec2 st0p = vec2(0.0, 1.0 / imageHeightFactor);
        mediump vec2 stpp = vec2(1.0 / imageWidthFactor, 1.0 / imageHeightFactor);
        mediump vec2 stpm = vec2(1.0 / imageWidthFactor, -1.0 / imageHeightFactor);
    
        mediump float i00   = dot( textureColor, W);
        mediump float im1m1 = dot( texture2D(inputImageTexture, textureCoordinate - stpp).rgb, W);
        mediump float ip1p1 = dot( texture2D(inputImageTexture, textureCoordinate + stpp).rgb, W);
        mediump float im1p1 = dot( texture2D(inputImageTexture, textureCoordinate - stpm).rgb, W);
        mediump float ip1m1 = dot( texture2D(inputImageTexture, textureCoordinate + stpm).rgb, W);
        mediump float im10 = dot( texture2D(inputImageTexture, textureCoordinate - stp0).rgb, W);
        mediump float ip10 = dot( texture2D(inputImageTexture, textureCoordinate + stp0).rgb, W);
        mediump float i0m1 = dot( texture2D(inputImageTexture, textureCoordinate - st0p).rgb, W);
        mediump float i0p1 = dot( texture2D(inputImageTexture, textureCoordinate + st0p).rgb, W);
        mediump float h = -im1p1 - 2.0 * i0p1 - ip1p1 + im1m1 + 2.0 * i0m1 + ip1m1;
        mediump float v = -im1m1 - 2.0 * im10 - im1p1 + ip1m1 + 2.0 * ip10 + ip1p1;
    
        mediump float mag = 1.0 - length(vec2(h, v));
        mediump vec3 target = vec3(mag);
    
        gl_FragColor = vec4(mix(textureColor, target, intensity), 1.0);
     }
    

    Finally, the oil painting look is generated using a Kuwahara filter. This particular filter is from the outstanding work of Jan Eric Kyprianidis and his fellow researchers, as described in the article “Anisotropic Kuwahara Filtering on the GPU” within the GPU Pro book. The shader code from that is as follows:

     varying highp vec2 textureCoordinate;
     uniform sampler2D inputImageTexture;
     uniform int radius;
    
     precision highp float;
    
     const vec2 src_size = vec2 (768.0, 1024.0);
    
     void main (void) 
     {
        vec2 uv = textureCoordinate;
        float n = float((radius + 1) * (radius + 1));
    
        vec3 m[4];
        vec3 s[4];
        for (int k = 0; k < 4; ++k) {
            m[k] = vec3(0.0);
            s[k] = vec3(0.0);
        }
    
        for (int j = -radius; j <= 0; ++j)  {
            for (int i = -radius; i <= 0; ++i)  {
                vec3 c = texture2D(inputImageTexture, uv + vec2(i,j) / src_size).rgb;
                m[0] += c;
                s[0] += c * c;
            }
        }
    
        for (int j = -radius; j <= 0; ++j)  {
            for (int i = 0; i <= radius; ++i)  {
                vec3 c = texture2D(inputImageTexture, uv + vec2(i,j) / src_size).rgb;
                m[1] += c;
                s[1] += c * c;
            }
        }
    
        for (int j = 0; j <= radius; ++j)  {
            for (int i = 0; i <= radius; ++i)  {
                vec3 c = texture2D(inputImageTexture, uv + vec2(i,j) / src_size).rgb;
                m[2] += c;
                s[2] += c * c;
            }
        }
    
        for (int j = 0; j <= radius; ++j)  {
            for (int i = -radius; i <= 0; ++i)  {
                vec3 c = texture2D(inputImageTexture, uv + vec2(i,j) / src_size).rgb;
                m[3] += c;
                s[3] += c * c;
            }
        }
    
    
        float min_sigma2 = 1e+2;
        for (int k = 0; k < 4; ++k) {
            m[k] /= n;
            s[k] = abs(s[k] / n - m[k] * m[k]);
    
            float sigma2 = s[k].r + s[k].g + s[k].b;
            if (sigma2 < min_sigma2) {
                min_sigma2 = sigma2;
                gl_FragColor = vec4(m[k], 1.0);
            }
        }
     }
    

    Again, these are all built-in filters within GPUImage, so you can just drop that framework into your application and start using them on images, video, and movies without having to touch any OpenGL ES. All the code for the framework is available under a BSD license, if you’d like to see how it works or tweak it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the JavaScript Native Interface of GWT I can perform the following: public native
I am looking for XML/XHTML Java library/framework that can perform the following two tasks
Smarty Pants sounds like a cool idea to me: SmartyPants can perform the following
I have a MDI WinForms application that can perform several tasks. Each task is
I've written a small console application that can perform certain tasks. The user interface
I'm following this example in: http://bxslider.com/examples/perform-action-transition-callback But with this example I can get the
I can perform the following SQL Server selection of distinct (or non-repeating names) from
I want to perform the following task using JSF / Richfaces On click of
Wondering if there's any jquery library/plugin that can easily perform the following. At main
we can perform vim substitute on a set of lines by selecting them in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.