【发布时间】:2017-04-18 14:04:58
【问题描述】:
我目前正在尝试将一段 matlab 代码转换为 java。代码的目的是反转和标准化图像文件的图像像素。在java中,像素存储在一个字节数组中。下面是重要的Matlab代码:
inp2=1024.-inp.-min; %inp is the input array (double precision). min is the minimum value in that matrix.
图像是 16 位的,但仅使用 10 位进行存储,所以这就是 1024 的来源 (2^10)。我明确知道这段代码在 matlab 中有效。但是,我个人并不精通 matlab,而且我的 java 翻译的表现与它的对应部分不同。
以下是我尝试反转图像矩阵的方法:
//bitsStored is the bit depth. In this test, it is 10.
//imageBytes is the pixel data in a byte array
public static short[] invert(int bitsStored) {
short min = min(imageBytes);//custom method. Gets the minimum value in the byte array.
short range = (short) (2 << bitsStored);
short[] holder = new short[imageBytes.length];
for (int i = 0; i < imageBytes.length; i++) {
holder[i] = (short) (range - imageBytes[i] - min);
}
imageBytes = holder;
return imageBytes;
}
但是,图像并没有反转颜色通道,而是丢失了一些数据并变得更加粗糙(更高的对比度、更少的混合等)。我在这里做错了什么?
让我知道是否可以为您更清楚地说明问题。谢谢。
更新: 嗨,我对这段代码还有另一个问题。上面的代码(固定为short[]而不是byte[])可以在同一个文件上反向使用吗?如,如果我使用原始图像的反转版本重新运行此代码,我应该从程序开始获取原始输入/图像吗?我认为唯一的问题是运行之间的最小值会发生变化。
【问题讨论】:
标签: java matlab image-processing