LEADTOOLS Medical (Leadtools.Dicom assembly)
LEAD Technologies, Inc

SetWindow(Int32,Int32,DicomWindowAttributes,DicomSetImageFlags) Method

Example 







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
Sets the attributes that describe the "Window Center" and "Window Width". .NET support WinRT support Silverlight support
Syntax
public void SetWindow( 
   int frameIndex,
   int index,
   DicomWindowAttributes attributes,
   DicomSetImageFlags flags
)
'Declaration
 
Public Overloads Sub SetWindow( _
   ByVal frameIndex As Integer, _
   ByVal index As Integer, _
   ByVal attributes As DicomWindowAttributes, _
   ByVal flags As DicomSetImageFlags _
) 
'Usage
 
Dim instance As DicomDataSet
Dim frameIndex As Integer
Dim index As Integer
Dim attributes As DicomWindowAttributes
Dim flags As DicomSetImageFlags
 
instance.SetWindow(frameIndex, index, attributes, flags)
public void SetWindow( 
   int frameIndex,
   int index,
   DicomWindowAttributes attributes,
   DicomSetImageFlags flags
)
ObjectiveC Syntax
 function Leadtools.Dicom.DicomDataSet.SetWindow(Int32,Int32,DicomWindowAttributes,DicomSetImageFlags)( 
   frameIndex ,
   index ,
   attributes ,
   flags 
)
public:
void SetWindow( 
   int frameIndex,
   int index,
   DicomWindowAttributes^ attributes,
   DicomSetImageFlags flags
) 

Parameters

frameIndex
A zero-based index that identifies the frame number in the dataset. If the dataset does not support Multi-frames, this parameter is ignored.
index
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.
attributes
The window-related attributes to set.
flags
determines how the VOI LUT is set
Remarks

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 DicomWindowAttributes.WindowCenter.

