gpt4 book ai didi

ios - 在 GPUImage 中将黑白图像转换为透明和白色图像? RGB -> Alpha 基本上

转载 作者:行者123 更新时间:2023-12-01 19:10:31 30 4
gpt4 key购买 nike

我从 GPUImage 中的边缘检测滤镜得到了一张黑白图像,其中白色代表边缘,图像内容大部分是黑色的,不透明的。问题是,我想将此图像叠加在另一个图像之上,以显示边缘如何与下面的图像对齐。

但是非边缘区域不是透明而是黑色,所以基本上我希望黑色是透明的,或者将黑白色的强度改为透明的强度。

我没有找到用于此转换任务的直接 GPUImage 过滤器。 GPUImageChromaKeyFilter 似乎是这样做的一种方式,但它不仅仅是 RGB 到 Alpha channel 的转换,并且不适用于此任务。

最佳答案

编辑:
感谢 Brad 的评论,无需交换 channel 的更有效解决方案是替换“gl_FragColor = vec4(vec3(mag), 1.0);”用“gl_FragColor = vec4(mag);”在边缘检测滤波器源中。


您可以使用 GPUImageColorMatrixFilter 中的参数,并将 channel 从一个映射到另一个。示例代码:

GPUImagePicture *gpuImage = [[GPUImagePicture alloc] initWithImage:image];
GPUImageSobelEdgeDetectionFilter *edgeFilter = [[GPUImageSobelEdgeDetectionFilter alloc] init];

GPUImageColorMatrixFilter *conversionFilter = [[GPUImageColorMatrixFilter alloc] init];
conversionFilter.colorMatrix = (GPUMatrix4x4){
{0.0, 0.0, 0.0, 1.0},
{0.0, 0.0, 0.0, 1.0},
{0.0, 0.0, 0.0, 1.0},
{1.0,0.0,0.0,0.0},
};

[gpuImage addTarget:edgeFilter];
[edgeFilter addTarget:conversionFilter];
[gpuImage processImage];

return [conversionFilter imageFromCurrentlyProcessedOutputWithOrientation:orientation];

colorMatrix 中指定的值基本上是说使用之前的 Alpha channel (对于非透明图像全部为 255)来替换 RGB channel ,并使用之前的 R channel (黑白图像在 RGB 中具有相同的值)来替换 Alpha channel .

关于ios - 在 GPUImage 中将黑白图像转换为透明和白色图像? RGB -> Alpha 基本上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16845812/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com