gpt4 book ai didi

android - Renderscript - 获取相邻像素

转载 作者:行者123 更新时间:2023-11-30 03:31:28 35 4
gpt4 key购买 nike

我开始探索 renderscript 的强大功能。

尝试使用 2D 图像数据,我可以将像素转换为其他像素。但是,如何从输入分配中获取相邻像素?

我想知道例如内置的 convolve3x3 过滤器是如何完成的,当它需要相邻像素进行操作时,它会很好地钳制图像边缘的像素。

假设我有函数

void root(const uchar4 *v_in, uchar4 *v_out) {
float4 f4 = rsUnpackColor8888(*v_in);
// do something on pixel
uchar4 u4 = rsPackColorTo8888(f4);
*v_out = u4;
}

我真的应该像 v_in[1] 或 v_in[k] 那样索引 v_in 以获得其他像素,还是有一些聪明的 rs* 函数来获取相邻的水平/垂直像素,同时提供适当的图像尺寸钳位,所以我没有索引 v_in 数组超出其大小?

最佳答案

如果你想查看相邻像素(并且你正在使用 rs_allocations),你应该只使用一个全局 rs_allocation 而不是将它作为 *v_in 传递。这看起来像:

rs_allocation in;

// Using the new kernel syntax where v_out becomes the return value.
uchar4 __attribute__((kernel)) doSomething(uint32_t x, uint32_t y) {
uchar4 u4 = rsGetElementAt_uchar4(in, x, y); // You can adjust x,y here to get neighbor values too.
float4 f4 = rsUnpackColor8888(u4);
...
return rsPackColorTo8888(f4);
}

不幸的是,没有很好的方法可以通过常规 rs_allocation 进行自动夹紧,但您可以调整代码以手动进行边缘夹紧。将 maxX、maxY 作为全局变量传递给脚本,然后在任何 rsGetElementAt*() 之前动态检查您是否在范围内。如果您确实想要自动夹紧/环绕行为,您还可以查看 rs_sampler 和 rsSample() API。

关于android - Renderscript - 获取相邻像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17399255/

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