Creating Two Slices Out Of An Image Stack Using A Double Cut Line

This tutorial teaches you how to use the cut-plane and double cut-plane features to generate a slice out of a stack of images.

  1. Open Visual Studio 2005 or later.
  2. From the File menu > choose Project.
  3. The new project dialog appears.
  4. From project types, expand Other languages node, and click on the Visual C# node.
  5. From the template list on the left side of the dialog, choose Windows Forms Application.
  6. Type the project name as "Creating Two Slices Out Of An Image Stack" in the Project Name field, and then choose OK.
  7. Select OK to create the project.
  8. From View menu > choose Solution explorer.
  9. On the Solution explorer tree, right click on the References node and select Add Reference.
  10. On the Add Reference dialog, select the Browse tab, and add the following dll's.

    • Leadtools.dll
    • Leadtools.Codecs.dll
    • Leadtools.MedicalViewer.dll
    • Leadtools.Medical3D.dll
    • Leadtools.Dicom.dll
    • Leadtools.Codecs.Cmp.dll

    Note: If you do not intend to load a DICOM file, then you do not need to add Leadtools.Dicom.dll.

    Note: If you encounter an "Invalid File Format" or "Feature Not Supported" exception, please refer to the topic Invalid File Format/Feature Not Supported.

  11. Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file:

    VB
    Imports Leadtools 
    Imports Leadtools.Codecs 
    Imports Leadtools.MedicalViewer 
    Imports Leadtools.Medical3D 
    Imports Leadtools.Dicom 
    C#
    using Leadtools; 
    using Leadtools.Codecs; 
    using Leadtools.MedicalViewer; 
    using Leadtools.Medical3D; 
    using Leadtools.Dicom; 

  12. In Form1 create a new method InitClass()

  13. Write the following in the InitClass() method:

    VB
    Private Sub InitClass() 
       Dim MY_LICENSE_FILE As String = "d:\temp\TestLic.lic" 
                          
       ' Unlock DICOM support 
       Dim MY_DicomDEVELOPER_KEY As String = "xyz123abc" 
       RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DicomDEVELOPER_KEY); 
                          
       ' Unlock Medical support 
       Dim MY_MedicalDEVELOPER_KEY As String = "abc123xyz" 
       RasterSupport.SetLicense(MY_LICENSE_FILE, MY_MedicalDEVELOPER_KEY); 
                          
       ' Unlock Medical 3D support 
       Dim MY_3DDEVELOPER_KEY As String = "123xyzabc" 
       RasterSupport.SetLicense(MY_LICENSE_FILE, MY_3DDEVELOPER_KEY); 
                          
       ' Create a new instance of the codecs class, which will be used to load the images. 
       Dim _codecs As RasterCodecs = New RasterCodecs() 
                          
       ' Create a new instance of the Medical Viewer, the layout will be divided to 2X2. 
       Dim viewer As MedicalViewer = New MedicalViewer(2, 2) 
                          
       ' Fit the view to the whole form 
       viewer.Dock = DockStyle.Fill 
                          
       ' Create the cell that will hold the stack of images. 
       Dim cell As MedicalViewerMultiCell = New MedicalViewerMultiCell() 
                          
       ' Add the cell above to the MedicalViewer. 
       viewer.Cells.Add(cell) 
                          
       cell.Image = _codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm") 
       ' Add the viewer as a child to the form. 
       Me.Controls.Add(viewer) 
    End Sub 
    C#
    void InitClass() 
    { 
         string MY_LICENSE_FILE = "d:\\temp\\TestLic.lic"; 
                        
         // Unlock DICOM support 
         string MY_DicomDEVELOPER_KEY = "xyz123abc"; 
         RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DicomDEVELOPER_KEY); 
                          
         // Unlock Medical support 
         string MY_MedicalDEVELOPER_KEY = "abc123xyz"; 
         RasterSupport.SetLicense(MY_LICENSE_FILE, MY_MedicalDEVELOPER_KEY); 
                          
         // Unlock Medical 3D support 
         string MY_3DDEVELOPER_KEY = "123xyzabc"; 
         RasterSupport.SetLicense(MY_LICENSE_FILE, MY_3DDEVELOPER_KEY); 
                                        
         // Create a new instance of the codecs class, which will be used to load the images. 
         RasterCodecs _codecs = new RasterCodecs(); 
                           
         // Create a new instance of the Medical Viewer, the layout will be divided to 2X2. 
         MedicalViewer viewer = new MedicalViewer(2, 2); 
                           
         // Fit the view to the whole form 
         viewer.Dock = DockStyle.Fill; 
                           
         // Create the cell that will hold the stack of images. 
         MedicalViewerMultiCell cell = new MedicalViewerMultiCell(); 
                           
         // Add the cell above to the MedicalViewer. 
         viewer.Cells.Add(cell); 
                           
         cell.Image = _codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm"); 
         // Add the viewer as a child to the form. 
         this.Controls.Add(viewer); 
     } 

    Note: You may need to change the above path to point to "image1.dcm" located in the LEADTOOLS images directory.

  14. Call the InitClass method from inside the Form1 constructor, and place the call after InitializeComponent();

  15. If you run the program now, you will see a 2x2 layout with one slot filled with a multi-frame image.
  16. Add the following lines to the bottom of the InitClass function. This is necessary to view the progress bar:

    VB
    Show() 
    Update() 
    C#
    Show(); 
    Update(); 

  17. Register two events before using the cut-line feature. The two events are:

    • Data3DRequested: Add the following line to the bottom of the InitClass Method:

      VB
      AddHandler cell.Data3DRequested, AddressOf Of MedicalViewerData3DRequestedEventArgs 
      C#
      cell.Data3DRequested += new EventHandler<MedicalViewerData3DRequestedEventArgs>(cell_Data3DRequested); 

      Make the event handler procedure look as shown below:

      VB
      Private Sub cell_Data3DRequested(ByVal sender As Object, ByVal e As MedicalViewerData3DRequestedEventArgs) 
         e.Succeed = Medical3DEngine.Provide3DInformation(e) 
      End Sub 

      C#

      void cell_Data3DRequested(object sender, MedicalViewerData3DRequestedEventArgs e) 
      { 
         e.Succeed = Medical3DEngine.Provide3DInformation(e); 
      } 

    • Data3DFrameRequested: Add the following line to the bottom of the InitClass method:

      VB
      AddHandler cell.Data3DFrameRequested, AddressOf Of MedicalViewer3DFrameRequestedEventArgs 
      C#
      cell.Data3DFrameRequested += new EventHandler<MedicalViewer3DFrameRequestedEventArgs>(cell_Data3DFrameRequested); 

      Make the event handler procedure look like as shown below (You may need to change the file name based on the file name you chose in the previous steps):

      VB
      Private Sub cell_Data3DFrameRequested(ByVal sender As Object, ByVal e As MedicalViewer3DFrameRequestedEventArgs) 
         ' Create a new instance of the Codecs class, which will be used to load the images. 
         Dim _codecs As RasterCodecs = New RasterCodecs() 
         ' This line loads the image with the desired frame index (e.ImageIndex) and assigns it to the argument parameter Image. 
         e.Image = _codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm", 0, CodecsLoadByteOrder.BgrOrGray, e.ImageIndex + 1, e.ImageIndex + 1) 
      End Sub 
      C#
      void cell_Data3DFrameRequested(object sender, MedicalViewer3DFrameRequestedEventArgs e) 
      { 
         // Create a new instance of the Codecs class, which will be used to load the images. 
         RasterCodecs _codecs = new RasterCodecs(); 
         // This line loads the image with the desired frame index (e.ImageIndex) and assigns it to the argument parameter Image. 
         e.Image = _codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm", 0, CodecsLoadByteOrder.BgrOrGray, e.ImageIndex + 1, e.ImageIndex + 1); 
      } 

  18. Add a cut-line or a double cut-line. For this demonstration, let us add a double cut-line as follows:

    • Create two new instances of the MedicalViewerCell and add it to the MedicalViewer. To do this, add the following lines to the bottom of the InitClass method:

      VB
      ' Creating a double cut-line: The double cut-line consist of two cut-lines. For each one, you will need to create a cell. 
      MedicalViewerCell firstCutLineCell = new MedicalViewerCell() 
      MedicalViewerCell secondCutLineCell = new MedicalViewerCell() 
      ' add both of the instances to the MedicalViewer instance. 
      viewer.Cells.Add(firstCutLineCell) 
      viewer.Cells.Add(secondCutLineCell) 
      C#
      // Creating a double cut-line: The double cut-line consist of two cut-lines. For each one, you will need to create a cell. 
      MedicalViewerCell firstCutLineCell = new MedicalViewerCell(); 
      MedicalViewerCell secondCutLineCell = new MedicalViewerCell(); 
      // add both of the instances to the MedicalViewer instance. 
      viewer.Cells.Add(firstCutLineCell); 
      viewer.Cells.Add(secondCutLineCell); 

      These instances will be used to view the double cut-lines output images.

    • Create a new instance of the MedicalViewerDoublePlaneCutLine and add the two cells above through the constructor parameters. To do this, add the following line at the bottom of the InitClass method:

      VB
      Dim doubleCutLine As MedicalViewerDoublePlaneCutLine = new MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell) 
      C#
      MedicalViewerDoublePlaneCutLine doubleCutLine = new MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell); 

    • Finally, add the MedicalViewerDoublePlaneCutLine object created above to the DoubleCutLine collection of the cell with the stack of images. To do this, add the following line at the bottom of the InitClass method:

      VB
      cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine) 
      C#
      cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine); 

  19. Your main class should now look like below:

    VB
    Public Sub New() 
       InitializeComponent() 
       InitClass() 
    End Sub 
                          
    Private Sub InitClass() 
       Dim MY_LICENSE_FILE As String = "d:\temp\TestLic.lic" 
                          
       ' Unlock DICOM support 
       Dim MY_DicomDEVELOPER_KEY As String = "xyz123abc" 
       RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DicomDEVELOPER_KEY); 
                          
       ' Unlock Medical support 
       Dim MY_MedicalDEVELOPER_KEY As String = "abc123xyz" 
       RasterSupport.SetLicense(MY_LICENSE_FILE, MY_MedicalDEVELOPER_KEY); 
                          
       ' Unlock Medical 3D support 
       Dim MY_3DDEVELOPER_KEY As String = "123xyzabc" 
       RasterSupport.SetLicense(MY_LICENSE_FILE, MY_3DDEVELOPER_KEY); 
                          
       ' Create a new instance of the codecs class, which will be used to load the images. 
       Dim _codecs As RasterCodecs = New RasterCodecs() 
                          
       ' Create a new instance of the Medical Viewer, the layout will be divided to 2X2. 
       Dim viewer As MedicalViewer = New MedicalViewer(2, 2) 
                          
       ' Fit the view to the whole form 
       viewer.Dock = DockStyle.Fill 
                          
       ' Create the cell that will hold the stack of images. 
       Dim cell As MedicalViewerMultiCell = New MedicalViewerMultiCell() 
                          
       ' Add the cell above to the MedicalViewer. 
       viewer.Cells.Add(cell) 
                          
       cell.Image = _codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm") 
       ' Add the viewer as a child to the form. 
       Me.Controls.Add(viewer) 
                          
       Show() 
       Update() 
                          
       AddHandler cell.Data3DRequested, AddressOf Of MedicalViewerData3DRequestedEventArgs 
                          
       AddHandler cell.Data3DFrameRequested, AddressOf Of MedicalViewer3DFrameRequestedEventArgs 
                          
       ' Creating a double cut-line: The double cut-line consist of two cut-lines. For each one, you will need to create a cell. 
        Dim firstCutLineCell As MedicalViewerCell = New MedicalViewerCell() 
       Dim secondCutLineCell As MedicalViewerCell = New MedicalViewerCell() 
       ' add both of the instances to the MedicalViewer instance. 
       viewer.Cells.Add(firstCutLineCell) 
       viewer.Cells.Add(secondCutLineCell) 
                          
       Dim doubleCutLine As MedicalViewerDoublePlaneCutLine = New MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell) 
                          
       cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine) 
    End Sub 
                       
    Private Sub cell_Data3DRequested(ByVal sender As Object, ByVal e As MedicalViewerData3DRequestedEventArgs) 
       e.Succeed = Medical3DEngine.Provide3DInformation(e) 
    End Sub 
                       
    Private Sub cell_Data3DFrameRequested(ByVal sender As Object, ByVal e As MedicalViewer3DFrameRequestedEventArgs) 
       ' Create a new instance of the Codecs class, which will be used to load the images. 
       Dim _codecs As RasterCodecs = New RasterCodecs() 
       ' This line loads the image with the desired frame index (e.ImageIndex) and assigns it to the argument parameter Image. 
       e.Image = _codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm", 0, CodecsLoadByteOrder.BgrOrGray, e.ImageIndex + 1, e.ImageIndex + 1) 
    End Sub 
    C#
    public Form1() 
    { 
       InitializeComponent(); 
       InitClass(); 
    } 
    void InitClass() 
    { 
       string MY_LICENSE_FILE = "d:\\temp\\TestLic.lic"; 
                        
       // Unlock DICOM support 
       string MY_DicomDEVELOPER_KEY = "xyz123abc"; 
       RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DicomDEVELOPER_KEY); 
                          
       // Unlock Medical support 
       string MY_MedicalDEVELOPER_KEY = "abc123xyz"; 
       RasterSupport.SetLicense(MY_LICENSE_FILE, MY_MedicalDEVELOPER_KEY); 
                          
       // Unlock Medical 3D support 
       string MY_3DDEVELOPER_KEY = "123xyzabc"; 
       RasterSupport.SetLicense(MY_LICENSE_FILE, MY_3DDEVELOPER_KEY); 
                                        
       // Create a new instance of the codecs class, which will be used to load the images. 
       RasterCodecs _codecs = new RasterCodecs(); 
                           
       // Create a new instance of the Medical Viewer, the layout will be divided to 2X2. 
       MedicalViewer viewer = new MedicalViewer(2, 2); 
                           
       // Fit the view to the whole form 
       viewer.Dock = DockStyle.Fill; 
                           
       // Create the cell that will hold the stack of images. 
       MedicalViewerMultiCell cell = new MedicalViewerMultiCell(); 
                           
       // Add the cell above to the MedicalViewer. 
       viewer.Cells.Add(cell); 
                           
       cell.Image = _codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm"); 
       // Add the viewer as a child to the form. 
       this.Controls.Add(viewer); 
                           
       Show(); 
       Update(); 
                           
       cell.Data3DRequested += new EventHandler<MedicalViewerData3DRequestedEventArgs>(cell_Data3DRequested); 
                           
       cell.Data3DFrameRequested += new EventHandler<MedicalViewer3DFrameRequestedEventArgs>(cell_Data3DFrameRequested); 
                           
       // Creating a double cut-line: The double cut-line consist of two cut-lines. For each one, you will need to create a cell. 
       MedicalViewerCell firstCutLineCell = new MedicalViewerCell(); 
       MedicalViewerCell secondCutLineCell = new MedicalViewerCell(); 
       // add both of the instances to the MedicalViewer instance. 
       viewer.Cells.Add(firstCutLineCell); 
       viewer.Cells.Add(secondCutLineCell); 
                           
       MedicalViewerDoublePlaneCutLine doubleCutLine = new MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell); 
                           
       cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine); 
    } 
                           
    void cell_Data3DRequested(object sender, MedicalViewerData3DRequestedEventArgs e) 
    { 
       e.Succeed = Medical3DEngine.Provide3DInformation(e); 
    } 
                           
    void cell_Data3DFrameRequested(object sender, MedicalViewer3DFrameRequestedEventArgs e) 
    { 
       // Create a new instance of the Codecs class, which will be used to load the images. 
       RasterCodecs _codecs = new RasterCodecs(); 
       // This line loads the image with the desired frame index (e.ImageIndex) and assigns it to the argument parameter Image. 
       e.Image = _codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm", 0, CodecsLoadByteOrder.BgrOrGray, e.ImageIndex + 1, e.ImageIndex + 1); 
    } 

  20. Run the application. If you did everything correctly, you should see three cells: One with a cross line (the double cut-line) and the two cells that represent the generated images.

Note: For more information on how to acquire the above unlock keys, please contact LEAD Technologies support.

Note: Now you will need to have DICOMDIR files for the next step. You can download a sample from our site. Download the file from here (Download chest_ct_compressed_subset_for_3d_tutorial.zip), and extract the file to "C:\Leadtools_DICOMDIR". For more information on building 3D objects from a DICOMDIR, please see Loading a DICOMDIR To Create a 3D Object.

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

LEADTOOLS Imaging, Medical, and Document