使用GLSL着色器进行图像处理? [英] Image Processing with GLSL shaders?

查看:211
本文介绍了使用GLSL着色器进行图像处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参加了着色器课程,并且对计算机视觉和图像处理感兴趣.我想知道如何将GLSL着色器知识与图像处理融合在一起?如果我使用GLSL实现图像处理算法,会得到什么?

I am enrolled in shaders course and interested in computer vision and image processing. I was wondering how can I mix GLSL shaders knowledge with image processing? What do I gain if I implement image processing algorithms with GLSL?

推荐答案

第一个明显的答案是您获得了并行性.现在,为什么要使用GLSL而不是说CUDA哪一种更灵活? GLSL不需要您拥有NVIDIA图形卡,因此它是一种更加可移植的解决方案(尽管您仍然可以选择OpenCL).

The first obvious answer is that you gain parallelism. Now, why using GLSL rather than, say CUDA which is more flexible ? GLSL doesn't require you to have an NVIDIA graphics card, so it's a much more portable solution (you'd still have the option of OpenCL though).

您可以从并行中学到什么?大多数时候,您可以独立对待像素.例如,增加图像的对比度通常需要您遍历所有像素并应用像素值的仿射变换.如果每个像素都由单独的线程处理,则不再需要执行此循环:您只需对四边形进行分级处理,然后应用一个像素着色器即可读取当前光栅化点的纹理,然后将其输出到渲染目标(或屏幕)转换后的像素值.

What can you gain with parallelism ? Most of the time, you can treat pixels independantly. For instance, increasing the contrast of an image usually requires you to loop over all pixels and apply an affine transform of the pixel values. If each pixel is handled by a separate thread, then you don't need to do this loop anymore : you just raterize a quad, and apply a pixel shader that reads a texture at the current rasterized point, and ouput to the render target (or the screen) the transformed pixel value.

缺点是您的数据需要驻留在GPU上:您需要将所有图像传输到GPU,这可能需要一些时间,并且可能会使并行化所获得的加速无效.因此,当要执行的操作需要大量计算时,或者整个流水线可以保​​留在GPU上时,GPU实施通常就可以完成(例如,如果目标是仅在屏幕上显示修改后的图像,则可以节省需求)将图像传回CPU).

The drawback is that your data need to reside on the GPU : you'll need to transfer all your images to the GPU which can take some time, and can make the speedup gained with the parallelization useless. As such, GPU implementations are often done either when the operations to be made are compute intensive, or when the whole pipeline can remain on the GPU (for instance, if the goal is to only display the modified image on screen, you save the need to transfer back the image on the CPU).

这篇关于使用GLSL着色器进行图像处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