Results 1 to 4 of 4

Thread: auto-scaling grayscale image possible?

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    26

    auto-scaling grayscale image possible?

    Dear all,

    How can I display a grayscale *floating point* image without clamping it myself to the [0,1] region? So for example, when the maximum pixel value is 135.6f, this value should be displayed as full white and when the minimum pixel is 5.1f this value will be displayed as full black, whilst everything in between will be scaled as a grayscale value linearly with respect to [5.1, 135.6].
    (similarly to the "imagesc" function in Matlab).

    Can this be done in OpenGL?

    Currently I work with PBO's and I create a texture as follows:

    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, 1, width, height, 0, GL_LUMINANCE, GL_FLOAT, NULL);

    and update the texture in my display() function with:

    Code :
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,GL_DEPTH_COMPONENT, GL_FLOAT,0);

    If it can be done with these lines, how should I modify the internalformat, type,... parameters?

    Thanks in advance!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,112
    With legacy OpenGL, you can use glPixelMap to specify a mapping which is applied when data is uploaded to a texture. With modern OpenGL, you can use a floating-point internal format such as GL_R16F then perform the conversion in the fragment shader.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    26
    Quote Originally Posted by GClements View Post
    With legacy OpenGL, you can use glPixelMap to specify a mapping which is applied when data is uploaded to a texture. With modern OpenGL, you can use a floating-point internal format such as GL_R16F then perform the conversion in the fragment shader.
    There is no way to do this in modern OpenGL without using fragment shaders? I'm not too familiar with them yet...

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,112
    Quote Originally Posted by samvdj View Post
    There is no way to do this in modern OpenGL without using fragment shaders? I'm not too familiar with them yet...
    The general philosophy behind "modern" OpenGL is that, if you can do it yourself (i.e. in a shader), then OpenGL won't do it for you.

Similar Threads

  1. Rendering grayscale image from array
    By Shintai in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 10-02-2014, 04:39 AM
  2. [SOLVED]- Uploading a grayscale image to OpenGL
    By mobeen in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-09-2011, 05:06 PM
  3. Grayscale image processing
    By axiao in forum OpenGL: Linux
    Replies: 2
    Last Post: 09-01-2005, 01:25 PM
  4. Grayscale image processing
    By axiao in forum OpenGL: Linux
    Replies: 0
    Last Post: 08-29-2005, 01:02 PM
  5. How to texture a RGB image in grayscale?
    By Klynn in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-09-2003, 02:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean