I'm working on a Medical app on iOS. The iOS devices just support GL_UNSIGNED_BYTE with GL_LUMINANCE or generally just support 8 bit per component. Now I have some grayscale images are 16 bit unsigned integer and I want to show them. I find we can't show 16 bit unsigned integer and Therefore I should convert them to 8 bit unsigned integer. But in Medical I should not loss data or should have minimum data loss.
Now, my question is : how to convert 16 bit unsigned integer to 8 bit unsigned integer by a legal conversion in Medical? Now I'm using simplest way to do this. Just divide it to 256 :-O. Some other commercial softwares are doing this and they are using in action.
Thank you in advance.
You MUST convert these values in order to show them applying a Window Level.
Grayscale Dicom images do usually have two Data Elements (Dicom fields) containing the values WC (Window Center, Data Element: 0028,1050) and WL (Window Level, Data Element: 0028,1051). These values define the linear equation necessary to display the information contained in the image.
You can find a more detailed description about the concept of Window Level here.
I tried it by dividing each pixel by a value (max value in the matrix or brightest / 256), then each pixel became an 8 bit value. And it gave same result when I apply pseudo equation mentioned in https://www.dabsoft.ch/dicom/3/C.11.2.1.2/.
const void *bytes = [data bytes];
NSMutableData* ary = [[NSMutableData alloc] init];
int maxValue = 4087/256; //its a dummy value, use your max value in image instead of 4087
for (NSUInteger i = 0; i < [data length]; i += sizeof(int16_t)) {
UInt16 elem = OSReadLittleInt16(bytes, i);
UInt8 temp = round(elem/maxValue);
[ary appendBytes:&temp length:sizeof(UInt8)];
}
Use 'ary' to make your image.