Top Banner

of 205

IDL Image Processing working with Images in IDL.pdf

Aug 07, 2018

Download

Documents

Ashoka Vanjare
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    1/523

    IDL Version 5.5December, 2001 EditionCopyright © Research Systems, IncAll Rights Reserved

    Working withImages in IDL

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    2/523

    Research Systems, Inc. documentation is printed on recycled paper. Our paper has a minimum20% post-consumer waste content and meets all EPA guidelines.

    Restricted Rights Notice

    The IDL ® software program and the accompanying procedures, functions, anddocumentation described herein are sold under license agreement. Their use,duplication, and disclosure are subject to the restrictions stated in the licenseagreement. Research Systems, Inc., reserves the right to make changes to thisdocument at any time and without notice.

    Limitation of Warranty

    Research Systems, Inc. makes no warranties, either express or implied, as to anymatter not expressly set forth in the license agreement, including without limitationthe condition of the software, merchantability, or fitness for any particular purpose.

    Research Systems, Inc. shall not be liable for any direct, consequential, or otherdamages suffered by the Licensee or any others resulting from use of the IDLsoftware package or its documentation.

    Permission to Reproduce this Manual

    If you are a licensed user of this product, Research Systems, Inc. grants you alimited, nontransferable license to reproduce this particular document providedsuch copies are for your use only and are not sold or distributed to third parties. Allsuch copies must contain the title page and this notice page in their entirety.

    Acknowledgments

    IDL ® is a trademark of Research Systems Inc., registered in the United States Patent and Trademark Office, for thecomputer program described herein.

    Numerical Recipes™ is a trademark of Numerical Recipes Software. Numerical Recipes routines are used byperission.

    GRG2™ is a trademark of Windward Technologies, Inc. The GRG2 software for nonlinear optimization is used bypermission.

    ESRI™ is a trademark of Environmental Systems Research Institute, Inc. ESRI routines are used by permission.

    NCSA Hierarchical Data Format (HDF) Software Library and Utilities Copyright 1988-1998 The Board of Trustees of the University of Illinois All rights reserved.

    Portions of this software are copyrighted by INTERSOLV, Inc., 1991-1998.

    Other trademarks and registered trademarks are the property of the respective trademark holders.

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    3/523

    Working with Images

    ContentsChapter 1:Introduction to Working with Images in IDL ................................What is an Image and How is it Processed? ........................................................Types of Images ................................................................................................... 1

    Binary Images ................................................................................................ 1Grayscale Images ........................................................................................... 1Indexed Images .............................................................................................. 1RGB images ................................................................................................... 1

    Pixel Data Types .................................................................................................. 1Byte ................................................................................................................ 13

    Unsigned Integer ............................................................................................ 1Signed Integer ................................................................................................ 1Unsigned Longword Integer .......................................................................... Longword Integer .......................................................................................... 1

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    4/523

    2

    Contents Working with Images

    Floating-point ................................................................................................. 13Double-precision ............................................................................................ 13

    Accessing Images from a File .............................................................................. 14Querying Images ............................................................................................ 14Importing in Images ....................................................................................... 16Writing out Images ........................................................................................ 18

    Chapter 2:Creating Image Displays ............................................................. 21Overview of Creating Image Displays ................................................................. 22Differentiating Between Graphics Systems ......................................................... 24

    Direct Graphics .............................................................................................. 24Object Graphics ............................................................................................. 24Understanding Windows and Related Device Coordinates ........................... 25

    Creating Direct Graphics Image Displays ........................................................... 27Displaying Binary Images with Direct Graphics ........................................... 27Displaying Grayscale Images with Direct Graphics ...................................... 30Displaying Indexed Images with Direct Graphics ......................................... 32Displaying RGB Images with Direct Graphics .............................................. 36

    Creating Object Graphics Image Displays ........................................................... 41Displaying Binary Images with Object Graphics .......................................... 41Displaying Grayscale Images with Object Graphics ..................................... 44Displaying Indexed Images with Object Graphics ........................................ 47Displaying RGB images with Object Graphics ............................................. 52

    Displaying Multiple Images in a Window ........................................................... 57Displaying Multiple Images in Direct Graphics ............................................ 57Displaying Multiple Images in Object Graphics ........................................... 62

    Zooming in on an Image ...................................................................................... 68

    Zooming in on a Direct Graphics Image Display .......................................... 68Zooming in on a Object Graphics Image Display ......................................... 70

    Panning within an Image ..................................................................................... 74Panning in Direct Graphics ............................................................................ 74

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    5/523

    Working with Images Con

    Panning in Object Graphics ...........................................................................

    Chapter 3:Working with Color ...................................................................... 81Overview of Working with Color ........................................................................

    Color Systems ................................................................................................ 8Color Visuals: PseudoColor Versus TrueColor ............................................How Colors are Associated with Indexed and RGB Images ......................Chapter Overview .......................................................................................... 8

    Loading Pre-defined Color Tables ....................................................................... Modifying and Converting Color Tables .............................................................

    Using the XLOADCT Utility ........................................................................ Using the XPALETTE Utility ..................................................................... 1Using the MODIFYCT Routine .................................................................. 1Converting to Other Color Systems ............................................................. 1

    Converting Between Image Types ..................................................................... 1Converting Indexed Images to RGB Images ............................................... Converting RGB Images to Indexed Images ...............................................

    Highlighting Features with a Color Table ......................................................... 1Highlighting Features with Color in Direct Graphics .................................. Highlighting Features with Color in Object Graphics .................................

    Showing Variations in Uniform Areas .............................................................. 1Showing Variations with Direct Graphics ...................................................

    Applying Color Annotations to Images ............................................................. 1Applying Color Annotations to Indexed Images in Direct Graphics ..........Applying Color Annotations to Indexed Images in Object Graphics .........Applying Color Annotations to RGB Images in Direct Graphics ..............Applying Color Annotations to RGB Images in Object Graphics ..............

    Chapter 4:Transforming Image Geometries .............................................. 161Overview of Geometric Transformations .......................................................... 1Interpolation Methods ........................................................................................ 16

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    6/523

    4

    Contents Working with Images

    Cropping Images ................................................................................................ 166Padding Images .................................................................................................. 170Resizing Images ................................................................................................. 174Shifting Images .................................................................................................. 177Reversing Images ............................................................................................... 180Transposing Images ........................................................................................... 183Rotating Images ................................................................................................. 186

    Rotating an Image by 90 Degree Increments ............................................... 186Using the ROT Function for Arbitrary Rotations ........................................ 189

    Planar Slicing of Volumetric Data ..................................................................... 192Displaying a Series of Planar Slices ............................................................ 192Extracting a Slice of Volumetric Data ......................................................... 196

    Interactive Planar Slicing of Volumetric Data ............................................. 199Displaying Volumetric Data Using SLICER3 ............................................. 199Manipulating Volumetric Data Using SLICER3 ......................................... 200Displaying Volumes Using XVOLUME ..................................................... 204Manipulating Volumetric Data Using XVOLUME ..................................... 205

    Chapter 5:Mapping an Image onto Geometry ........................................... 209Overview of Mapping Images onto Geometric Surfaces ................................... 210Mapping an Image onto Elevation Data ............................................................ 212Mapping an Image onto a Sphere ...................................................................... 221

    Mapping an Image onto a Sphere Using Direct Graphics ........................... 221Mapping an Image onto a Sphere Using Object Graphics ........................... 225

    Chapter 6:Using Mathematics with Images .............................................. 231Overview of Image Mathematics ....................................................................... 232Making Masks .................................................................................................... 234

    Thresholding Images .................................................................................... 234Scaling Images ............................................................................................. 239

    Applying Math Operations to Images ................................................................ 245

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    7/523

    Working with Images Con

    Adding Images ............................................................................................. 24Subtracting Images ...................................................................................... 25Multiplying Images ...................................................................................... 25Dividing Images ........................................................................................... 25

    Working with the Values of Images .................................................................. 2Sorting Values of Images ............................................................................. 2Locating Values of Images .......................................................................... 2Totalling Values of Images .......................................................................... 2

    Chapter 7:Warping Images ......................................................................... 277Overview of Warping Images ............................................................................ 2

    Important Control Point Selection Tips ....................................................... 2Creating Transparent Image Overlays ............................................................... 2Warping Images Using Direct Graphics ............................................................ 2Warping Images Using Object Graphics ........................................................... 2

    Chapter 8:Working with Regions of Interest (ROIs) ................................. 30Overview of Working with ROIs ....................................................................... 3

    Contrasting an ROI ’s Geometric Area and Mask Area ...............................

    Defining Regions of Interest .............................................................................. 3Displaying ROI Objects in a Direct Graphics Window ..................................... Programmatically Defining ROIs and Computing Geometry and Pixel Statistics317Growing a Region .............................................................................................. 32Creating and Displaying an ROI Mask .............................................................. 3Testing an ROI for Point Containment .............................................................. 3Creating a Surface Mesh of an ROI Group ........................................................ 3

    Chapter 9:Transforming Between Image Representations ...................... 3Overview of Transforming Between Image Representations ............................

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    8/523

    6

    Contents Working with Images

    Fast Fourier Transform (FFT) ............................................................................ 347Forward FFT ................................................................................................ 347FFT Power Spectrum ................................................................................... 350Inverse FFT .................................................................................................. 354Removing Noise with FFT .......................................................................... 357

    Hough and Radon Transforms ........................................................................... 362Forward Hough and Radon Transforms ...................................................... 362Hough and Radon Backprojections ............................................................. 365Finding Straight Lines with Hough ............................................................. 368Color Density Contrasting with Radon ........................................................ 375

    Discrete Wavelet Transform .............................................................................. 381Forward Wavelet Transform ........................................................................ 381

    Wavelet Power Spectrum ............................................................................. 384Inverse Wavelet Transform ......................................................................... 388Removing Noise with Wavelet .................................................................... 391

    Chapter 10:Enhancing Contrast and Filtering ............................................ 397Overview of Enhancing Contrast and Filtering Images ..................................... 398Byte-Scaling ....................................................................................................... 399

    Example: Byte-Scaling ................................................................................ 400Working with Histograms .................................................................................. 402

    Equalizing with Histograms ......................................................................... 402Adaptive Equalizing with Histograms ......................................................... 406

    Filtering an Image .............................................................................................. 412Low Pass Filtering ....................................................................................... 412High Pass Filtering ....................................................................................... 415Laplace Filtering .......................................................................................... 418

    Direction Filtering ........................................................................................ 419Removing Noise ................................................................................................ 421

    Windowing to Remove Noise ...................................................................... 421Lee Filtering to Remove Noise .................................................................... 422

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    9/523

    Working with Images Con

    Smoothing an Image .......................................................................................... 42Smoothing with the Average Value ............................................................. 4Smoothing with the Middle Value ............................................................... 4

    Detecting Edges ................................................................................................. 42Enhancing Edges with the Roberts Operator ............................................... Enhancing Edges with the Sobel Operator ..................................................

    Sharpening an Image ......................................................................................... 43

    Chapter 11:Segmenting Images ................................................................... 431Overview of Segmenting Images ....................................................................... 4Plotting Histograms ........................................................................................... 43Plotting Intensity Profiles .................................................................................. 43Probing Pixel Values ......................................................................................... 43Determining Image Statistics ............................................................................. 4

    Chapter 12:Extracting and Analyzing Shapes ............................................ 437Overview of Extracting and Analyzing Image Shapes ......................................

    Applying a Morphological Structuring Element to an Image ......................Guidelines for Determining Structuring Element Shapes and Sizes ................

    Determining Intensity Values When Thresholding and Stretching Images .....Eroding and Dilating Image Objects ................................................................. 4

    Characteristics of Erosion ............................................................................ 4Characteristics of Dilation ........................................................................... 4Applying Erosion and Dilation .................................................................... 4

    Smoothing Images with MORPH_OPEN .......................................................... 4Smoothing Images with MORPH_CLOSE ....................................................... 4Detecting Peaks of Brightness ........................................................................... 4Creating Image Object Boundaries .................................................................... 4Selecting Specific Image Objects ...................................................................... 4Detecting Edges of Image Objects ..................................................................... 4Creating Distance Maps ..................................................................................... 48

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    10/523

    8

    Contents Working with Images

    Thinning Image Objects ..................................................................................... 484Combining Morphological Operations .............................................................. 492Analyzing Image Shapes ................................................................................... 498

    Using LABEL_REGION to Extract Image Object Information ................. 498Using CONTOUR to Extract Image Object Information ............................ 504

    Chapter 13:Printing Images .......................................................................... 509Printing ............................................................................................................... 510

    Printing an Image ......................................................................................... 510

    Chapter 14:Animating Images ...................................................................... 511

    Appendix A:Glossary ..................................................................................... 513

    key value ...................................................................................................... 514

    Index ........................................................................................... 519

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    11/523

    Working with Images

    Chapter 1:

    Introduction to Workingwith Images in IDLThis chapter describes the following topics:

    What is an Image and How is it Processed? 10Types of Images . . . . . . . . . . . . . . . . . . . . . 11

    Pixel Data Types . . . . . . . . . . . . . . . . . Accessing Images from a File . . . . . . . .

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    12/523

    10 Chapter 1: Introduction to Working with Images in IDL

    What is an Image and How is it Processed? Working with Images

    What is an Image and How is it Processed?

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    13/523

    Chapter 1: Introduction to Working with Images in IDL

    Working with Images Types of Im

    Types of Images

    Binary, grayscale, and indexed images are two-dimensional arrays. The type of imais determined by its contents and how it may relate to a color table.

    Binary ImagesBinary images only contain two different values (off or on). The off value is usuallzero and the on value is usually a one. This type of image is commonly used asmultiplier to mask regions within another image. Zero times anything is zero, onetimes anything is itself.

    Grayscale Images

    Grayscale images represent intensities. A pixel within a grayscale image is moreintense the closer it is to white. Less intense pixels are closer to black. Grayscaleimages usually range from 0 to 255. If intensity values have a greater range, the dvalues are usually scaled to range between 0 to 255 to display the image.

    Indexed Images

    Instead of intensities, a pixel within an indexed image relates to a color within a taof up to 256 colors. The value of a pixel determines the index of a color within thimage ’s related color table. A color within the table is defined by the amount of eprimary color (red, green, and blue) within it.

    The amount of each primary color is known as a color triple. In IDL, the amount red, green, or blue range from 0 to 255. If a pixel is represented by a (0, 0, 0) triplis black. If a pixel is represented by a (255, 255, 255) triple, it is white.

    The color table contains triples for each pixel value (index) for up to 256 colors. Tthree primary colors of the table are known as color components. These componenare usually associated with their related color. For example, the red componentcontains the red values of the color table for the index of the pixels within the ima

    Grayscale and binary images can actually be treated as indexed images a grayscale(black and white) color table. Since indexed images reference color tables of up to256 colors, the data values of these images are usually scaled to range between 0 a255.

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    14/523

    12 Chapter 1: Introduction to Working with Images in IDL

    Types of Images Working with Images

    RGB images

    RGB images are three-dimensional arrays. Two of the three-dimensions specify thelocation of a pixel within the image. The other dimensions are used to specify thecolor of each pixel. A color can be defined by the amount of each primary color (red,green, and blue) within it.

    The amount of each primary color is known as a color triple. In IDL, the amount of red, green, or blue range from 0 to 255. If a pixel is represented by a (0, 0, 0) triple, itis black. If a pixel is represented by a (255, 255, 255) triple, it is white.

    The combination of the location dimensions and the color dimension is known asinterleaving. The color dimension will always have a size of 3. The three parts of thecolor dimension are usually referred to as color bands or channels. These bands arealso usually associated with their related color. For example, the red band (channel)contains the red values of the color triple of the pizels within the image.

    The location dimensions will be the size of the height, h, and the width, w, of theimage. The type of interleaving depends on the arrangement of these dimensions.

    Pixel Interleaving

    The color bands (channels) are in the first dimension. The pixel locations are after thecolor bands. In other words, the dimensions are arranged (3, w, h).

    Line Interleaving

    The color bands (channels) are in the second dimension. The pixel locations areseparated by the color bands. In other words, the dimensions are arranged (w, 3, h).

    Image InterleavingThe color bands (channels) are in the third (last) dimension. The pixel locations arebefore the color bands. In other words, the dimensions are arranged (w, h, 3).

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    15/523

    Chapter 1: Introduction to Working with Images in IDL

    Working with Images Pixel Data T

    Pixel Data Types

    Byte

    Unsigned Integer

    Signed Integer

    Unsigned Longword Integer

    Longword Integer

    Floating-point

    Double-precision

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    16/523

    14 Chapter 1: Introduction to Working with Images in IDL

    Accessing Images from a File Working with Images

    Accessing Images from a File

    Images are usually contained within binary files. These files may have headers.Headers appear at the beginning of a file to provide information about the data withinthe file. Some files have headers arranged in a specific format. These files arecommon image such as JPEG, PNG, DICOM, TIFF, etc. Images are not commonlystored in ASCII text files.

    Querying Images

    Unformatted binary files are usually referred to as just binary files. Accessing thesefiles require given information about the data within the file such as dimension sizes,data arrangement, and data type. Binary files are not queried because they are do notconform to any format standard.

    Formatted binary files with headers are usually referred to as image files. Since thesefiles contain information about the file within its header and the header conforms to astandard, these files can be queried. IDL provides the QUERY_IMAGE function toquery any image file supported within IDL.

    For example, the mineral.png file is an image file within the examples/datadirectory. You can query this image with the QUERY_IMAGE function, whichrequires the path to the file as an argument. The path to the file can be determinedwith the FILEPATH function:

    file = FILEPATH(’mineral.png’, $SUBDIRECTORY = [’examples’, ’data’])

    Now, you can use the QUERY_IMAGE function to query the image:

    query = QUERY_IMAGE(file, info)

    The query variable contains the result of the query. If query is zero, the file cannot beaccessed with IDL. If query is one, the file can be accessed with IDL. To determinethe results of uses the QUERY_IMAGE function, you can print the value of the queryvariable:

    PRINT, ’query = ’, query

    IDL should display the following text in the Output Log:

    query = 1

    The mineral.png file can be accessed with IDL. Moreover, the info variable is nowan IDL structure containing important parameters about the image file. The tagsassociated with this structure variable are standard with any image file. You can see

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    17/523

    Chapter 1: Introduction to Working with Images in IDL

    Working with Images Accessing Images from a

    the tags of this structure by setting the STRUCTURE keyword to the HELPcommand with the info variable as its argument:

    HELP, info, /STRUCTURE

    IDL should display the following text in the Output Log:

    ** Structure , 7 tags, length=36, refs=1:CHANNELS LONG 1DIMENSIONS LONG Array[2]HAS_PALETTE INT 1IMAGE_INDEX LONG 0NUM_IMAGES LONG 1PIXEL_TYPE INT 1TYPE STRING ’ PNG ’

    The channels tag is either 1 or 3. If channels is 1, the image is a two-dimensionalarray. If channels is 3, the image is a three-dimensional array. The dimensions tagcontains the width and height of the image. The has_palette tag is a logic setting.

    has_palette is 0, the image does not have an associated color palette (color table). has_palette is 1, the image has an associated color palette (color table). Theimage_index and num_images shows if the file contains multiple images and whicone of these images is current. The pixel_type tag shows the data type of the valuewithin the image. The value of this tag relates to the data type as shown in thefollowing table.

    Type Code Data Type

    0 Undefined

    1 Byte2 Integer

    3 Longword integer

    4 Floating point

    5 Double-precision floating

    6 Complex floating

    7 String

    8 Structure9 Double-precision complex

    Table 1-1: IDL Type Codes

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    18/523

    16 Chapter 1: Introduction to Working with Images in IDL

    Accessing Images from a File Working with Images

    The type tag specifies the type of image file containing the image.

    From the output results of the info variable, the single image within themineral.png PNG file is an indexed image because it has only one channel (is atwo-dimensional array) and it has a color palette. The image also has byte data typevalues. You can determine the size of the image by using the values within theDIMENSIONS tag:

    PRINT, ’ Size: ’ , info.dimensions

    IDL should display the following text in the Output Log:

    Size: 288 216

    IDL also provides query functions for each individual image file types:

    These functions have the same syntax and useage as the QUERY_IMAGE function.

    Importing in Images

    Images in binary files (unformatted binary files) can be imported with theREAD_BINARY function and its DATA_DIMS and DATA_TYPE keywords. Youcan specify the size of the image within the file with the DATA_DIMS keyword. Youcan specify the data type of the image with the DATA_TYPE keyword. TheDATA_TYPE keyword is set to the type codes in the previous table. However, most

    10 Pointer

    11 Object reference

    12 Unsigned Integer

    13 Unsigned Longword Integer

    14 64-bit Integer

    15 Unsigned 64-bit Integer

    • QUERY_BMP • QUERY_PICT • QUERY_SRF

    • QUERY_DICOM • QUERY_PNG • QUERY_TIFF

    • QUERY_JPEG • QUERY_PPM

    Type Code Data Type

    Table 1-1: IDL Type Codes

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    19/523

    Chapter 1: Introduction to Working with Images in IDL

    Working with Images Accessing Images from a

    images in binary files are of the byte data type, which is the default setting for theDATA_TYPE keyword. Thus, in most cases, you do not have to set the DATA_TYPkeyword. For images in binary files, the DATA_DIMS keyword is required becausthe READ_BINARY function assumes the data values are arranged in a single vec(a one-dimensional array). The DATA_DIMS keyword is used to specify a two- orthree-dimensional array.

    The parameters of an image within a binary file are not usually provided within thfile. If the parameters are provided within the file, they are definitely not provideda standard method. Thus, the owner of the file should already known the parameteof the image within a binary file.

    For example, the worldelv.dat file is a binary file, which contains an image. Ycan only import this image by knowing that the data values of the image are byte athe image has a width of 360 pixels by 360 pixels. Before using the READ_BINARfunction to access this image, you must determine the path to this file.

    file = FILEPATH( ’ worlelv.dat ’ , $SUNDIRECTORY = [ ’ examples ’ , ’ data ’ ])

    And you should define the parameters of the image.

    imageSize = [360, 360]

    n image type parameter is not required because the data values of image are byte,which is the default type for the READ_BINARY function.

    The READ_BINARY function can now be used to import the image within theworldelv.dat file.

    image = READ_BINARY(file, DATA_DIMS = imageSize)

    Images in image files (formatted binary with standardize headers) can be importedwith the READ_IMAGE function. The READ_IMAGE function actually determinwhich type of image file is being accessed so you do not have to specify the file ty just as long as the image file type is supported within IDL. The READ_IMAGEfunction only requires the path to the file to import the file ’s image. TheREAD_IMAGE function also provides output arguments for red, green, and bluecolor table components if available. You can use the QUERY_IMAGE function todetermine the parameters of an image within a file.

    For example, the rose.jpg file is an image file, which contains a RGB image. Ycan import this image with the READ_IMAGE function. Befire using theREAD_IMAGE function, you must determine the path to this file.

    file = FILEPATH( ’ rose.jpg ’ , $SUBDIRECTORY = [ ’ examples ’ , ’ data ’ ])

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    20/523

    18 Chapter 1: Introduction to Working with Images in IDL

    Accessing Images from a File Working with Images

    Now you can use the READ_IMAGE function to import the image.

    image = READ_IMAGE(file)

    IDL also provides read routines for each individual image file types:

    These routines are similar to the READ_IMAGE function, but provide more detailsfor importing a specific image file if required.

    Writing out Images

    Images in binary files (unformatted binary files) can be exported with the WRITEU

    procedure. Before using the WRITEU procedure, you must open a file for writing.You can open a file for writing with the OPENW procedure. However, if you open afile, you must remember to close it with either the FREE_LUN or CLOSE procedurewhen you are done exporting the image.

    For example, you can again import the image from the rose.jpg image file.

    file = FILEPATH( ’ rose.jpg ’ , $SUBDIRECTORY = [ ’ examples ’ , ’ data ’ ])

    image = READ_IMAGE(file)

    Then you can export this image to a binary file by first opening a file for writing.

    OPENW, unit, ’ rose.dat ’ , /GET_LUN

    Now you can use the WRITEU procedure to write the image to the open file.

    WRITEU, unit, image

    You should always remember to close open files when you are done with them.

    FREE_LUN, unit

    Images in image files (formatted binary with standardize headers) can be exportedwith the WRITE_IMAGE procedure. The WRITE_IMAGE procedure requires threeinputs: the exported file ’s name, the image file type, and the image itself. You canalso provide the red, green, and blue color components to an associated color table if these components exists.

    For example, you can again import the image from the worldelv.dat binary file.

    file = FILEPATH( ’ worlelv.dat ’ , $

    • READ_BMP • READ_JPEG • READ_PPM

    • READ_DICOM • READ_PICT • READ_SRF

    • READ_INTERFILE • READ_PNG • READ_TIFF

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    21/523

    Chapter 1: Introduction to Working with Images in IDL

    Working with Images Accessing Images from a

    SUNDIRECTORY = [ ’ examples ’ , ’ data ’ ])imageSize = [360, 360]image = READ_BINARY(file, DATA_DIMS = imageSize)

    Then you can export this image to an image file (a JPEG file) with theWRITE_IMAGE procedure.

    WRITE_IMAGE, ’ worldelv.dat ’ , ’ JPEG ’ , image

    IDL also provides write routines for each individual image file types:

    These routines are similar to the WRITE_IMAGE procedure, but provide moredetails for exporting a specific image file if required.

    • READ_BMP • READ_JPEG • READ_PPM

    • READ_DICOM • READ_PICT • READ_SRF

    • READ_INTERFILE • READ_PNG • READ_TIFF

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    22/523

    20 Chapter 1: Introduction to Working with Images in IDL

    Accessing Images from a File Working with Images

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    23/523

    Working with Images

    Chapter 2:

    Creating ImageDisplaysThis chapter describes the following topics:

    Overview of Creating Image Displays . . . . 22Differentiating Between Graphics Systems 24Creating Direct Graphics Image Displays . 27Creating Object Graphics Image Displays . 41

    Displaying Multiple Images in a WindowZooming in on an Image . . . . . . . . . . . .Panning within an Image . . . . . . . . . . . .

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    24/523

    22 Chapter 2: Creating Image Displays

    Overview of Creating Image Displays Working with Images

    Overview of Creating Image Displays

    To understand how to display an image, you must understand IDL ’s graphics systems,window coordinate systems, and the types of images you can display. IDL has twotypes of graphics systems, Direct and Object. Direct Graphics displays directly to awindow. Object Graphics uses object-oriented programming to display withininstances of window objects. For more information, see “Differentiating BetweenGraphics Systems ” on page 24

    One of IDL’s three window coordinate systems controls the placement of the imagewithin Direct and Object Graphics displays. These window coordinate systems aredata, device, and normalized. Data coordinates are the same as device coordinates forimages. Device coordinates are based on the pixel locations of an image. Normalizedcoordinates range from zero and one and are based on the width and height of theimage. See “Understanding Windows and Related Device Coordinates ” on page 25

    for more information.IDL can display four types of images; binary, grayscale, indexed, and RGB. IDLtreats binary and grayscale images as a subsets of indexed images. How the image isdisplayed depends on its type. Binary images have only two values, 0 and 1.Grayscale images represent intensities and use a normal grayscale color table.Indexed images use an associated color table. RGB images contain their own colorinformation in layers known as bands or channels.Any of these images can bedisplayed with Direct Graphics, see “Creating Direct Graphics Image Displays ” onpage 27, or Object Graphics, see “Creating Object Graphics Image Displays ” onpage 41.

    Multiple images can also be displayed in the same. The location of the imagesdepends on the window coordinate system. For more information, see “DisplayingMultiple Images in a Window ” on page 57.

    You can magnify specific areas of an image by changing the display show just thatregion. This magnification is known as zooming in on the image. By zooming in onan area, you can visualize each pixel that make up a feature or a boundary. See“Zooming in on an Image ” on page 68 for more information.

    When you zoom in on a feature within an image, you may want to move along thefeature at that magnification. The movement is known as panning. For moreinformation on panning, see “Panning within an Image ” on page 74.

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    25/523

    Chapter 2: Creating Image Displays

    Working with Images Overview of Creating Image Displ

    The following list introduces image display tasks and associated IDL imageprocessing routines covered in this chapter.

    NoteThis chapter uses data files from the IDL x.x /examples/data directory. Twfiles, data.txt and index.txt , contain descriptions of the files, including arsizes.

    Task Routine(s) Description

    “CreatingDirectGraphicsImageDisplays ” onpage 27 .

    TV

    TVSCL

    Display binary, grayscale, indexed, anRGB images using the Direct Graphicsystem.

    “CreatingObjectGraphicsImageDisplays ” onpage 41

    IDLgrImage

    IDLgrPalette

    Display binary, grayscale, indexed, anRGB images using the Object Graphicsystem.

    “DisplayingMultipleImages in aWindow ” onpage 57 .

    TV

    TVSCL

    IDLgrImage

    Display multiple images in a singleDirect Graphics and Object Graphicswindow.

    “Zooming inon an Image ”on page 68 .

    ZOOM

    ZOOM_24

    IDLgrImageIDLgrView

    Magnify specific areas of an image usDirect and Object Graphics.

    “Panningwithin anImage ” onpage 74 .

    SLIDE_IMAGE

    IDLgrImage

    IDLgrView

    Zoom in on specific areas of an imagand then move to another area within image using Direct and Object Graphi

    Table 2-1: Image Display Tasks and Related Image Display Routines.

    http://reference/T.pdfhttp://reference/T.pdfhttp://reference/objects.pdfhttp://reference/objects.pdfhttp://reference/T.pdfhttp://reference/T.pdfhttp://reference/objects.pdfhttp://reference/Z.pdfhttp://reference/Z.pdfhttp://reference/objects.pdfhttp://reference/objects.pdfhttp://reference/S.pdfhttp://reference/objects.pdfhttp://reference/objects.pdfhttp://reference/objects.pdfhttp://reference/objects.pdfhttp://reference/objects.pdfhttp://reference/objects.pdfhttp://reference/objects.pdfhttp://reference/objects.pdfhttp://reference/objects.pdfhttp://reference/S.pdfhttp://reference/Z.pdfhttp://reference/Z.pdfhttp://reference/T.pdfhttp://reference/T.pdfhttp://reference/T.pdfhttp://reference/T.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    26/523

    24 Chapter 2: Creating Image Displays

    Differentiating Between Graphics Systems Working with Images

    Differentiating Between Graphics Systems

    IDL supports two distinct graphics modes: Direct Graphics and Object Graphics.Direct Graphics rely on the concept of a current graphics device; IDL commands likeTV or PLOT create displays directly on the current graphics device. Object Graphicsuse an object-oriented programmer ’ interface to create graphic objects, which mustthen be drawn, explicitly, to a destination of the programmer ’s choosing.

    Direct Graphics

    The important aspects of Direct Graphics are:

    • Direct Graphics use a graphics device ( X for X-windows systems displays,WIN for Microsoft Windows displays, MAC for Macintosh displays, PS forPostScript files, etc.). You switch between graphics devices using theSET_PLOT command, and control the features of the current graphics deviceusing the DEVICE command.

    • Commands like TV, PLOT, XYOUTS, MAP_SET, etc. all draw their outputdirectly on the current graphics device.

    • Once a direct-mode graphic is drawn to the graphics device, it cannot bealtered or re-used. This means that if you wish to recreate the graphic on adifferent device, you must reissue the IDL commands to create the graphic.

    • When you add a new item to an existing direct-mode graphic (using a routinelike OPLOT or XYOUTS), the new item is drawn in front of the existing

    items.Object Graphics

    The important aspects of Object Graphics are:

    • Object graphics are device independent. There is no concept of a currentgraphics device when using object-mode graphics; any graphics object can bedisplayed on any physical device for which a destination object can be created.

    • Object graphics are object-oriented. Graphic objects are meant to be createdand reused; you may create a set of graphic objects, modify their attributes,draw them to a window on your computer screen, modify their attributes again,then draw them to a printer device without reissuing all of the IDL commandsused to create the objects. Graphics objects also encapsulate functionality; thismeans that individual objects include method routines that providefunctionality specific to the individual object.

    http://reference/S.pdfhttp://reference/D.pdfhttp://reference/S.pdfhttp://reference/D.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    27/523

    Chapter 2: Creating Image Displays

    Working with Images Differentiating Between Graphics System

    • Object graphics are rendered in three dimensions. Rendering implies manyoperations not needed when drawing Direct Graphics, including calculation normal vectors for lines and surfaces, lighting considerations, and generalobject overhead. As a result, the time needed to render a given object —asurface, say — will often be longer than the time taken to draw the analogouimage in Direct Graphics.

    • Object Graphics use a programmer ’s interface. Unlike Direct Graphics, whare well suited for both programming and interactive, ad hoc use, ObjectGraphics are designed to be used in programs that are compiled and run. Whit is still possible to create and use graphics objects directly from the IDLcommand line, the syntax and naming conventions make it more convenientbuild a program offline than to create graphics objects on the fly.

    • Because Object Graphics persist in memory, there is a greater need for theprogrammer to be cognizant of memory issues and memory leakage. Efficiedesign — remembering to destroy unused object references and cleaning up

    will avert most problems, but even the best designs can be memory-intensivlarge numbers of graphic objects (or large datasets) are involved.

    Understanding Windows and Related Device Coordinates

    Images are displayed within a window (Direct Graphics) or within an instance of awindow object (Object Graphics). In Direct Graphics, the WINDOW procedure isused to initialize the coordinates system for the image display. In Object Graphics,the IDLgrWindow, IDLgrView, and IDLgrModel objects are used to initialize thecoordinate system for the image display.

    A coordinate system determines how and where the image appears within thewindow. You can specify coordinates to IDL using one of the following coordinatesystems:

    • Data Coordinates - This system usually spans the window with a rangeidentical to the range of the data. The system can have two or three dimensiand can be linear, logarithmic, or semi-logarithmic.

    • Device Coordinates - This coordinate system is the physical coordinate systof the selected device. Device coordinates are integers, ranging from (0, 0) the bottom-left corner to ( V x –1, V y –1) at the upper-right corner of the disp

    V x and V y are the number of columns and rows of the device (a display windfor example).

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    28/523

    26 Chapter 2: Creating Image Displays

    Differentiating Between Graphics Systems Working with Images

    NoteFor images, the data coordinates are the same as the device coordinates. Thedevices coordinates of an image are directly related to the pixel (data) locationswithin an image.

    • Normal Coordinates - The normalized coordinate system ranges from zero toone over columns and rows of the device.

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    29/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Direct Graphics Image Displa

    Creating Direct Graphics Image Displays

    The procedure used to display an image in Direct Graphics depends upon the typeimage to be displayed. Binary, grayscale, and indexed images are two-dimensionalarrays. In Direct Graphics, these images are displayed with the TV or TVSCLprocedures. The TV procedure displays the image in its original form. The TVSCLprocedure displays the image scaled to range from 0 up to 255 depending on thecolors available to IDL. Three dimensional RGB images are displayed with the TVprocedure.

    Examples of creating such displays are shown in the following sections:

    • “Displaying Binary Images with Direct Graphics ”.

    • “Displaying Grayscale Images with Direct Graphics ” on page 30.

    • “Displaying Indexed Images with Direct Graphics ” on page 32.

    • “Displaying RGB Images with Direct Graphics ” on page 36.

    Displaying Binary Images with Direct Graphics

    Binary images are composed of pixels having one of two values, usually zero or onWith most color tables, pixels having values of zero or one are displayed with almothe same color, especially with a normal grayscale color table. Thus, a binary imagis usually shown in a scaled display to show the zeros as black and the ones as wh

    The following example imports a binary image of the world from the

    continent_mask.dat binary file. In this image, the oceans are zeros (black) athe continents are ones (white). This type of image can be used to mask out (omit)data over the oceans. The image contains byte data values and is 360 pixels by 36pixels.

    For code that you can copy and paste into an Editor window, see “Example CodDisplaying Binary Images with Direct Graphics ” on page 29 or complete thefollowing steps for a detailed description of the process.

    1. Determine the path to the continent_mask.dat file:

    file = FILEPATH('continent_mask.dat', $

    SUBDIRECTORY = ['examples', 'data'])

    2. Initialize the image size parameter:

    imageSize = [360, 360]

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    30/523

    28 Chapter 2: Creating Image Displays

    Creating Direct Graphics Image Displays Working with Images

    3. Use READ_BINARY to import the image from the file:

    image = READ_BINARY(file, DATA_DIMS = imageSize)

    4. If you are running IDL on a TrueColor display, set the DECOMPOSEDkeyword to the DEVICE command to zero before your first color table relatedroutine is used within an IDL session or program. See “How Colors areAssociated with Indexed and RGB Images ” on page 84 for more information.DEVICE, DECOMPOSED = 0

    5. Load a grayscale color table:

    LOADCT, 0

    6. Create a window and display the original image with the TV procedure:

    WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $TITLE = 'A Binary Image, Not Scaled'

    TV, image

    The resulting window should be all black (blank). The binary image containszeros and ones, which are almost the same color (black). Binary images shouldbe displayed with the TVSCL procedure in order to scale the ones to white.

    7. Create another window and display the scaled binary image:

    WINDOW, 1, XSIZE = imageSize[0], YSIZE = imageSize[1], $TITLE = 'A Binary Image, Scaled'

    TVSCL, image

    http://reference/R.pdfhttp://reference/R.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    31/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Direct Graphics Image Displa

    The following figure shows the results of scaling this display.

    Example Code: Displaying Binary Images with Direct Graphics

    Copy and paste the following text into the IDL Editor window. After saving the fias DisplayBinaryImage_Direct.pro , compile and run the program toreproduce the previous example.

    PRO DisplayBinaryImage_Direct

    ; Determine the path to the file:file = FILEPATH('continent_mask.dat', $

    SUBDIRECTORY = ['examples', 'data'])

    ; Initialize the image size parameter.imageSize = [360, 360]

    ; Import in the image from the file.image = READ_BINARY(file, DATA_DIMS = imageSize)

    ; Initialize the display,DEVICE, DECOMPOSED = 0LOADCT, 0

    ; Create a window and display the original image.WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $

    Figure 2-1: Binary Image in Direct Graphics

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    32/523

    30 Chapter 2: Creating Image Displays

    Creating Direct Graphics Image Displays Working with Images

    TITLE = 'A Binary Image, Not Scaled'TV, image

    ; Create another window and display the image scaled; to range from 0 up to 255.WINDOW, 1, XSIZE = imageSize[0], YSIZE = imageSize[1], $

    TITLE = 'A Binary Image, Scaled'

    TVSCL, image

    END

    Displaying Grayscale Images with Direct Graphics

    Features within grayscale images are created by pixels that have varying intensities.Pixel values range from least intense (black) to the most instance (white). Since agrayscale image is composed of pixels of varying intensities, it is best displayed witha color table that progresses linearly from black to white. Although IDL has several

    such predefined color tables, the grayscale color table (B-W LINEAR), is the mostfitting choice when displaying grayscale images.

    The following example imports a grayscale image from the convec.dat binary file.This grayscale image shows the convection of the Earth ’s mantle. The image containsbyte data values and is 248 pixels by 248 pixels. Since the data type is byte, thisimage does not need to by scaled before display. If the data was of any type other thanbyte and the data values were not within the range of 0 up to 255, the display wouldneed to scale the image in order to show its intensities.

    For code that you can copy and paste into an Editor window, see “Example Code:

    Displaying Grayscale Images with Direct Graphics ” on page 31 or complete thefollowing steps for a detailed description of the process.

    1. Determine the path to the convec.dat file:

    file = FILEPATH('convec.dat', $SUBDIRECTORY = ['examples', 'data'])

    2. Initialize the image size parameter:

    imageSize = [248, 248]

    3. Using READ_BINARY , import the image from the file:

    image = READ_BINARY(file, DATA_DIMS = imageSize)

    http://reference/R.pdfhttp://reference/R.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    33/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Direct Graphics Image Displa

    4. If you are running IDL on a TrueColor display, set the DECOMPOSEDkeyword to the DEVICE command to zero before your first color table relatroutine is used within an IDL session or program. See “How Colors areAssociated with Indexed and RGB Images ” on page 84 for more informat

    DEVICE, DECOMPOSED = 0

    5. Load a grayscale color table:LOADCT, 0

    6. Create a window and display the original image with the TV procedure:

    WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $TITLE = 'A Grayscale Image'

    TV, image

    The following figure shows the resulting grayscale image display.

    Example Code: Displaying Grayscale Images with Direct Graphics

    Copy and paste the following text into the IDL Editor window. After saving the fias DisplayGrayscaleImage_Direct.pro , compile and run the program toreproduce the previous example.

    PRO DisplayGrayscaleImage_Direct

    ; Determine the path to the file.file = FILEPATH('convec.dat', $

    SUBDIRECTORY = ['examples', 'data'])

    ; Initialize the image size parameter.

    Figure 2-2: Grayscale Image in Direct Graphics

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    34/523

    32 Chapter 2: Creating Image Displays

    Creating Direct Graphics Image Displays Working with Images

    imageSize = [248, 248]

    ; Import in the image from the file.image = READ_BINARY(file, DATA_DIMS = imageSize)

    ; Initialize the display.DEVICE, DECOMPOSED = 0

    LOADCT, 0

    ; Create a window and display the image.WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $

    TITLE = 'A Grayscale Image'TV, image

    END

    Displaying Indexed Images with Direct Graphics

    An indexed image contains up to 256 colors, typically defined by a color tableassociated with the image. The value of each pixel relates to a color within theassociated color table. Combinations of the primary colors (red, green, and blue)make up the colors within the color table. Indexed images are usually stored in imagefiles, instead of binary files, since they typically contain related color information (anassociated color table). You can query an image file to determine if it contains anindexed image.

    The following example imports an indexed image from the avhrr.png image file.This indexed image is a satellite photograph of the world. Most indexed images range

    in value from 0 up to 255 because of the range of the associated color table.Therefore, most indexed images do not require scaled displays.

    For code that you can copy and paste into an Editor window, see “Example Code:Displaying Indexed Images with Direct Graphics ” on page 35 or complete thefollowing steps for a detailed description of the process.

    1. Determine the path to the avhrr.png file:

    file = FILEPATH('avhrr.png', $SUBDIRECTORY = ['examples', 'data'])

    2. Use QUERY_IMAGE to query the file to determine image parameters:

    queryStatus = QUERY_IMAGE(file, imageInfo)

    http://reference/Q.pdfhttp://reference/Q.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    35/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Direct Graphics Image Displa

    3. Output the results of the file query:

    PRINT, 'Query Status = ', queryStatusHELP, imageInfo, /STRUCTURE

    The following text appears in the Output Log:

    Query Status = 1** Structure , 7 tags, length=36, refs=1:

    CHANNELS LONG 1DIMENSIONS LONG Array[2]HAS_PALETTE INT 1IMAGE_INDEX LONG 0NUM_IMAGES LONG 1PIXEL_TYPE INT 1TYPE STRING 'PNG'

    4. Set the image size parameter from the query information:

    imageSize = imageInfo.dimensions

    The HAS_PALETTE tag has a value of 1. Thus, the image has a palette (cotable), which is also contained within the file. The color table is made up ofthree primary components (the red component, the green component, and thblue component).

    5. Use READ_IMAGE to import the image and its associated color table frothe file:

    image = READ_IMAGE(file, red, green, blue)

    6. If you are running IDL on a TrueColor display, set the DECOMPOSED

    keyword to the DEVICE command to zero before your first color table relatroutine is used within an IDL session or program. See “How Colors areAssociated with Indexed and RGB Images ” on page 84 for more informat

    DEVICE, DECOMPOSED = 0

    7. Load the red, green, and blue components of the image ’s associated colortable:

    TVLCT, red, green, blue

    8. Create a window and display the original image with the TV procedure:

    WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $TITLE = 'An Indexed Image'

    TV, image

    http://reference/R.pdfhttp://reference/R.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    36/523

    34 Chapter 2: Creating Image Displays

    Creating Direct Graphics Image Displays Working with Images

    9. Use the XLOADCT utility to display the associated color table:

    XLOADCT

    Click on the Done button of XLOADCT to exit out of the utility.

    The following figure shows the resulting indexed image and its color table.

    The data values within the image are indexed to specific colors within the

    table. You can change the color table associated with this image to show howan indexed images is dependent upon its related color table.

    10. Change the current color table to the EOS B pre-defined color table:

    LOADCT, 27

    11. Redisplay the image to show the color table change:

    TV, image

    NoteThis step is not always necessary to redisplay the image. On some computers, thedisplay will update automatically when the current color table is changed.

    Figure 2-3: Indexed Image and Associated Color Table in Direct Graphics

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    37/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Direct Graphics Image Displa

    12. Use the XLOADCT utility to display the current color table:

    XLOADCT

    Click on the Done button of XLOADCT to exit out of the utility.

    The following figure shows the indexed image with the EOS B color table.

    Example Code: Displaying Indexed Images with Direct Graphics

    Copy and paste the following text into the IDL Editor window. After saving the fias DisplayIndexedImage_Direct.pro , compile and run the program toreproduce the previous example. The BLOCK keyword is set when using theXLOADCT utility to force the example routine to wait until the Done button ispressed to continue.

    PRO DisplayIndexedImage_Direct

    ; Determine the path to the file.file = FILEPATH('avhrr.png', $

    SUBDIRECTORY = ['examples', 'data'])

    ; Query the file to determine image parameters.queryStatus = QUERY_IMAGE(file, imageInfo)

    ; Output the results of the file query.

    Figure 2-4: Indexed Image and EOS B Color Table in Direct Graphics

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    38/523

    36 Chapter 2: Creating Image Displays

    Creating Direct Graphics Image Displays Working with Images

    PRINT, 'Query Status = ', queryStatusHELP, imageInfo, /STRUCTURE

    ; Set image size parameter.imageSize = imageInfo.dimensions

    ; Import in the image and its associated color table

    ; from the file.image = READ_IMAGE(file, red, green, blue)

    ; Initialize the display.DEVICE, DECOMPOSED = 0TVLCT, red, green, blue

    ; Create a window and display the image.WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $

    TITLE = 'An Indexed Image'TV, image

    ; Use the XLOADCT utility to display the color table.XLOADCT, /BLOCK

    ; Change the color table to the EOS B pre-defined color; table.LOADCT, 27

    ; Redisplay the image with the EOS B color table.TV, image

    ; Use the XLOADCT utility to display the current color; table.

    XLOADCT, /BLOCK

    END

    Displaying RGB Images with Direct Graphics

    RGB images are three-dimensional arrays made up of width, height, and threechannels of color information. In Direct Graphics, these images are displayed withthe TV procedure. The TRUE keyword to TV is set according to the interleaving of the RGB image. With RGB images, the interleaving, or arrangement of the channels

    within the image file, dictates the setting of the TRUE keyword. If the image is:• pixel interleaved (3, w, h), TRUE is set to 1.

    • line interleaved (w, 3, h), TRUE is set to 2.

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    39/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Direct Graphics Image Displa

    • image interleaved (w, h, 3), TRUE is set to 3.

    You can determine if an image file contains an RGB image by querying the file. TCHANNELS tag of the resulting query structure will equal 3 if the file ’s image RGB. The query does not determine which interleaving is used in the image, but tarray returned in DIMENSIONS tag of the query structure can be used to determin

    the type of interleaving.Unlike indexed images (two dimensional arrays with an associated color table), RGimages contain their own color information. However, if you are using a PseudoCodisplay, your RGB images must be converted to indexed images to be displayedwithin IDL. See “How Colors are Associated with Indexed and RGB Images ” opage 84 for more information on RGB images and PseudoColor displays.

    The following example queries and imports a pixel-interleaved RGB image from trose.jpg image file. This RGB image is a close-up photograph of a red rose. It pixel interleaved.

    For code that you can copy and paste into an Editor window, see “Example CodDisplaying RGB Images with Direct Graphics ” on page 39 or complete the followsteps for a detailed description of the process.

    1. Determine the path to the rose.jpg file:

    file = FILEPATH('rose.jpg', $SUBDIRECTORY = ['examples', 'data'])

    2. Use QUERY_IMAGE to query the file to determine image parameters:

    queryStatus = QUERY_IMAGE(file, imageInfo)

    3. Output the results of the file query:

    PRINT, 'Query Status = ', queryStatusHELP, imageInfo, /STRUCTURE

    The following text appears in the Output Log:

    Query Status = 1** Structure , 7 tags, length=36, refs=1:

    CHANNELS LONG 3DIMENSIONS LONG Array[2]HAS_PALETTE INT 0IMAGE_INDEX LONG 0NUM_IMAGES LONG 1PIXEL_TYPE INT 1TYPE STRING 'JPEG'

    The CHANNELS tag has a value of 3. Thus, the image is an RGB image.

    http://reference/Q.pdfhttp://reference/Q.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    40/523

    38 Chapter 2: Creating Image Displays

    Creating Direct Graphics Image Displays Working with Images

    4. Set the image size parameter from the query information:

    imageSize = imageInfo.dimensions

    The type of interleaving can be determined from the image size parameter andactual size of each dimension of the image. To determine the size of eachdimension, you must first import the image.

    5. Use READ_IMAGE to import the image from the file:

    image = READ_IMAGE(file)

    6. Determine the size of each dimension within the image:

    imageDims = SIZE(image, /DIMENSIONS)

    7. Determine the type of interleaving by comparing the dimension sizes to theimage size parameter from the file query:

    interleaving = WHERE((imageDims NE imageSize[0]) AND $

    (imageDims NE imageSize[1])) + 1

    8. Output the results of the interleaving computation:

    PRINT, 'Type of Interleaving = ', interleaving

    The following text appears in the Output Log:

    Type of Interleaving = 1

    The image is pixel interleaved. If the resulting value was 2, the image wouldhave been line interleaved. If the resulting value was 3, the image would havebeen image interleaved.

    9. If you are running IDL on a TrueColor display, set the DECOMPOSEDkeyword to the DEVICE command to one before your first RGB image isdisplayed within an IDL session or program. See “How Colors are Associatedwith Indexed and RGB Images ” on page 84 for more information:

    DEVICE, DECOMPOSED = 1

    10. Create a window and display the image with the TV procedure:

    WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $TITLE = 'An RGB Image'

    TV, image, TRUE = interleaving[0]

    http://reference/R.pdfhttp://reference/R.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    41/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Direct Graphics Image Displa

    The following figure shows the resulting RGB image display.

    Example Code: Displaying RGB Images with Direct Graphics

    Copy and paste the following text into the IDL Editor window. After saving the fias DisplayRGBImage_Direct.pro , compile and run the program to reproduce

    previous example.

    PRO DisplayRGBImage_Direct

    ; Determine the path to the file.file = FILEPATH('rose.jpg', $

    SUBDIRECTORY = ['examples', 'data'])

    ; Query the file to determine image parameters.queryStatus = QUERY_IMAGE(file, imageInfo)

    ; Output the results of the file query.PRINT, 'Query Status = ', queryStatusHELP, imageInfo, /STRUCTURE

    ; Set the image size parameter from the query; information.imageSize = imageInfo.dimensions

    ; Import the image.image = READ_IMAGE(file)

    ; Determine the size of each dimension within the image.imageDims = SIZE(image, /DIMENSIONS)

    ; Determine the type of interleaving by comparing the; dimension sizes with the image size parameter from the; file query.interleaving = WHERE((imageDims NE imageSize[0]) AND $

    Figure 2-5: RGB Image in Direct Graphics

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    42/523

    40 Chapter 2: Creating Image Displays

    Creating Direct Graphics Image Displays Working with Images

    (imageDims NE imageSize[1])) + 1

    ; Output the results of the interleaving computation.PRINT, 'Type of Interleaving = ', interleaving

    ; Initialize display.DEVICE, DECOMPOSED = 1

    ; Create a window and display the image with the TV; procedure and its TRUE keyword.WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $

    TITLE = 'An RGB Image'TV, image, TRUE = interleaving[0]

    END

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    43/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Object Graphics Image Displa

    Creating Object Graphics Image Displays

    In Object Graphics, binary, grayscale, indexed, and RGB images are contained inimage objects. The image object is contained within a model object, which is a parta view object. The view object is displayed within a window object with the Drawmethod to that window object. For some types of images, their data values must bscaled with the BYTSCL function before displaying the image in a window objectWhen the scaling is required depends on the type of image to be displayed.

    This section includes the following examples:

    • “Displaying Binary Images with Object Graphics ”.

    • “Displaying Grayscale Images with Object Graphics ” on page 44.

    • “Displaying Indexed Images with Object Graphics ” on page 47.

    • “Displaying RGB images with Object Graphics ” on page 52.

    Displaying Binary Images with Object Graphics

    Binary images are composed of pixels having one of two values, usually 0 or 1.These values are usually zero and one. With most color tables, pixels having valueof zero and one are displayed with almost the same color, especially with a normagrayscale color table. Thus, a binary image is usually scaled to display the zeros ablack and the ones as white.

    The following example imports a binary image of the world from the

    continent_mask.dat binary file. In this image, the oceans are zeros (black) athe continents are ones (white). This type of image can be used to mask out (omit)data over the oceans. The image contains byte data values and is 360 pixels by 36pixels.

    For code that you can copy and paste into an Editor window, see “Example CodDisplaying Binary Images with Object Graphics ” on page 43 or complete thefollowing steps for a detailed description of the process.

    1. Determine the path to the continent_mask.dat file:

    file = FILEPATH('continent_mask.dat', $

    SUBDIRECTORY = ['examples', 'data'])

    2. Initialize the image size parameter:

    imageSize = [360, 360]

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    44/523

    42 Chapter 2: Creating Image Displays

    Creating Object Graphics Image Displays Working with Images

    3. Use READ_BINARY to import the image from the file:

    image = READ_BINARY(file, DATA_DIMS = imageSize)

    4. Initialize the display objects:

    oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $DIMENSIONS = imageSize, $TITLE = 'A Binary Image, Not Scaled')

    oView = OBJ_NEW('IDLgrView', $VIEWPLANE_RECT = [0., 0., imageSize])

    oModel = OBJ_NEW('IDLgrModel')

    5. Initialize the image object:

    oImage = OBJ_NEW('IDLgrImage', image)

    6. Add the image object to the model, which is added to the view, then display theview in the window:

    oModel -> Add, oImageoView -> Add, oModeloWindow -> Draw, oView

    The resulting window should be all black (blank). The binary image containszeros and ones, which are almost the same color (black). A binary imageshould be scaled prior to displaying in order to show the ones as white.

    7. Initialize another window:

    oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $DIMENSIONS = imageSize, $TITLE = 'A Binary Image, Scaled')

    8. Update the image object with a scaled version of the image:

    oImage -> SetProperty, DATA = BYTSCL(image)

    9. Display the view in the window:

    oWindow -> Draw, oView

    http://reference/R.pdfhttp://reference/R.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    45/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Object Graphics Image Displa

    The following figure shows the results of scaling this display.

    10. Cleanup the object references. When working with objects always remembeto cleanup any object references with the OBJ_DESTROY routine. Since thview contains all the other objects, except for the window (which is destroyby the user), you only need to use OBJ_DESTROY on the view object.

    OBJ_DESTROY, [oView]

    Example Code: Displaying Binary Images with Object GraphicsCopy and paste the following text into the IDL Editor window. After saving the fias DisplayBinaryImage_Object.pro , compile and run the program toreproduce the previous example.

    PRO DisplayBinaryImage_Object

    ; Determine the path to the file.file = FILEPATH('continent_mask.dat', $

    SUBDIRECTORY = ['examples', 'data'])

    ; Initialize the image size parameter.imageSize = [360, 360]

    ; Import the image.image = READ_BINARY(file, DATA_DIMS = imageSize)

    Figure 2-6: Binary Image in Object Graphics

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    46/523

    44 Chapter 2: Creating Image Displays

    Creating Object Graphics Image Displays Working with Images

    ; Initialize display objects.oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $

    DIMENSIONS = imageSize, $TITLE = 'A Binary Image, Not Scaled')

    oView = OBJ_NEW('IDLgrView', $VIEWPLANE_RECT = [0., 0., imageSize])

    oModel = OBJ_NEW('IDLgrModel')

    ; Initialize image object.oImage = OBJ_NEW('IDLgrImage', image)

    ; Add the image to the model, which is added to the; view, and then display the view in the window.oModel -> Add, oImageoView -> Add, oModeloWindow -> Draw, oView

    ; Initialize another window.

    oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $DIMENSIONS = imageSize, $TITLE = 'A Binary Image, Scaled')

    ; Update the image object with a scaled version of the; image.oImage -> SetProperty, DATA = BYTSCL(image)

    ; Display the view in the window.oWindow -> Draw, oView

    ; Cleanup object references.

    OBJ_DESTROY, [oView]

    END

    Displaying Grayscale Images with Object Graphics

    Features within grayscale images are created by pixels that have varying intensities.Pixel values range from least intense (black) to the most instance (white). Since agrayscale image is composed of pixels of varying intensities, it is best displayed witha color table that progresses linearly from black to white. IDL provides several pre-

    defined color tables that progress linearly from black to white, but the bestrepresentation of a grayscale image is still the normal grayscale color table, which isthe default palette for IDL Object Graphics.

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    47/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Object Graphics Image Displa

    The following example imports a grayscale image from the convec.dat binaryThis grayscale image shows the convection of the Earth ’s mantle. The image conbyte data values and is 248 pixels by 248 pixels. Since the data type is byte, thisimage does not need to by scaled before display. If the data was of any type other thbyte and the data values were not within the range of 0 up to 255, the display wouneed to scale the image in order to show its intensities.

    For code that you can copy and paste into an Editor window, see “Example CodDisplaying Grayscale Images with Object Graphics ” on page 46 or complete thefollowing steps for a detailed description of the process.

    1. Determine the path to the convec.dat file:

    file = FILEPATH('convec.dat', $SUBDIRECTORY = ['examples', 'data'])

    2. Initialize the image size parameter:

    imageSize = [248, 248]

    3. Using READ_BINARY , import the image from the file:

    image = READ_BINARY(file, DATA_DIMS = imageSize)

    4. Initialize the display objects:

    oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $DIMENSIONS = imageSize, $TITLE = 'A Grayscale Image')

    oView = OBJ_NEW('IDLgrView', $VIEWPLANE_RECT = [0., 0., imageSize])

    oModel = OBJ_NEW('IDLgrModel')

    5. Initialize the image object:

    oImage = OBJ_NEW('IDLgrImage', image, /GREYSCALE)

    6. Add the image object to the model, which is added to the view, then displayview in the window:

    oModel -> Add, oImageoView -> Add, oModeloWindow -> Draw, oView

    http://reference/R.pdfhttp://reference/R.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    48/523

    46 Chapter 2: Creating Image Displays

    Creating Object Graphics Image Displays Working with Images

    The following figure shows the resulting grayscale image display

    7. Cleanup the object references. When working with objects always rememberto cleanup any object references with the OBJ_DESTROY routine. Since theview contains all the other objects, except for the window (which is destroyedby the user), you only need to use OBJ_DESTROY on the view object.

    OBJ_DESTROY, [oView]

    Example Code: Displaying Grayscale Images with ObjectGraphics

    Copy and paste the following text into the IDL Editor window. After saving the fileas DisplayGrayscaleImage_Object.pro , compile and run the program toreproduce the previous example.

    PRO DisplayGrayscaleImage_Object

    ; Determine the path to the file.file = FILEPATH('convec.dat', $

    SUBDIRECTORY = ['examples', 'data'])

    ; Initialize the image size parameters.imageSize = [248, 248]

    ; Import the image.image = READ_BINARY(file, DATA_DIMS = imageSize)

    ; Initialize display objects.oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $

    DIMENSIONS = imageSize, $

    Figure 2-7: Grayscale Image in Object Graphics

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    49/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Object Graphics Image Displa

    TITLE = 'A Grayscale Image')oView = OBJ_NEW('IDLgrView', $

    VIEWPLANE_RECT = [0., 0., imageSize])oModel = OBJ_NEW('IDLgrModel')

    ; Initialize image object.oImage = OBJ_NEW('IDLgrImage', image, $

    /GREYSCALE)

    ; Add the image object to the model, which is added to; the view, then display the view in the window.oModel -> Add, oImageoView -> Add, oModeloWindow -> Draw, oView

    ; Cleanup object references.OBJ_DESTROY, [oView]

    END

    Displaying Indexed Images with Object Graphics

    An indexed image contains up to 256 colors, typically defined by a color tableassociated with the image. The value of each pixel relates to a color within theassociated color table. Combinations of the primary colors (red, green, and blue)make up the colors within the color table. Indexed images are usually stored in imafiles, instead of binary files, since they typically contain related color information (associated color table). You can query an image file to determine if it contains anindexed image.

    The following example imports an indexed image from the avhrr.png image This indexed image is a satellite photograph of the world. Most indexed images ranin value from 0 up to 255 because of the range of the associated color table.Therefore, most indexed images do not require scaled displays.

    For code that you can copy and paste into an Editor window, see “Example CodDisplaying Indexed Images with Object Graphics ” on page 51 or complete thefollowing steps for a detailed description of the process.

    1. Determine the path to the avhrr.png file:

    file = FILEPATH('avhrr.png', $SUBDIRECTORY = ['examples', 'data'])

    2. Use QUERY_IMAGE to query the file to determine image parameters:

    queryStatus = QUERY_IMAGE(file, imageInfo)

    http://reference/Q.pdfhttp://reference/Q.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    50/523

    48 Chapter 2: Creating Image Displays

    Creating Object Graphics Image Displays Working with Images

    3. Output the results of the file query:

    PRINT, 'Query Status = ', queryStatusHELP, imageInfo, /STRUCTURE

    The following text appears in the Output Log:

    Query Status = 1** Structure , 7 tags, length=36, refs=1:

    CHANNELS LONG 1DIMENSIONS LONG Array[2]HAS_PALETTE INT 1IMAGE_INDEX LONG 0NUM_IMAGES LONG 1PIXEL_TYPE INT 1TYPE STRING 'PNG'

    4. Set the image size parameter from the query information:

    imageSize = imageInfo.dimensions

    The HAS_PALETTE tag has a value of 1. Thus, the image has a palette (colortable), which is also contained within the file. The color table is made up of itsthree primary components (the red component, the green component, and theblue component).

    5. Use READ_IMAGE to import the image and its associated color table fromthe file:

    image = READ_IMAGE(file, red, green, blue)

    6. Initialize the display objects:

    oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $DIMENSIONS = imageSize, TITLE = 'An Indexed Image')

    oView = OBJ_NEW('IDLgrView', $VIEWPLANE_RECT = [0., 0., imageSize])

    oModel = OBJ_NEW('IDLgrModel')

    7. Initialize the image ’s palette object:

    oPalette = OBJ_NEW('IDLgrPalette', red, green, blue)

    8. Initialize the image object with the resulting palette object:

    oImage = OBJ_NEW('IDLgrImage', image, $

    PALETTE = oPalette)

    http://reference/R.pdfhttp://reference/R.pdf

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    51/523

    Chapter 2: Creating Image Displays

    Working with Images Creating Object Graphics Image Displa

    9. Add the image object to the model, which is added to the view, then displayview in the window:

    oModel -> Add, oImageoView -> Add, oModeloWindow -> Draw, oView

    10. Use the colorbar object to display the associated color table in anotherwindow:

    oCbWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $DIMENSIONS = [256, 48], $TITLE = 'Original Color Table')

    oCbView = OBJ_NEW('IDLgrView', $VIEWPLANE_RECT = [0., 0., 256., 48.])

    oCbModel = OBJ_NEW('IDLgrModel')oColorbar = OBJ_NEW('IDLgrColorbar', PALETTE = oPalette, $

    DIMENSIONS = [256, 16], SHOW_AXIS = 1)oCbModel -> Add, oColorbar

    oCbView -> Add, oCbModeloCbWindow -> Draw, oCbView

    The following figure shows the resulting indexed image and its color table.

    The data values within the image are indexed to specific colors within thetable. You can change the color table associated with this image to show hoan indexed image is dependent upon its related color tables.

    11. Change the palette (color table) to the EOS B pre-defined color table:

    oPalette -> LoadCT, 27

    Figure 2-8: Indexed Image and Associated Color Table in Object Graphics

  • 8/20/2019 IDL Image Processing working with Images in IDL.pdf

    52/523

    50 Chapter 2: Creating Image Displays

    Creating Object Graphics Image Displays Working with Images

    12. Redisplay the image in another window to show the palette change:

    oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $DIMENSIONS = imageSize, TITLE = 'An Indexed Image')

    oWindow -> Draw, oView

    13. Redisplay the colorbar in another window to show the palette change:

    oCbWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $DIMENSIONS = [256, 48], $TITLE = 'EOS B Color Table')

    oCbWindow -> Draw, oCbView

    The following figure shows the indexed image with the EOS B color table.

    14. Cleanup the object references. When working with objects always rememberto cleanup any object references with the OBJ_DESTROY routine. Since theview contains all the other objects, except for the window (which is destroyedby the user), you only need to use OBJ_DESTROY on the view object.

    OBJ_DESTROY, [oView, oCbVeiw, oPalette]

    Figure 2-9: Indexed Image and EOS B Color Table in Object Graphics

  • 8/20/2019 IDL Image Processi