- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想在我的应用程序中对图像应用滤镜效果。我是 Open GL 的新手,想在我的应用中对图像应用Sepia、RGB、GrayScale 效果。我实现了亮度、对比度、饱和度效果,但无法找到任何关于灰度、RGB 和棕褐色效果的解决方案。
提前致谢。
最佳答案
您没有指定是要在 OpenGL ES 1.1 还是 2.0 中执行此操作,因此我假设您指的是较新的 2.0。如果 1.1 确实是您的目标,那么您需要像 Apple 在其 GLImageProcessing example 中那样使用混合模式。 .
对于 OpenGL ES 2.0,您可以使用片段着色器来实现这些效果中的每一个。对于图像的灰度版本,您可以使用以下片段着色器仅提取亮度:
precision highp float;
varying vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);
void main()
{
float luminance = dot(texture2D(inputImageTexture, textureCoordinate).rgb, W);
gl_FragColor = vec4(vec3(luminance), 1.0);
}
对于棕褐色调,您可以使用我在 this answer 中演示的颜色矩阵操作着色器。 :
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
uniform lowp mat4 colorMatrix;
uniform lowp float intensity;
void main()
{
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
lowp vec4 outputColor = textureColor * colorMatrix;
gl_FragColor = (intensity * outputColor) + ((1.0 - intensity) * textureColor);
}
矩阵为
self.colorMatrix = (GPUMatrix4x4){
{0.3588, 0.7044, 0.1368, 0},
{0.2990, 0.5870, 0.1140, 0},
{0.2392, 0.4696, 0.0912 ,0},
{0,0,0,0},
};
我不知道您所说的“RGB 效果”是什么意思。也许您的意思是颜色矩阵操作,在这种情况下,上述内容也适用于您。
所有这些都是我开源中的内置过滤器 GPUImage框架(参见 GPUImageBrightnessFilter、GPUImageContrastFilter、GPUImageSaturationFilter、GPUImageSepiaFilter 和 GPUImageColorMatrixFilter)。如果您真的是 OpenGL ES 的新手,您将需要大量代码来设置场景、将 UIImage 作为纹理拉入、针对它运行顶点和片段着色器、检索该图像并保存它作为 UIImage 退出。 GPUImage 将通过几行 Objective-C 代码为您完成所有这些工作。
关于ios - 对 UIImage 应用 Sepia、RGB、GrayScale 效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700499/
我想使用 R 平均两个灰度图像(两个相同大小的 png 文件)。 以下面的图片为例: img1.png img2.png img3.png img1.png的平均值和 img2.png应该导致类似 i
我很喜欢使用来自 UIGraphicsImageRenderer 的新 API自 iOS 10 以来引入,但现在我想知道是否有可能获得灰度 Data来自其 pngData方法。 假设我有一个名为“ma
我正在使用我在另一个堆栈溢出问题中找到的着色器来以灰度渲染我的屏幕: import com.badlogic.gdx.graphics.glutils.ShaderProgram; public cl
我目前正在使用这个 Bootstrap 主题:http://startbootstrap.com/template-overviews/grayscale/我正在尝试更改导航栏的颜色。我讨厌 CSS,
我正在尝试在 John Zelle 的“Python 编程:计算机科学导论”中做一个练习。我为他的书下载了一个特殊的图形包( graphics.py ,在链接的网站上)。题目如下: 编写一个程序,将彩
我有疑问。当我从 Android 中的 Bitmap 获取像素时。我在里面加载了一张图片,这张图片是灰度图。如果我创建一个 getPixels() 并检查值,我可以看到 R != G != B 的值。
这个问题在这里已经有了答案: Convert a Bitmap to GrayScale in Android (5 个回答) 关闭8年前。 我正在尝试使用红色、绿色、蓝色的平均值将彩色图像转换为灰度
我正在使用 jQuery 插件 Waypoints当用户滚动一组图像时为它们设置动画。我想要实现的效果是,当用户滚动上述图像时,以下 css 会附加到对象 - opacity:1 和 filter:g
我正在做一项作业,要求我们开发一个程序,对具有不同过滤器尺寸 3x3、5x5...11x11 的灰度图像执行平均过滤器 首先我用 Java 开发了一个矩阵类: final public class M
我有一个绘图应用程序,它由一个带有灰度背景图像的容器组成,在它上面有另一个图像(相同但不是灰度图像)。 当我在图像上绘制时,我会删除绘制的位置或转为灰度(以在背景中再现图像)。 我怎样才能做到这一点?
我知道这个问题可以问专家,但我想在 openCV 中访问灰度图像的像素。我正在使用以下代码: cv::Mat img1 = cv::imread("bauckhage.jpg", CV_LOAD_IM
我正在尝试将并行性添加到将 .bmp 转换为灰度 .bmp 的程序中。我看到并行代码的性能通常会差 2-4 倍。我正在调整 parBuffer/分 block 大小,但似乎仍然无法推理。寻求指导。 这
我正在尝试熟悉 OpenCV2 以进行基本的图像和视频处理。现在我无法保存灰度视频帧。以下代码(改编自 here )旨在保存我拍摄的凯旋门 ( arc.avi ) 的 6 秒视频的三个版本 - 一个未
我有一个 HTML5 canvas 元素,用户可以在其中动态移动、调整大小和旋转彩色照片。 我希望用户能够在灰度和颜色之间切换。 我可以想到两种方法,但都不理想: 1) 在每次调整大小和旋转事件(每秒
我在整个互联网上搜索过,但没有找到任何解决方案。 谁能说出 css3 的替代品是什么 filter和 transistion3d在 IE 11 和 IE 12 中? 我不想使用任何插件。 不适用于 S
我在图像上使用 filter:grayscale(1)。图像的容器也有伪 :after 应用背景颜色设置为 mix-blend-mode:screen。似乎一切正常,但在 Safari iOS 上除外
这是我的代码。这很简单。 Mat image = imread("filename.png"); imshow("image", image); waitKey(); //Image looks g
我想在我的应用中实现自定义相机。所以,我正在使用 AVCaptureDevice 创建这个相机。 现在我只想在我的自定义相机中显示灰色输出。因此,我尝试使用 setWhiteBalanceModeLo
我正在尝试使用 SwiftUI 将图像转换为全灰度,并且正在使用 .grayscale() . 文档说明了此方法的以下内容: The intensity of grayscale to apply.
Site in question 我正在尝试使用以下函数将使用 d3.select 附加的所有 svg:images 转换为灰度: js: function convert() { d
我是一名优秀的程序员,十分优秀!