# Thread: How to multiply an image by another image?

1. ## 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. ## Re: How to multiply an image by another image?

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

3. ## 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".

4. ## 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. ## 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. ## 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. ## 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. ## 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. ## 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. ## Re: How to multiply an image by another image?

Anyone else can help me?
Thanks a lot.

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•