←Select platform

SetWindow(int,int,DicomWindowAttributes,DicomSetImageFlags) Method

Sets the attributes that describe the "Window Center" and "Window Width".
public void setWindow(int frameIndex, int index, DicomWindowAttributes attributes, int dicomSetImageFlags) 


A zero-based index that identifies the frame number in the dataset. If the dataset does not support Multi-frames, this parameter is ignored.

The zero-based index of the window center, window width value, to update. According to the DICOM standard, if multiple values are present for the window center and window width, both attributes shall have the same number of values and shall be considered as pairs.

The window-related attributes to set.

determines how the VOI LUT is set


This method will set the attributes that describe window center and window width.

If "Window Center" (0028,1050) does not already exist in the Data Set, this method will insert it and set its value to WindowCenter.

If "Window Width" (0028,1051) does not already exist in the Data Set, this method will insert it and set its value to WindowWidth.

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 Frame VOI LUT Sequence (0028,9132) item. The uFlags parameter can be used to add or modify existing information in the Frame VOI LUT Sequence. The following flags are used only if the Frame VOI LUT Sequence does not already exist.

  • DicomSetImageFlags.MfgVoiLutPerFrame
  • DicomSetImageFlags.MfgVoiLutShared In this case, the sequence is placed in the sequence indicated by the (Per-frame Functional Groups Sequence or Shared Functional Groups Sequence) flag. If a Frame VOI LUT Sequence already exists in a DICOM dataset, uFlags is ignored and the sequence is placed in the location where sequences already exist.

The specific elements that are read or updated when using these flags are 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

Valid flags are DicomSetImageFlags.None, DicomSetImageFlags.MfgOverwriteShared, DicomSetImageFlags.MfgVoiLutPerFrame, DicomSetImageFlags.MfgVoiLutShared. All other flags are ignored. For a detailed discussion on Multi-frame Functional Groups see the topic Multi-frame Functional Groups.


This example will initialize a new DICOM command set that supports Multi-frame functional groups Two VOI LUT will be added to the dataset at the per frame level The VOI LUT from the second frame is retrieved Finally, the VOI LUT from the second frame is deleted

using Leadtools; 
using Leadtools.Dicom; 
void DicomDataSet_SetWindowExample() 
   DicomDataSet ds = new DicomDataSet(); 
   DicomDataSetInitializeFlags flags = 
      DicomDataSetInitializeFlags.ExplicitVR | 
      DicomDataSetInitializeFlags.LittleEndian | 
      DicomDataSetInitializeFlags.AddMandatoryElementsOnly | 
   // Initialize with class that supports multiframe functional groups 
   ds.Initialize(DicomClassType.EnhancedMRImageStorage, flags); 
   // Delete these items -- they will get added again later in the sample 
   // * Shared Functional Group2 Sequence 
   // * Per-frame Functional Group2 Sequence 
   DicomElement element = ds.FindFirstElement(null, DicomTag.PerFrameFunctionalGroupsSequence, false); 
   if (element != null) 
   element = ds.FindFirstElement(null, DicomTag.SharedFunctionalGroupsSequence, false); 
   if (element != null) 
   // Add a VOI LUT on 0th frame 
   DicomWindowAttributes windowAttributes = new DicomWindowAttributes(); 
   windowAttributes.WindowCenter = 32767; 
   windowAttributes.WindowWidth = 65535; 
   windowAttributes.Explanation = "frame 0"; 
   ds.SetWindow(0, 0, windowAttributes, DicomSetImageFlags.MfgVoiLutPerFrame); 
   // Add a second VOI LUT on the 1st frame 
   windowAttributes.WindowCenter = 32000; 
   windowAttributes.WindowWidth = 60000; 
   windowAttributes.Explanation = "frame 1"; 
   ds.SetWindow(1, 0, windowAttributes, DicomSetImageFlags.MfgVoiLutPerFrame); 
   // Retrieve the modality LUT attributes from second frame (frameIndex == 1) 
   DicomWindowAttributes windowAttributes2 = ds.GetWindow(1, 0); 
   string sMsg = string.Format("Window Center: {0}\nWindowWidth: {1}\nExplanation {2}", 
   // Finally, delete the second VOI LUT 
   ds.DeleteWindow(1, DicomSetImageFlags.None); 
   // Save the file 
   ds.Save(Path.Combine(LEAD_VARS.ImagesDir, "Test.dcm"), DicomDataSetSaveFlags.None); 
static class LEAD_VARS 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 

Target Platforms

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

Leadtools.Dicom Assembly