Displaying an Image in LEADTOOLS HTML5 / JavaScript Controls Medical Image Viewer


Take the following steps to display an image in the controls Medical Image Viewer:

  1. Create a new HTML file and name it display.html and copy the following HTML5 template into the file:

    <!DOCTYPE html> 
     <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> 
        <head> <meta charset="utf-8" /> <title>LEADTOOLS Demo</title> 
        <!-- LEADTOOLS Libraries --> 
        <script type="text/javascript" src="lib/Leadtools.js"></script> 
        <script type="text/javascript" src="lib/Leadtools.Controls.js"></script> 
              <script type="text/javascript" src="lib/Leadtools.Annotations.Engine.js"></script> 
              <script type="text/javascript" src="lib/Leadtools.Annotations.Designers.js"></script> 
              <script type="text/javascript" src="lib/Leadtools.Annotations.Rendering.JavaScript.js"></script> 
              <script type="text/javascript" src="lib/Leadtools.Annotations.Automation.js"></script> 
        <script type="text/javascript" src="lib/Leadtools.Controls.Medical.js"></script> 
        <script type="text/javascript" src="app.js"></script> 
        <!-- DIV to use as the container for the LEADTOOLS image viewer--> 
        <div id="MedicalViewerParentDiv" style="width: 600px; height: 600px; background-color:darkgray"></div> 

  2. Create a folder named lib in the same location as the HTML and copy the LEADTOOLS JavaScript files to this folder. These files can be found in "<LEADTOOLS_INSTALLDIR>\Bin\JS":

    • Leadtools.js
    • Leadtools.Controls.js
    • Leadtools.Annotations.Engine.js
    • Leadtools.Annotations.Designers.js
    • Leadtools.Annotations.Rendering.JavaScript.js
    • Leadtools.Annotations.Automation.js
    • Leadtools.Controls.Medical.js

    The HTML contains the minimum code required to use the LEADTOOLS JavaScript Image Viewer in your application.

    • Leadtools.js is the kernel of the LEADTOOLS JavaScript support and is required by all other libraries.
    • Leadtools.Controls.js contains the basic image viewer functionality.
    • Leadtools.Annotations.Engine.js, Leadtools.Annotations.Automation.js, Leadtools.Annotations.Designers.js and Leadtools.Annotations.Rendering.JavaScript.js contain the annotations functionalities that will be handled by the medical viewer.
    • Leadtools.Controls.Medical.js contains the medical image viewer that holds the medical images, and contains various medical functionalities, like window level, reference line, MPR...etc. All of these JS files are added to the head section of the HTML.

    Next, create an HTML DIV element to act as the container for the viewer.
    And, create the app.js that will contain the JavaScript code to create and use the viewer.

  3. Create a text file called app.js in the same folder as display.html and add the following code to it:
     window.onload = function () { 
         // Get the parent DIV 
         var imageViewerDiv = document.getElementById("MedicalViewerParentDiv"); 
         // Create the medical viewer control, and specify the number or rows and columns. 
         var viewer = new lt.Controls.Medical.MedicalViewer(imageViewerDiv, 2, 2); 
         // [optional] Update the splitter size so it become thick and easy to move. 
        // Create a cell name var  
        cellName = 'MedicalCell' + Date.now(); 
        // Create a cell. It will contain an image or a series of images, based on how many Frames are added (see below for more details). 
        var cell = new lt.Controls.Medical.Cell(viewer, viewer.get_divId(), 1, 1); 
        // Set the show border to "true", to show a border around the cell. 
        // Add the cell to the viewer.  
        // [optional] Select the cell (it can also be selected by clicking on it.) 
        // Now create a frame object which will hold the image inside the cell. 
        var cellFrame = new lt.Controls.Medical.Frame(cell); 
        // Add the frame to the cell class. 
        // we are now going to download an image from leadtools medical viewer demo web site, you need to change this to download images from your database. 
        var xhttp = new XMLHttpRequest(); 
        xhttp.onreadystatechange = function(data) 
          if (this.readyState == 4 && this.status == 200) 
             // here we got the authentication Code that we need to retrieve the images from leadtools database. 
             authenticationCode = encodeURIComponent(this.responseText); 
             // now, this is the MRTI info that contains the image information, width, height, tiles....etc. 
             var mrtiInfo = new lt.Controls.Medical.MRTIImage(); 
             // The image dpi. 
             mrtiInfo.fullDpi = lt.LeadSizeD.create(150, 150); 
             // the tile size, recommended value is 256 
             mrtiInfo.tileSize = lt.LeadSizeD.create(256, 256); 
             mrtiInfo.frameIndex = 0; 
             // does this image support window leve. 
             mrtiInfo.supportWindowLevel = true; 
             // different resolution for the image. 
             var resolutions = [{ "width": 2460, "height": 2970 }, { "width": 1230, "height": 1485 }, { "width": 615, "height": 742 }, { "width": 307, "height": 371 }, { "width": 153, "height": 185 }, { "width": 76, "height": 92 }]; 
             mrtiInfo.resolutions = []; 
             for (var i = 0; i < resolutions.length; i++) { 
                      mrtiInfo.resolutions[i] = lt.LeadSizeD.create(resolutions[i].width, resolutions[i].height); 
             // the image width and height. 
             // the image full size. 
             mrtiInfo.fullSize = lt.LeadSizeD.create(cellFrame.get_width(), cellFrame.get_height()); 
             // now we need the image URL, 
             var imageUri = "https://demo.leadtools.com/MedicalViewerService20/ObjectRetrieveService.svc"; 
             imageUri += "/GetImageTile?auth="; 
             imageUri += authenticationCode; 
             // this the image instance UID, change this if you want to retrieve anything else. 
             imageUri += "&instance="; 
             mrtiInfo.imageUri = imageUri; 
             // set this info to the cell frame. 
             cellFrame.mrtiInfo = mrtiInfo;           
             // now we need to set the information for the image so we can do window level. 
             var imageInfo = new lt.Controls.Medical.DICOMImageInformation(); 
             // set the image width and height. 
             imageInfo.width = 2460; 
             imageInfo.height = 2970; 
             // bits per pixel for the image 
             imageInfo.bitsPerPixel = 16; 
             // low and high bit. 
             imageInfo.lowBit = 0; 
             imageInfo.highBit = 11; 
             // other information, setting some of them to zero means that the toolkit will try and calculate it by itself, but you can always get those values from the DicomDataSet. 
             imageInfo.modalityIntercept = 0; 
             imageInfo.modalitySlope = 1; 
             imageInfo.minValue = 0; 
             imageInfo.maxValue = 0; 
             imageInfo.windowWidth = 0; 
             imageInfo.windowCenter = 0; 
             imageInfo.signed = false; 
             imageInfo.photometricInterpretation = 'MONOCHROME1'; 
             imageInfo.firstStoredPixelValueMapped = 0; 
             // set these information to the frame. 
        // We are trying here to get an image from the Leadtools database, we need to login and get the authentication code. 
        xhttp.open("POST", "https://demo.leadtools.com/MedicalViewerService20/AuthenticationService.svc/AuthenticateUser", true); 
          xhttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); 
           // we log in as a 'guest', after calling the below line, we will receive the authentication code sent via 'onreadystatechange' above. 
        xhttp.send(JSON.stringify({ userName: 'guest', password: 'guest', userData: '' }));      
        // [optional] Add an action that allows the user to move the loaded image using either the mouse or by touch and drag. we are adding an offset action. 
        cell.setCommand(1, new lt.Controls.Medical.OffsetAction()); 
        // [optional] Add an action that allows the user to do window level on the image. 
        cell.setCommand(2, new lt.Controls.Medical.WindowLevelAction()); 
        // [optional] Run the action. Now if the user clicks or touches the image and drags it, the image will move correspondingly. 
        // [optional] Create an overlay text that will appear at the top of the loaded image. 
        var overlay = new lt.Controls.Medical.OverlayText(); 
        // [optional] Set the aligment for the overlay text. 
        // [optional] Set the row index of overlay text. 
        // [optional] add window level overlay text, this will change when you click and drag the mouse. 
        // [optional] Add this overlay to the overlay list of the cell. Currently there is only one overlay, but the user can add multiple overlay texts. 
        alert('-Hold left mouse button and drag to change the image window level \n-Double click to expand the view area \n-Double click again to return to the previous view area.'); 
  4. Launch the page in a browser that supports HTML5 to test it.
Help Version 22.0.2023.1.18
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.


Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.