我想在服务器的简短[]]中显示一个图像。
服务器(C ++)将图像写为像素的无符号短[](12位深度)。
我的Java应用程序通过CORBA调用该服务器获取图像。
由于Java没有Ushort,因此将像素存储为(签名)短[]。
这是我用来从数组中获取缓冲图的代码:
private WritableImage loadImage(short[] pixels, int width, int height) {
int[] intPixels = new int[pixels.length];
for (int i = 0; i < pixels.length; i++) {
intPixels[i] = (int) pixels[i];
}
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
WritableRaster raster = (WritableRaster) image.getData();
raster.setPixels(0, 0, width, height, intPixels);
return SwingFXUtils.toFXImage(image, null);
}
然后:
WritableImage orgImage = convertShortArrayToImage2(image.data, image.size_x, image.size_y);
//load it into the widget
Platform.runLater(() -> {
imgViewer.setImage(orgImage);
});
我检查了宽度= 1280和高度= 1024,并且像素阵列为1280x1024,与光栅高度和宽度相匹配。
但是,我在行中的界限出现了一个数组:
raster.setPixels(0, 0, width, height, intPixels);
它们都会产生相同的错误
- 我尝试了所有图像型,除了: type_ushort_gray :我认为这是一个是一个, ,但显示全黑图像
- type_byte_gray :哪个显示图像为负(!)和大量谷物(?)
- type_byte_indexed :喜欢上面以有趣的方式上色的内容,
当我从镜头转换为int时,我也尝试过转换位,没有任何区别:
intPixels[i] = (int) pixels[i] & 0xffff;
所以..我在寻找互联网中的解决方案后感到非常沮丧。任何帮助都非常欢迎
编辑。以下是接收到的图像的示例,并将其转换为服务器端的JPG。不确定它是否有用,因为我认为它是由像素重塑(SQRT)的:
I want to display an image received in a short[] of pixels from a server.
The server(C++) writes the image as an unsigned short[] of pixels (12 bit depth).
My java application gets the image by a CORBA call to this server.
Since java does not have ushort, the pixels are stored as (signed) short[].
This is the code I'm using to obtain a BufferedImage from the array:
private WritableImage loadImage(short[] pixels, int width, int height) {
int[] intPixels = new int[pixels.length];
for (int i = 0; i < pixels.length; i++) {
intPixels[i] = (int) pixels[i];
}
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
WritableRaster raster = (WritableRaster) image.getData();
raster.setPixels(0, 0, width, height, intPixels);
return SwingFXUtils.toFXImage(image, null);
}
And later:
WritableImage orgImage = convertShortArrayToImage2(image.data, image.size_x, image.size_y);
//load it into the widget
Platform.runLater(() -> {
imgViewer.setImage(orgImage);
});
I've checked that width=1280 and height=1024 and the pixels array is 1280x1024, that matches with the raster height and width.
However I'm getting an array out of bounds error in the line:
raster.setPixels(0, 0, width, height, intPixels);
I have try with ALL ImageTypes , and all of them produce the same error except for:
- TYPE_USHORT_GRAY: Which I thought it would be the one, but shows an all-black image
- TYPE_BYTE_GRAY: which show the image in negative(!) and with a lot of grain(?)
- TYPE_BYTE_INDEXED: which likes the above what colorized in a funny way
I also have tried shifting bits when converting from shot to int, without any difference:
intPixels[i] = (int) pixels[i] & 0xffff;
So..I'm quite frustrated after looking for days a solution in the internet. Any help is very welcome
Edit. The following is an example of the images received, converted to jpg on the server side. Not sure if it is useful since I think it is made from has pixel rescaling (sqrt) :

发布评论
评论(1)
好吧,最后我解决了它。
可能不是最好的解决方案,但它可以正常工作,并且可以帮助某人。...
作为图像灰度12位深度,我使用了类型 type_byte_gray的bufferedimage 像素阵列。从0-4095到0-255。
我遇到了一个问题,以建立量表的较高和下限。我用n个较高/下限的AVG进行了测试,该AVG效果很好,直到有人向我发送了转换Zscale算法(例如DS9工具中使用)的Java程序的链接,以获取GreyScale VLUES范围的限制显示:
从那时起,我修改了上一个代码,它像魅力一样工作:
Well, finally I solved it.
Probably not the best solution but it works and could help someone in ether....
Being the image grayscale 12 bit depth, I used BufferedImage of type TYPE_BYTE_GRAY, but I had to downsample to 8 bit scaling the array of pixels. from 0-4095 to 0-255.
I had an issue establishing the higher and lower limits of the scale. I tested with avg of the n higher/lower limits, which worked reasonably well, until someone sent me a link to a java program translating the zscale algorithm (used in DS9 tool for example) for getting the limits of the range of greyscale vlues to be displayed:
find it here
from that point I modified the previous code and it worked like a charm: