Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: How to multiply an image by another image?

  1. #1
    Member Newbie
    Join Date
    Mar 2004
    Posts
    35

    How to multiply an image by another image?

    Hi,
    now I want to multiply an image by another image using opengl? Anyone can tell me how to implement it?
    Thanks for any suggestions!

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2002
    Location
    St. Louis, MO USA
    Posts
    177

    Re: How to multiply an image by another image?

    r2 = r0 * r1;
    g2 = g0 * g1;
    b2 = b0 * b1;
    a2 = a0 * a1;

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2004
    Location
    india
    Posts
    19

    Re: How to multiply an image by another image?

    Red book
    Chapter 8 : Drawing pixels , Bitmaps and fonts and images.

    Refer to the topic "Convolutions".
    Sophia.

  4. #4
    Member Newbie
    Join Date
    Mar 2004
    Posts
    35

    Re: How to multiply an image by another image?

    Sorry, I don't think so.
    For example, I have two images: Img1[256][256] and Img2[256][256]. Now I allocate a block of memory result[256][256] to save the result just like the following C code:
    Code :
    for(int i = 0; i < 255; i++)
    {
       for(int j = 0; j < 255; j++)
       {
          result[i][j] = Img1[i][j]*Img[i][j];
       }
    }
    Now I want to use Opengl to realize the multiply of two images

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    595

    Re: How to multiply an image by another image?

    Simplest way to use opengl for this is to

    1. draw the first image as a texture on a quad.
    2. enable blend with the func (GL_DST_COLOR,GL_ZERO)
    3. draw the next image
    4. turn off blend again( if you want to make the operation more than once)
    5. fetch the result with glReadPixels

    This only works if everything is viewed on the screen. for invisible useage you need to use p-buffers which is a rather unpleasant trip

  6. #6
    Guest

    Re: How to multiply an image by another image?

    What I do now is read the values from the framebuffer using glReadPixels and implement the multiply of two images by CPU. I'll do the steps mentioned above several times, so the frequent callings of glReadPixels becomes the time bottleneck. So I want to do it using Opengl. Just now I did just like what Mazy said and found it becomes slower Are there anyother better methods?
    Thank you!

  7. #7
    Senior Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: How to multiply an image by another image?

    This is very easy to implement in a fragment program.

    If you want to use the fixed function pipeline, take a look at
    http://oss.sgi.com/projects/ogl-samp...nv_combine.txt

    Use GL_MODULATE with the two textures as input to multiply the two images.

    Greetz,

    Nico

  8. #8
    Senior Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    569

    Re: How to multiply an image by another image?

    I'm not sure I understand the problem but can't you do this?

    Texture map the first image onto a quad that's the size of the image using GL_DECAL. At this point you would have the original image.
    Use multi texturing to map the other image onto the same quad using GL_MODULATE. what you end up with is the two images multiplied together.

    if you need to store it somewhere after that you can do a read pixels cropped using the quad size.

    I might be grossly misunderstanding the problem or what you want to achieve but this seems pretty straight forward to me.

    EDIT: looks like Nico and I posted simultaneously.
    we're both saying the same thing

  9. #9
    Guest

    Re: How to multiply an image by another image?

    Hi, NiCo
    I really don't know how to use the ARB_texture_env_combine, can you give me an URL where I can find how to use it. Thank you in advance!

  10. #10
    Member Newbie
    Join Date
    Mar 2004
    Posts
    35

    Re: How to multiply an image by another image?

    Anyone else can help me?
    Thanks a lot.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 05-07-2017, 03:36 AM
  2. Help in Image Multiply Mode
    By mkarthik293 in forum OpenVG
    Replies: 0
    Last Post: 07-17-2008, 12:39 AM
  3. Replies: 5
    Last Post: 01-25-2008, 12:50 PM
  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: Advanced Coding
    Replies: 0
    Last Post: 03-07-2003, 09:00 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