If "Window Width" (0028,1051) does not already exist in the Data Set, this method will isnert it and set its value to DicomWindowAttributes.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.
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.
Example
Copy CodeCopy Code  
''' 
   Private Sub DicomDataSet_SetWindowExample()
      Dim ds As DicomDataSet = New DicomDataSet()
      Dim flags As DicomDataSetInitializeFlags = DicomDataSetInitializeFlags.ExplicitVR Or DicomDataSetInitializeFlags.LittleEndian Or _
         DicomDataSetInitializeFlags.AddMandatoryElementsOnly Or DicomDataSetInitializeFlags.AddMandatoryModulesOnly
      ' 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

      Dim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PerFrameFunctionalGroupsSequence, False)
      If Not element Is Nothing Then
         ds.DeleteElement(element)
      End If

      element = ds.FindFirstElement(Nothing, DicomTag.SharedFunctionalGroupsSequence, False)
      If Not element Is Nothing Then
         ds.DeleteElement(element)
      End If

      ' Add a VOI LUT on 0th frame
      Dim windowAttributes As DicomWindowAttributes = 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)
      Dim windowAttributes2 As DicomWindowAttributes = ds.GetWindow(1, 0)

      Dim sMsg As String = String.Format("Window Center: {0}" & Constants.vbLf & "WindowWidth: {1}" & Constants.vbLf & "Explanation {2}", _
                                         windowAttributes.WindowCenter, windowAttributes.WindowWidth, windowAttributes.Explanation)
      MessageBox.Show(sMsg)

      ' 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)
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
/// 
   void DicomDataSet_SetWindowExample()
   {
      DicomDataSet ds = new DicomDataSet();
      DicomDataSetInitializeFlags flags =
         DicomDataSetInitializeFlags.ExplicitVR |
         DicomDataSetInitializeFlags.LittleEndian |
         DicomDataSetInitializeFlags.AddMandatoryElementsOnly |
         DicomDataSetInitializeFlags.AddMandatoryModulesOnly
         ;
      // 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)
         ds.DeleteElement(element);

      element = ds.FindFirstElement(null, DicomTag.SharedFunctionalGroupsSequence, false);
      if (element != null)
         ds.DeleteElement(element);

      // 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}",
         windowAttributes.WindowCenter,
         windowAttributes.WindowWidth,
         windowAttributes.Explanation);
      MessageBox.Show(sMsg);

      // 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:\Users\Public\Documents\LEADTOOLS Images";
}
/// 
async Task DicomDataSet_SetWindowExample()
{
   DicomDataSet ds = new DicomDataSet();
   DicomDataSetInitializeFlags flags =
      DicomDataSetInitializeFlags.ExplicitVR |
      DicomDataSetInitializeFlags.LittleEndian |
      DicomDataSetInitializeFlags.AddMandatoryElementsOnly |
      DicomDataSetInitializeFlags.AddMandatoryModulesOnly
      ;
   // 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, DicomTagConstants.PerFrameFunctionalGroupsSequence
      , false);
   if (element != null)
      ds.DeleteElement(element);

   element = ds.FindFirstElement(null, DicomTagConstants.SharedFunctionalGroupsSequence, false);
   if (element != null)
      ds.DeleteElement(element);

   // 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}",
      windowAttributes.WindowCenter,
      windowAttributes.WindowWidth,
      windowAttributes.Explanation);
   Debug.WriteLine(sMsg);

   // Finally, delete the second VOI LUT
   ds.DeleteWindow(1, DicomSetImageFlags.None);

   // Save the file
   string dicomFileNameOutput = "Test.dcm";
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(dicomFileNameOutput);
   ILeadStream streamOutput = LeadStreamFactory.Create(saveFile);
   using (IDisposable disposableOUT = streamOutput as IDisposable)
   {
      await ds.SaveAsync(streamOutput, DicomDataSetSaveFlags.None);
   }
}
void DicomDataSet_SetWindowExample(Stream outputStream)
{
   DicomDataSet ds = new DicomDataSet();
   DicomDataSetInitializeFlags flags =
      DicomDataSetInitializeFlags.ExplicitVR |
      DicomDataSetInitializeFlags.LittleEndian |
      DicomDataSetInitializeFlags.AddMandatoryElementsOnly |
      DicomDataSetInitializeFlags.AddMandatoryModulesOnly
      ;
   // 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)
      ds.DeleteElement(element);

   element = ds.FindFirstElement(null, DicomTag.SharedFunctionalGroupsSequence, false);
   if (element != null)
      ds.DeleteElement(element);

   // 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}",
      windowAttributes.WindowCenter,
      windowAttributes.WindowWidth,
      windowAttributes.Explanation);
   Debug.WriteLine(sMsg);

   // Finally, delete the second VOI LUT
   ds.DeleteWindow(1, DicomSetImageFlags.None);

   // Save the file
   ds.Save(outputStream, DicomDataSetSaveFlags.None);
}
Private Sub DicomDataSet_SetWindowExample(ByVal outputStream As Stream)
   Dim ds As DicomDataSet = New DicomDataSet()
      Dim flags As DicomDataSetInitializeFlags = DicomDataSetInitializeFlags.ExplicitVR Or _
                                                 DicomDataSetInitializeFlags.LittleEndian Or _
                                                 DicomDataSetInitializeFlags.AddMandatoryElementsOnly Or _
                                                 DicomDataSetInitializeFlags.AddMandatoryModulesOnly
   ' 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

   Dim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PerFrameFunctionalGroupsSequence, False)
   If Not element Is Nothing Then
      ds.DeleteElement(element)
   End If

   element = ds.FindFirstElement(Nothing, DicomTag.SharedFunctionalGroupsSequence, False)
   If Not element Is Nothing Then
      ds.DeleteElement(element)
   End If

   ' Add a VOI LUT on 0th frame
   Dim windowAttributes As DicomWindowAttributes = 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)
   Dim windowAttributes2 As DicomWindowAttributes = ds.GetWindow(1, 0)

      Dim sMsg As String = String.Format("Window Center: {0}" _
                                         & Constants.vbLf _
                                         & "WindowWidth: {1}" _
                                         & Constants.vbLf _
                                         & "Explanation {2}", _
                                         windowAttributes.WindowCenter, _
                                         windowAttributes.WindowWidth, _
                                         windowAttributes.Explanation)
   Debug.WriteLine(sMsg)

   ' Finally, delete the second VOI LUT
   ds.DeleteWindow(1, DicomSetImageFlags.None)

   ' Save the file
   ds.Save(outputStream, DicomDataSetSaveFlags.None)
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DicomDataSet Class
DicomDataSet Members
Overload List
GetWindowCount Method
VoiLutCount Property
GetWindow(Int32) Method
DeleteWindow Method
GetVoiLut Method
SetVoiLut Method
GetVoiLutData Method
DeleteVoiLut Method

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Dicom requires a Medical toolkit server license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features