【发布时间】:2020-10-11 07:07:26
【问题描述】:
我只得到了没有标题信息的图像数据,但我知道几件事:
- 16位灰度数据
- 1200x1200(虽然是 1200x900,但底部可能有一个“条”)
- 数据大小为 2880000 字节,适合 1200x1200 x 2bytes ->short here is the raw image data 为了可视化我使用这个:
public static void saveImage(short[] pix, int width, int height, File outputfile) {
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
int[] nBits = {16};
ComponentColorModel cm = new ComponentColorModel(cs, nBits,false, false, Transparency.OPAQUE, DataBuffer.TYPE_USHORT);
SampleModel sm = cm.createCompatibleSampleModel(width, height);
DataBufferShort db = new DataBufferShort(pix, width*height);
WritableRaster raster = Raster.createWritableRaster(sm, db, null);
BufferedImage bf = new BufferedImage(cm, raster, false, null);
if(outputfile!=null)
try {
if(!ImageIO.write(bf, "png", outputfile)) System.out.println("No writer found.");
System.out.println("Saved: "+outputfile.getAbsolutePath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
else System.out.println("error");
}
数据是这样读取的(仅实验/错误代码,仅用于测试):
for(int tt=1; tt<20; tt++) {
pix = new short[1200*1200];
i = 0;
int z = 0;
int line = 0;
//loop
while(i<(1200*1200)) {
pix[i++] = buffer.getShort(z);
z += tt;
if(z>=(len-1)) {
line += 2;
z = line;
if(z>=(len-1)) {
System.out.println("break at "+z);
break;
}
System.out.println("test "+line);
}
}
System.out.println("img_"+imgcount+".png "+pix.length);
saveImage(pix, 1200, 1200, new File("img_"+imgcount+"_"+tt+".png"));
}
在哪里我可以看到 tt=4,8,16 的东西(图像成倍增加)但我无法真正了解整个图片。image tt=8image tt=16 就像解决方案就在我面前,但我看不到它xD 有人可以帮我解决图像存储的算法/格式吗?
编辑:连续读取数据:
short[] pix = new short[1200*1200];
int i = 0;
while(i< (1200*1200) && buffer.remaining()>0) {
pix[i++] = buffer.getShort();
}
编辑 2: Ok 看起来像它的 base64 编码,这很有意义,因为它存储在一个 xml 文件中
【问题讨论】:
-
您能解释一下为什么您会以这种方式读取缓冲区吗?你为什么不连续看短片?
-
以链的形式读取数据只会导致您看不到任何东西的嘈杂灰色图像,因此数据不只是存储在单个链中。
-
我添加了一张图片
-
首先,我会使用
ShortBuffer sb = buffer.order(ByteOrder.BIG_ENDIAN).asShortBuffer(); sb.get(pix,0,sb.remaining();而不是您冗长的循环。然后,如果我得到随机图像,我会尝试使用ByteOrder.LITTLE_ENDIAN。如果它仍然是随机的,我仍然需要解释您选择该算法的原因、您认为它的作用、len是什么等。 -
算法还不正确,因为我不知道数据的存储顺序。看起来它不是简单地存储在一条直线上,更像是每 8 个字节(4 个短裤)。除此之外,我似乎必须订购这些线条......这真的很复杂,而且我不是那种图像格式。我只是使用错误并尝试确定正确的字节序列
标签: java image grayscale image-formats