LDicomDS::GetImage

Summary

Loads the image of a Pixel Data element into a BITMAPHANDLE.

Syntax

#include "Ltdic.h"

L_UINT16 LDicomDS::GetImage(pElement, pBitmap, uStructSize, nIndex, nBitsPerPixel, uFlags, pfnCallback, pUserData)

Parameters

pDICOMELEMENT pElement

Pointer to a DICOMELEMENT structure within the Data Set.

pBITMAPHANDLE pBitmap

Pointer to the image handle that references the loaded image.

L_UINT uStructSize

Size in bytes, of the structure pointed to by pBitmap, for versioning. Use sizeof(BITMAPHANDLE).

L_UINT32 nIndex

Index value that indicates which frame in a Pixel Data element to load.

L_INT32 nBitsPerPixel

Resulting image pixel depth. The following are valid values:

Value Meaning
0 Keep the original file's pixel depth (Do not convert).
1 to 8 The specified bits per pixel in the resulting image
12 12 bits per pixel in the resulting image.
16 16 bits per pixel in the resulting image
24 24 bits per pixel in the resulting image
32 32 bits per pixel in the resulting image

L_UINT uFlags

Flags which control the behavior of this function:

Value Meaning
DICOM_GETIMAGE_AUTO_LOAD_OVERLAYS [0x0001] If set, the function will automatically extract the overlays included in the dataset and add them to the loaded image.
DICOM_GETIMAGE_AUTO_APPLY_MODALITY_LUT [0x0002] If set, the function will automatically apply the "Modality LUT" when loading the image.
DICOM_GETIMAGE_AUTO_APPLY_VOI_LUT [0x0004] If set, the function will automatically apply the "VOI LUT" when loading the image.
DICOM_GETIMAGE_ALLOW_RANGE_EXPANSION [0x0008] (Deprecated, do not use) If set, the function will adjust the high bit and/or low bit (if possible) inside the image handle in order to hold the range of pixel values after applying the modality LUT.
DICOM_GETIMAGE_AUTO_SCALE_MODALITY_LUT [0x0010] If set, the function will scale the resulting pixel data to fit within the range of 0 to 2^BitsPerPixel-1 if any of the values would exceed that range.
DICOM_GETIMAGE_AUTO_SCALE_VOI_LUT [0x0020] Only used in conjunction with DICOM_GETIMAGE_AUTO_SCALE_MODALITY_LUT. If set, the function will rescale the VOI LUT to match the rescale that was performed by DICOM_GETIMAGE_AUTO_SCALE_MODALITY_LUT.
DICOM_GETIMAGE_AUTODETECT_INVALID_RLE_COMPRESSION [0x0040] For RLE compressed, automatically detects if the MSB and LSB segments are written in the incorrect order.
DICOM_GETIMAGE_RLE_SWAP_SEGMENTS [0x0080] Swaps the MSB and LSB segments when loading RLE compressed data. This flag can be used to load RLE compressed data that is stored incorrectly in this manner. Use this flag only in instances where it is known that the RLE compressed data is stored incorrectly. To automatically detect/correct incorrectly stored RLE compressed data, pass the DICOM_GETIMAGE_AUTODETECT_INVALID_RLE_COMPRESSION flag instead.
DICOM_GETIMAGE_VOI_LUT_PAINT_ONLY [0x0200] Automatically applies the "VOI LUT" when loading the image, but only for display purposes
DICOM_GETIMAGE_USE_DISK [0x0400] Allocates the memory for loading the image using hard disk space (if possible).
DICOM_GETIMAGE_FROM_FLTLOAD [0x8000] Internal Use Only.
DICOM_GETIMAGE_KEEP_COLOR_PALETTE [0x10000] When Photometric Interpretation is 'PALETTE COLOR', returns a grayscale image with a color palette. Without this flag, 'PALETTE COLOR' images are converted to 24-RGB
DICOM_GETIMAGE_RESERVED1 [0x20000] Internal Use Only.

FILEREADCALLBACK pfnCallback

Optional callback function for additional processing. If you do not provide a callback function, use NULL as the value of this parameter. If you do provide a callback function, use the function pointer as the value of this parameter.

The callback function must adhere to the function prototype described in FILEREADCALLBACK Function.

L_VOID *pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID  *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure. If the additional parameters are not needed, you can pass NULL in this parameter.

Returns

Value Meaning
0 SUCCESS
>0 An error occurred. Refer to Return Codes.

Comments

Updates the BITMAPHANDLE structure with ONLY data pertaining to the image.  This means that fields such as XResolution and YResolution, will not be updated or will be set with default values.

If pElement is NULL, this function will load any image within the file, based on the nIndex parameter.

If DICOM_GETIMAGE_ALLOW_RANGE_EXPANSION is set in uFlags, note the following example:

For the following dataset attributes:

Attribute Value
Bits allocated 16
Bits stored 12
Pixel Range 0 - +4095
Pixel Representation Unsigned (0)
Photometric Interpretation MONOCHROME2
Rescale Slope 1
Rescale Intercept -1024

After applying the rescale slope and the intercept: - Output minimum pixel value = (0 * 1 +(-1024)) = -1024 - Output maximum pixel value = (4095 * 1 + (-1024)) = 3071

The new pixel value range (1024 to 3071) cannot be represented with the current bits stored (12 bits), which can represent values in the range (2048 to 2048). In this case the function will change the high bit inside the image handle to be 12 instead of 11 (bits stored becomes 13), which can represent values in the range (8192 to 8191).

The function cannot update the high bit and/or low bit if the number of bits stored is already equal to the number of bits allocated.

If the DICOM dataset has a Multi-frame Functional Groups module, some VOI LUT information will be read from the correspondingFrame VOI LUT Sequence, and some Modality LUT information will be read from the corresponding Pixel Value Transformation Sequence.

The specific elements that are read is shown below:

(0028,9132) Frame VOI LUT Sequence Child Elements:

Tag Name
(0028,1050) Window Center
(0028,1051) Window Width
(0028,1055) Window Center & Width Explanation

(0028,9145) Pixel Value Transformation Sequence Child Elements:

Tag Name
(0028,1052) Rescale Intercept
(0028,1053) Rescale Slope
(0028,1054) Rescale Type

For a detailed discussion on Multi-frame Functional Groups and how the DICOM_SET_IMAGE_MFG flags are used, see the topic Multi-frame Functional Groups.

Required DLLs and Libraries

Platforms

Win32, x64

See Also

Functions

Topics

Example

This example fills a bitmap with an image from the Data Set.

L_INT LDicomDS_GetImageExample() 
{ 
   L_INT          nRet; 
   LDicomDS      *pDS; 
   pDICOMELEMENT  pElement; 
   BITMAPHANDLE   Bitmap; 
 
   pDS = new LDicomDS(NULL); 
 
   nRet = pDS->LoadDS(MAKE_IMAGE_PATH(TEXT("image1.dcm")), 0); 
   if(nRet != DICOM_SUCCESS) 
      return nRet; 
 
   pElement = pDS->FindFirstElement(NULL, TAG_PIXEL_DATA, FALSE); 
   if (pElement != NULL) 
   { 
      nRet = pDS->GetImage(pElement, &Bitmap, sizeof(BITMAPHANDLE), 0, 0, DICOM_GETIMAGE_AUTO_APPLY_MODALITY_LUT| 
         DICOM_GETIMAGE_AUTO_APPLY_VOI_LUT, NULL, NULL); 
      if(nRet != DICOM_SUCCESS) 
         return nRet; 
 
      L_FreeBitmap(&Bitmap); 
   } 
 
   delete pDS; 
 
   return DICOM_SUCCESS; 
} 

Help Version 23.0.2024.7.1
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS DICOM C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.