我的问题基本上是我应该在uchar4
还是float4
上进行计算?
根据我的理解,char
将取0到025之间的值,那么浮动是否正确?
所以这里是我的代码的两个版本,旧的和新的(它做简单的边缘检测)。
旧:
#pragma version(1)
#pragma rs java_package_name(foo.bar)
rs_allocation inPixels;
int height;
int width;
int threeBythree[];
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
float3 pixel = convert_float4(in[0]).rgb;
if(x==0 || x==239 || y==0 || y==269){
pixel.rb = 0;
pixel.g = 255;
}else{ //do image processing here
float3 pixelNH = convert_float4(rsGetElementAt_uchar4(inPixels, x+1, y)).rgb;
float3 pixelNV = convert_float4(rsGetElementAt_uchar4(inPixels, x, y+1)).rgb;
int grayAvg = (pixel.r + pixel.g + pixel.b)/3;
int grayAvgNH = (pixelNH.r + pixelNH.g + pixelNH.b)/3;
int grayAvgNV = (pixelNV.r + pixelNV.g + pixelNV.b)/3;
int edgeOperatorValue = 2*grayAvg - grayAvgNH - grayAvgNV;
if(edgeOperatorValue < 0){
edgeOperatorValue = -1 * edgeOperatorValue;
};
pixel.r = edgeOperatorValue;
pixel.g = edgeOperatorValue;
pixel.b = edgeOperatorValue;
};
out->xyz = convert_uchar3(pixel);
}
以上产生了这个:
http://s9.postimg.org/9plpvjwun/Screenshot_2015_08_09_17_54_43.png
哪种方式有道理。
新的:
#pragma version(1)
#pragma rs java_package_name(com.apps.foo.bar)
rs_allocation inPixels;
int height;
int width;
uchar4 RS_KERNEL root(uchar4 in, uint32_t x, uint32_t y) {
uchar4 pixel = in.rgba;
if(x==0 || x==width || y==0 || y==height){
pixel.rb = 0;
pixel.g = 255;
}else{ //do image processing here
uchar4 pixelNH = rsGetElementAt_uchar4(inPixels, x+1, y);
uchar4 pixelNV = rsGetElementAt_uchar4(inPixels, x, y+1);
int grayAvg = (pixel.r + pixel.g + pixel.b)/3;
int grayAvgNH = (pixelNH.r + pixelNH.g + pixelNH.b)/3;
int grayAvgNV = (pixelNV.r + pixelNV.g + pixelNV.b)/3;
int edgePixelValue = abs(2 * grayAvg - grayAvgNH + grayAvgNV);
pixel.rgb = edgePixelValue;
};
return pixel;
}
这是相同的数学公式,只是以不同的方式编写。
产生这个:
http://s24.postimg.org/8kgg1a4v9/Screenshot_2015_08_09_17_55_35.png
它看起来像是一张灰度图像。
我正在处理rgb图像,我需要先对每个像素求平均值。我不需要单独完成每个频道。
由于