typescript - Dicom 图像太亮
问题描述
我在将 dicom 图像放到画布上时遇到问题。我试图遵循这个答案,但它导致图像太亮: dicom image dicom tags
public redraw() {
...
const buffer8 = this.base64ToArrayBuffer(entry)
let minValue = (windowCenter - windowWidth) / 2;
let maxValue = (windowCenter + windowWidth) / 2;
let scale = (maxValue - minValue) / 256;
for (let i = 0, j = 0; i < dstBmp.length; i += 4, j += 2) {
let pixelValue = (buffer8[j]) + (buffer8[j + 1]) * 256
let displayValue = Math.min((pixelValue - minValue) / scale, 255)
dstBmp[i + 0] = displayValue
dstBmp[i + 1] = displayValue
dstBmp[i + 2] = displayValue
dstBmp[i + 3] = 255
}
const idata = new ImageData(dstBmp, entryWidth, entryHeight);
context.putImageData(idata, 0, 0);
}
public base64ToArrayBuffer(base64: string) {
const binary_string = window.atob(base64);
const len = binary_string.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes;
}
解决方案
我没有尝试运行您的代码,也没有完全按照它来查看您在做什么,但是在开始时您确实 - 可能 - 误用了窗口和级别。
基于窗口和级别的最小值和最大值的逻辑应该是最小值是中心减去宽度的一半,反之亦然。
那不是您的代码似乎正在做的事情。您设置最小值和最大值的操作将导致值太低,因此您的图像很可能会显示为全白,这就是您所说的您所看到的。
也许试试这个:
let minValue = windowCenter - windowWidth / 2;
let maxValue = windowCenter + windowWidth / 2;
推荐阅读
- postgresql - 使用 alter table 时无法连接字符串
- ios - 显示一个弹出视图控制器
- c++ - TensorFlow 中的 SaveModelBundle 正在生成错误
- r - 帖子的图片标题未显示在 blogdown 帖子中
- enums - 在 Rust 中使用枚举实现动态多态性
- java - spring-data-mongodb : 从 ($gt, $lt) 到 ($gte, $lte)
- elasticsearch - Elasticsearch:开始和结束日期列表中的匹配范围
- angular - 使用 Angular 8 过滤 Firebase 数据的功能
- objective-c - macOS 以编程方式降低其他应用程序的音量
- spring - 自定义 ConstraintValidator 中的 Spring 服务为空