简体   繁体   English

使用 uint16array 数据显示图像

[英]display image by using uint16array data

I am doing a DICOM project using XTK library.我正在使用 XTK 库做一个 DICOM 项目。 Now I need to create a list of thumbnails from input DICOM files (output images could be PNG or JPG).现在我需要从输入 DICOM 文件创建一个缩略图列表(输出图像可以是 PNG 或 JPG)。

During the rendering process, XTK provides an array of pixel data in an Uint16Array of each DICOM file.在渲染过程中,XTK 在每个 DICOM 文件的一个Uint16Array中提供了一个像素数据数组。 But I have no idea about converting those pixel data into a canvas.但我不知道将这些像素数据转换成画布。

我正在看的内容的不必要的屏幕截图

I searched for some related articles or questions but found nothing possible.我搜索了一些相关的文章或问题,但没有发现任何可能。

Nowadays, ImageData has become a constructor , that you can put on a 2d context easily.如今, ImageData 已成为一个构造函数,您可以轻松地将其置于 2d 上下文中。

What it expects as arguments is an UInt8ClampedArray, a width and a height.它期望作为参数的是一个 UInt8ClampedArray,一个宽度和一个高度。

So from an Uint16Array representing rgba pixel data, you'd just have to do因此,从表示 rgba 像素数据的 Uint16Array 中,您只需要做

var data = your_uint16array;
var u8 = new Uint8ClampedArray(data.buffer);
var img = new ImageData(u8, width, height);
ctx.putImageData(img, 0,0);

But according to your screenshot, what you have is actually an Array of Uint16Array, so you will probably have to first merge all these Uint16Arrays in a single one.但是根据您的屏幕截图,您拥有的实际上是一个 Uint16Array 数组,因此您可能必须首先将所有这些 Uint16Array 合并为一个。

Also note that an Uint16Array is a weird view over an rgba pixel data, Uint32Array being more conventional (#ffff vs #ffffffff).另请注意,Uint16Array 是对 rgba 像素数据的奇怪视图,Uint32Array 更传统(#ffff vs #ffffffff)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM