简体   繁体   English

如何在Renderscript中获得位图分配的相邻像素?

[英]How do you get neighboring pixels of a bitmap Allocation in Renderscript?

I want to perform an image processing operation that needs neighboring pixels, but I'm not sure how to access them from an allocation. 我想执行需要相邻像素的图像处理操作,但是我不确定如何从分配中访问它们。 Most kernels I have seen operate on a single pixel, update it, and then return it. 我见过的大多数内核都对单个像素进行操作,对其进行更新,然后将其返回。 Is there a way I can access the neighbors of (x, y) in the method below. 有没有一种方法可以按以下方法访问(x,y)的邻居。

uchar4 __attribute__((kernel)) invert(uchar4 in, uint32_t x, uint32_t y) {

  uchar4 neighbor = allocation[x+1][y]; // How do I do this in renderscript?
  uchar4 otherNeighbor = allocation[x-1][y]; 
  ...
}

The standard input/output allocations that get implicitly connected are harder to access for neighboring pixels, but you can get to them by just creating a global variable of type rs_allocation. 隐式连接的标准输入/输出分配很难访问相邻像素,但是您可以通过创建rs_allocation类型的全局变量来获取它们。

rs_allocation input;
uchar4 __attribute__((kernel)) invert(uchar4 in, uint32_t x, uint32_t y) {

uchar4 neighbor = rsGetElementAt_uchar4(input, x+1, y);
uchar4 otherNeighbor = rsGetElementAt_uchar4(input, x-1, y);
...
}

In Java, before you call forEach on your kernel, you just need to do: 在Java中,在内核上调用forEach之前,您只需要执行以下操作:

myScript.set_input(myInputAllocation);
myScript.forEach_invert(myInputAllocation, myOutputAllocation);

You can, do this: 你可以这样做:

...
uchar4 neighbor = rsGetElementAt(in, x + 1, y);
uchar4 otherNeighbor = rsGetElementAt(in, x - 1, y);
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM