L_DicomInsertImage

#include "Ltdic.h"

L_LTDIC_API L_UINT16 L_DicomInsertImage(hDS, pElement, pBitmap, nIndex, nCompression, nPhotometric, nBitsPerPixel, nQFactor, uFlags, pfnCallback, pUserData)

Inserts an image in a Pixel Data element.

Parameters

HDICOMDS hDS

A DICOM handle.

pDICOMELEMENT pElement

Pointer to a DICOMELEMENT structure within the Data Set.

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle that references the bitmap to insert.

L_UINT32 nIndex

Index value that indicates the position at which the bitmap will be inserted. This is a zero-based index. For example, if nIndex is 0, the new image will be inserted as the first image in the Pixel Data Element.

L_INT32 nCompression

Value that indicates the type of compression to use, which are affect the way the image is compressed when call the function. Possible values are:

Value Meaning
IMAGE_COMPRESSION_NONE [0x00] No compression.
IMAGE_COMPRESSION_RLE [0x01] RLE compression.
IMAGE_COMPRESSION_JPEG_LOSSLESS [0x02] JPEG LossLess compression.
IMAGE_COMPRESSION_JPEG_LOSSY [0x03] JPEG Lossy compression.
IMAGE_COMPRESSION_J2K_LOSSLESS [0x06] JPEG 2000 lossless compression.
IMAGE_COMPRESSION_J2K_LOSSY [0x07] JPEG 2000 Lossy compression.
IMAGE_COMPRESSION_MPEG2 [0x08] INTERNAL USE ONLY. MPEG-2 compression. Internally used to read/write DICOM files with the LEADTOOLS Medical Multimedia Module. For more information on these filters, refer to LEAD DICOM Reader and LEAD DICOM Writer.
IMAGE_COMPRESSION_MPEG2_HD [0x09] INTERNAL USE ONLY. MPEG-2 compression. Internally used to read/write DICOM files with the LEADTOOLS Medical Multimedia Module. For more information on these filters, refer to LEAD DICOM Reader and LEAD DICOM Writer.

L_INT32 nPhotometric

Photometric constant. Possible values are:

Value Meaning
IMAGE_PHOTOMETRIC_MONOCHROME2 [0x01] 8- or 16-bits per pixel, grayscale image.
IMAGE_PHOTOMETRIC_PALETTE_COLOR [0x02] 8-bits per pixel, palettized color image.
IMAGE_PHOTOMETRIC_RGB [0x03] 24-bits per pixel, RGB color image.

L_INT32 nBitsPerPixel

Resulting bitmap pixel depth. Possible values are:

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

L_INT32 nQFactor

The quality factor (Q factor) is a number that determines the degree of loss in the compression process. You can set a value from 2 to 255, where 2 is the highest quality and 255 is the most compression.

L_UINT uFlags

Flags which control the behaviour of this function. Possible values are:

Value Meaning
DICOM_SETIMAGE_AUTO_SAVE_OVERLAYS [0x0001]If set, the function will automatically insert the overlays associated with the input bitmap into the dataset.
DICOM_SETIMAGE_AUTO_SET_VOI_LUT [0x0002]If set, the function will automatically add a VOI LUT to the dataset.
DICOM_SETIMAGE_MINIMIZE_JPEG_SIZE [0x0004] If set, and the nCompression parameter is IMAGE_COMPRESSION_JPEG_LOSSLESS or IMAGE_COMPRESSION_JPEG_LOSSY, the JPEG compression engine will use optimized Huffman tables, which results in better compression, but slower speed.
DICOM_SETIMAGE_MFG_OVERWRITE_SHARED [0x0008] If set, existing elements under the Shared Functional Groups Sequence will be overwritten. If this flag is not included, Shared Functional Groups Sequence elements are unchanged.
DICOM_SETIMAGE_MFG_VOI_LUT_PER_FRAME [0x0010] If the Frame VOI LUT Sequence does not already exist, it is added under the Per-frame Functional Groups Sequence. If the Frame VOI LUT Sequencealready exists under the Shared Functional Groups Sequence, this flag is ignored.
DICOM_SETIMAGE_MFG_VOI_LUT_SHARED [0x0020] If the Frame VOI LUT Sequence does not already exist, it is added under the Shared Functional Groups Sequence. If the Frame VOI LUT Sequencealready exists under the Per-frame Functional Groups Sequence, this flag is ignored.
DICOM_SETIMAGE_MFG_MODALITY_LUT_PER_FRAME [0x0040] If the Pixel Value Transformation Sequence does not already exist, it is added under the Per-frame Functional Groups Sequence. If the Pixel Value Transformation Sequence already exists under the Shared Functional Groups Sequence, this flag is ignored.
DICOM_SETIMAGE_MFG_MODALITY_LUT_SHARED [0x0080] If the Pixel Value Transformation Sequence does not already exist, it is added under the Shared Functional Groups Sequence. If the Pixel Value Transformation Sequencealready exists under the Per-frame Functional Groups Sequence, this flag is ignored.
DICOM_SETIMAGE_YBR_FULL [0x00000100] This flag is valid only for color images, and if nCompression is either IMAGE_COMPRESSION_NONE or IMAGE_COMPRESSION_RLE. It is ignored for all other transfer syntax values.  If set, this converts the RGB image data to YCbCr, which is one luminance (Y) and two chrominance planes (CB and CR).
DICOM_SETIMAGE_OPTIMIZED_MEMORY [0x00000200] If set, the function will try to save memory usage and utilize disk space instead.

FILESAVECALLBACK pfnCallback

Optional callback function for additional processing.

The callback function must adhere to the function prototype described in FILESAVECALLBACK 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
DICOM_SUCCESS The function was successful.
>0 An error occurred. Refer to Return Codes.

Comments

Most DICOM files will only have one Data Element of type TAG_PIXEL_DATA. Therefore, in most instances you can set pElement to NULL, since the function will automatically insert the image into the only Pixel Data Element in the file. If pElement is not NULL, it must point to the Pixel Data Element itself.

If the DICOM file is CLASS_BASIC_DIRECTORY, the file may contain more than one Pixel Data Element. In this case you must specify in pElement the Pixel Data Element in which to insert the image.

For a table of possible Compression, Photometric, BitsPerPixel, and Quality Factor combinations, refer to Compression Table.

For more options when using the JPEG 2000 compression, refer to L_DicomSetJ2KOptions.

This function will either insert, delete or update one or more of the following elements:

Tag Name
(7FE0,0010) Pixel Data
(0002,0010) Transfer Syntax UID
(0028,0101) Bits Stored
(0028,0100) Bits Allocated
(0028,0102) High Bit
(0028,0103) Pixel Representation
(0028,0010) Rows
(0028,0011) Columns
(0028,0002) Samples per Pixel
(0028,0006) Planar Configuration
(0028,0004) Photometric Interpretation
(0028,0106) Smallest Image Pixel Value
(0028,0107) Largest Image Pixel Value
(0028,1101) Red Palette Color Lookup Table Descriptor
(0028,1102) Green Palette Color Lookup Table Descriptor
(0028,1103) Blue Palette Color Lookup Table Descriptor
(0028,1201) Red Palette Color Lookup Table Data
(0028,1202) Green Palette Color Lookup Table Data
(0028,1203) Blue Palette Color Lookup Table Data
(0028,1199) Palette Color Lookup Table UID
(0028,1052) Rescale Intercept
(0028,1053) Rescale Slope
(0028,1054) Rescale Type
(0028,1221) Segmented Red Palette Color Lookup Table Data
(0028,1222) Segmented Green Palette Color Lookup Table Data
(0028,1223) Segmented Blue Palette Color Lookup Table Data
(0028,3010) VOI LUT Sequence
(0028,1050) Window Center
(0028,1051) Window Width
(0028,1055) Window Center & Width Explanation
(0028,0008) Number of Frames
(0054,0070) Time Slot Vector
(5200,9229) Shared Functional Groups Sequence
(5200,9230) Per-frame Functional Groups Sequence

If the Shared Functional Groups Sequence element or the Per-frame Functional Groups Sequence element is added, an item child element may be added that contains either the (0028,9132) Frame VOI LUT Sequence element or the (0028,9145) Pixel Value Transformation Sequence element.

(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

This function is indifferent to the pixel data restrictions imposed by the various DICOM IOD classes, for example this function will allow the user to insert a colored image into a "Digital X-Ray Image Storage" dataset.

This function will always insert a "Number of Frames" (0028, 0008) element and set its value.

The Multi-frame Functional Groups module may have a Shared Functional Groups Sequence item, and/or a Per-frame Functional Groups Sequence item. Either of these items may have a Pixel Value Transformation Sequence (0028,9145) item, or a Frame VOI LUT Sequence (0028,9132) item. The five DICOM_SETIMAGE_MFG flags can be used to add or modify existing information in the Pixel Value Transformation Sequence or the Frame VOI LUT Sequence.

The following flags are used only if the corresponding sequence (Frame VOI LUT Sequence or Pixel Value Transformation Sequence) does not already exist.

In this case, the sequence is placed in the sequence indicated by the flag (Per-frame Functional Groups Sequence or Shared Functional Groups Sequence).

If a Frame VOI LUT Sequence or a Pixel Value Transformation Sequence already exists in a DICOM dataset, the four above flags are ignored, and the sequence is placed in the location where sequences already exist.

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.

Note:

DICOM_SETIMAGE_MFG_VOI_LUT_PER_FRAME cannot be combined with DICOM_SETIMAGE_MFG_VOI_LUT_SHARED.

DICOM_SETIMAGE_MFG_MODALITY_LUT_PER_FRAME cannot be combined with DICOM_SETIMAGE_MFG_MODALITY_LUT_SHARED.

Note that the only valid values are for nPhotometric are:

All other values are ignored.

The nPhotometric  parameter is used as an indicator as how the data image data will be saved: gray, color, or palletized. The nPhotometric parameter is NOT necessarily going to be the final value of the Photometric Interpretation that is stored in the resulting DICOM dataset.  The resulting Photometric Interpretation in the DICOM dataset is set automatically, based on the compression type, flags, and QFactor.  The table below gives examples of the resulting DICOM dataset Photometric Interpretation, based on various input parameters:

nCompression nPhotometric uFlags nQFactor Resulting Photometric Interpretation in DICOM data set
IMAGE_COMPRESSION_NONE IMAGE_PHOTOMETRIC_MONOCHROME2 0 0 MONOCHROME2
IMAGE_COMPRESSION_NONE IMAGE_PHOTOMETRIC_RGB 0 0 RGB
IMAGE_COMPRESSION_RLE IMAGE_PHOTOMETRIC_RGB DICOM_SETIMAGE_YBR_FULL 0 YBR_FULL
IMAGE_COMPRESSION_JPEG_LOSSY IMAGE_PHOTOMETRIC_RGB 0 40 YBR_FULL_422
IMAGE_COMPRESSION_JPEG_LOSSY IMAGE_PHOTOMETRIC_RGB 0 2 YBR_FULL
IMAGE_COMPRESSION_JPEG_LOSSLESS IMAGE_PHOTOMETRIC_RGB 0 0 RGB
IMAGE_COMPRESSION_J2K_LOSSLESS IMAGE_PHOTOMETRIC_RGB 0 0 YBR_RCT
IMAGE_COMPRESSION_J2K_LOSSY IMAGE_PHOTOMETRIC_RGB 0 0 YBR_ICT

Note: There is no high level function to embed MPEG2 into a DICOM dataset. The Multimedia toolkit (DICOM writer) can create DICOM files with MPEG2 compression.

Note: This function cannot be used to encode DICOM transfer syntaxes (e.g. video compression support) that are not part of the main medical SDK and it is supported only via the LEADTOOLS Medical Multimedia Module.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example inserts an image in Data Set

L_INT DicomInsertImageExample(pBITMAPHANDLE pBitmap) 
{ 
   HDICOMDS      hDS; 
   pDICOMELEMENT pElement; 
   L_UINT16 nRet; 
 
   hDS = L_DicomCreateDS(NULL); 
 
   nRet = L_DicomLoadDS(hDS, MAKE_IMAGE_PATH(TEXT("Image1.dcm")), 0); 
   if (nRet != DICOM_SUCCESS) 
   { 
      L_DicomFreeDS(hDS); 
      return nRet; 
   } 
 
   pElement = L_DicomFindFirstElement(hDS, NULL, TAG_PIXEL_DATA, FALSE); 
   if (pElement != NULL) 
   { 
      L_DicomInsertImage(hDS, pElement, pBitmap, 1, IMAGE_COMPRESSION_NONE, 
                         IMAGE_PHOTOMETRIC_MONOCHROME1, 0, 0, DICOM_SETIMAGE_AUTO_SET_VOI_LUT, NULL, NULL); 
   } 
 
   L_DicomFreeDS(hDS); 
   return DICOM_SUCCESS; 
} 

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

LEADTOOLS DICOM C API Help