【发布时间】:2013-01-18 08:43:21
【问题描述】:
我在 Matlab 中编写了一个图像过滤器,我想将其转换为 java 以便使用我的 android 应用程序。如何将 short 或 int 转换为 uint8 数据格式。
顺便说一句:我知道java中没有像uint8这样的类型。
任何帮助将不胜感激。
Matlab:
for iX = 1:imageX
for iY = 1:imageY
x(1:3) = input(iX,iY,:);
output(iX, iY, :) = uint8(p1.*x.^5 + p2.*x.^4 + p3.*x.^3 + p4.*x.^2 + p5.*x + p6);
end
end
Java:
for (int iX = 0; iX < width; iX++) {
for (int iY = 0; iY < height; iY++) {
Arrays.fill(x, bitmap.getPixel(iX, iY));
short total = 0;
for (int i = 0; i < 3; i++) {
total +=p1[i] * Math.pow(x[i], 5) + p2[i]
* Math.pow(x[i], 4) + p3[i] * Math.pow(x[i], 3)
+ p4[i] * Math.pow(x[i], 2) + p5[i] * x[i] + p6[i];
}
output.setPixel(iX, iY, total);
}
}
【问题讨论】:
-
java中的8位int是字节
-
你当前的java实现不起作用?
-
@thang 但已签名。所以可能会引起麻烦。
-
很遗憾,java中total的值与matlab不同。
-
@thang 不!不!不!不! Java 中的 8 位 int 已签名!
标签: java matlab int type-conversion