|
Hello everyone, my brother is now using dicom as a browser for image.
The various tag data in the dicom file are already readable. When displaying pixel information, I encountered a problem:
The images I am looking for are all OW-shaped.
Bits Allocated = 16
Bits Stored = 16
High Bit = 15
window center = 40
window width = 400
I put every two bytes of data into the last two bytes of an int. Then use the Toolkit class in java, the code is as follows:
byte pixelData [] = new byte [fi.width * fi.height * 2];
int imageData [] = new int [fi.width * fi.height];
Ranch
try {
RandomAccessFile raf = new RandomAccessFile (directory + fileName, "r");
raf.seek (fi.pixelData);
System.out.println (fi.pixelData);
raf.read (pixelData, 0, fi.width * fi.height * 2);
}
catch (Exception e)
{
e.printStackTrace ();
}
int currentLine = 0;
int k = 0;
for (int j = 0; j <fi.height; j ++)
{
Ranch
for (int i = 0; i <fi.width; i ++)
{
int intdata = ((int) pixelData [2 * k]) << 8;
intdata = intdata | (int) pixelData [2 * k + 1];
imageData [fi.width * currentLine + i] = intdata;
k ++;
Ranch
}
currentLine ++;
}
image = Toolkit.getDefaultToolkit (). createImage (new MemoryImageSource (fi.width, fi.height, imageData, 0, fi.width));
But the resulting image is light yellow. Not a grayscale image. I think it must be that the intdata value of each pixel should be converted before it can be placed in the imageData array.
But I don't know how to switch or how to adjust the window width and window level.
Please troubleshoot your code to make it appear grayscale.
thank you very much! |
|