Results 1 to 7 of 7

Thread: Recoloring an image

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    2

    Recoloring an image

    I'm looking to recolor an image using OpenGL. So I'd like to be able to perform this kind of recoloring:



    I've tried searching on Google and on this forum for an answer - but to no avail. Ideally, the solution needs to be as efficient as possible.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jun 2009
    Location
    FL , USA
    Posts
    192

    Re: Recoloring an image

    Can be achieved by modifying toon shading technique under shader programming.

  3. #3
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: Recoloring an image

    OpenGL is not an image processing API, so without knowing more details it does not seem overly well suited for your problem.

    You could upload your input image as a texture to the GPU, render a single quad with that texture using a shader that performs the color transformation and download back to CPU memory. I'm not sure that will be much faster (and quite possibly slower) than simply writing a loop over the image that performs the transformation (you only seem to be setting red and green channels to zero and preserve blue?).

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    2

    Re: Recoloring an image

    Yeah, I had considered simply iterating over every pixel and adjusting its colour in the texture before rendering but wondered if there was a better method.

  5. #5
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: Recoloring an image

    Better by what metric?
    If performance: use SSE instructions, if the image exceeds a certain size, split into disjoint blocks and spawn threads to process the blocks.
    For large images there may actually be some benefit to offloading the work to the GPU, because it frees the CPU to do other stuff. Of course that assumes the GPU is idle and you actually have other computations to keep the CPU busy.

    If your metric is ease of maintenance and/or you only do this operation occasionally (or on small data sets), in other words this is not your application's bottleneck: write the loop and move on to more interesting problems

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jun 2009
    Location
    FL , USA
    Posts
    192

    Re: Recoloring an image

    Quote Originally Posted by SullySwede
    Yeah, I had considered simply iterating over every pixel and adjusting its colour in the texture before rendering but wondered if there was a better method.
    No need to write a loop. In fragment shader just check the value of pixel and recolor it on the basis of some threshold function.In short Toon shading.The shader will take care of processing each pixel.

    You need to add a loop if you want to do some processing inside the shader.

  7. #7
    Senior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214

    Re: Recoloring an image

    Quote Originally Posted by awhig
    No need to write a loop. In fragment shader just check the value of pixel and recolor it on the basis of some threshold function.In short Toon shading.The shader will take care of processing each pixel.

    You need to add a loop if you want to do some processing inside the shader.
    That is, the shader will automatically loop over every pixel. This will give you a very high performance, maybe the best you can get. If, by performance, you mean the time it takes to recolor the image.

    You didn't state if you want to present the result graphically, or if you just want to save it on a file.

    The disadvantage of this method is that you only have access to one pixel at a time. If you need a more advanced algorithm, with access to other near pixels, then it is more complicated (but still possible).

Similar Threads

  1. Replies: 1
    Last Post: 07-09-2017, 07:07 AM
  2. Drawing a sphere and recoloring and/or deleting it
    By LReiter in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 09-26-2013, 08:00 AM
  3. read gray image and color index image.
    By yjh1982 in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 08-21-2010, 04:09 AM
  4. Replies: 1
    Last Post: 01-31-2005, 11:01 AM
  5. problem in drawing a texture image(monochrome image)
    By philm in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-07-2003, 10:45 AM

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