我正在尝试在我的应用程序中实现DICOM图像的窗口级功能(在CT上应用骨骼,脑,肺等),并根据DICOM规范实现公式。 我正在根据以下公式更改像素值并创建新图像,但图像变为空白。出了什么问题,这是正确的做法。请帮助:( :(谢谢
BufferedImage image = input image;
double w = 2500; // Window width
double c = 500; // window Center
double ymin = 0;
double ymax = 255;
double x = 0;
double y = 0;
double slope = dicomObject.get(Tag.RescaleSlope).getFloat(true);
double intercept = dicomObject.get(Tag.RescaleIntercept).getFloat(true);
int width = image.getWidth();
int height = image.getHeight();
double val = c - 0.5 - (w - 1) / 2;
double val2 = c - 0.5 + (w - 1) / 2;
for (int m = 0; m < height; m++) {
for (int n = 0; n < width; n++) {
int rgb = image.getRGB(n, m);
int valrgb = image.getRGB(n, m);
int a = (0xff000000 & valrgb) >>> 24;
int r = (0x00ff0000 & valrgb) >> 16;
int g = (0x0000ff00 & valrgb) >> 8;
int b = (0x000000ff & valrgb);
x = a + r + g + b;
if (x <= val)
y = ymin;
else if (x > val2)
y = ymax;
else {
y = ((x - (c - 0.5)) / (w - 1) + 0.5) * (ymax - ymin)+ ymin;
}
y = y * slope + intercept;
rgb = (int) y;
image.setRGB(n, m, rgb);
}
}
String filePath = "out put fileName";
ImageIO.write(image, "jpeg", new File(filePath));
答案 0 :(得分:1)
首先,你的BufferedImage图像是什么? 您希望从原始(decopressed)像素数据中采取三个步骤:
修改强>
你必须告诉我你在哪里得到了#34;输入图像&#34;从?解压缩后的像素数据应该是一个大小为byte [width * height * 2]的字节数组(对于CT Image BitsAllocated总是16,因此* 2)。您可以获得如下存储的值:
ushort code = (ushort)((pixel[0] + (pixel[1] << 8)) & (ushort)((1<<bitsStored) - 1));
int value = TwosComplementDecode(code);