Jump to content
  • Advertisement
Sign in to follow this  
zzs2623

Is there anyone who use Cg to do image processing?

This topic is 3515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,all: I want use GPU to do image processing ,such as image histogram equalization,calculate the average of image pixels. I don't known exactly about the Render-to-Texture, all multi-pass technique, Can anyone help me ?? Best wishes. ---zzs2623

Share this post


Link to post
Share on other sites
Advertisement
You can check out PyGPU, which uses Cg to execute algorithms on the GPU from Python. It's a pretty slick system, and it's worth taking a look at...

Share this post


Link to post
Share on other sites
If your GPU supports it, look into using CUDA instead. The programming model's a lot nicer than Cg's for non-3d-rendering stuff, even for image manipulation.

Share this post


Link to post
Share on other sites
Thanks for your reply. But I'm confusing .
I building the framework using cg to realize image processing ,it based on OpenGL under the VC Platform, I can do some algorithms like Gaussian Filter.
Now I want to adjust the contrast of the image,so I need compute the average and standard deviation of the image. whether the calculation can be done in the GPU interior? or any other way to solve the problem?
At the begin, I calculate the parameter use the CPU, and then transfer it to GPU as the Uniform Parameter .It can do the contrast adjust. However ,I think the GPU is do little work in the program. Any other solutions??
---zzs2623
2008-12-4

Share this post


Link to post
Share on other sites
Calculating the average of an image using shaders is usually done by successive downsampling. This is because with pixel shaders you need to be careful with how many samples from a texture you take in per pixel, at least if performance is an issue. Typically you might take 4, 9, or 16 samples.

So for example if you were taking 16 samples, you would render to a render target texture whose width and height were both 1/4 of your original source image. A 1024x1024 source image would result in a 256x256 image after the first pass. Then for each pixel in the destination image, you would calculate the mean of a 4x4 block of texels in the source image and then output this average. In shader code it looks a little like this:


static const float g_vOffsets[4] = {-1.5f, -0.5f, 0.5f, 1.5f};

float4 DownscalePS ( in float2 in_vTexCoord : TEXCOORD0) : COLOR0
{
float4 vColor = 0;
for (int x = 0; x < 4; x++)
{
for (int y = 0; y < 4; y++)
{
float2 vOffset = float2(g_vOffsets[x], g_vOffsets[y]) / g_vSourceDimensions;
float4 vSample = tex2D(PointSampler0, in_vTexCoord + vOffset);
vColor += vSample;
}
}

return vColor / 16;
}



Then you would downscale the 256x256 image to 64x64, then 16x16, then 4x4, until eventually you have a 1x1 texture. The singular texel in this image would contain the mean. You could then use sample this texture in your contrast adjustment shader, and you would never need the data to leave the GPU.

Share this post


Link to post
Share on other sites
Thanks for your help.
You give me a good idea to solve this type problem, I'll try in my project.

I think this way need many fragment shaders, can send results to another shader or not? I want take this results as the next fragment shader's input.
---zzs2623

Share this post


Link to post
Share on other sites
The only data you can send to another fragment shader is what you output to the render target texture. So you render to one texture, then use that texture as input and render to another, and so on.

Share this post


Link to post
Share on other sites
In Cg tutorial,the chapter of two_texture_acsesses introduce the parameter transfer from the vertex shader to the pixel shader, but I'm not sure for the parameter from pixel shader to another shader , Could you give me a example code. I'm really appreciate for your help. Thanks.
---zzs2623

Share this post


Link to post
Share on other sites
You can't send parameters from one shader to another. Like I said before if you want one fragment shader to use a result from a previous fragment shader, it has to be output to a texture and sampled.

Share this post


Link to post
Share on other sites
I don't known exactly about the take the result of prevoius shader as the input of the next shader,like binding the texture and setting the buffer,FBO swap and so on. Could you give me a example program like image contrast enhancement? I want known the Procedure about the image enhancement use GPU.
My email address is :zzs2623@yahoo.com.cn
Thank you!
---zzs2623

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!