Image Processing

Image Processing

I have been involved in a variety of projects related to image processing - a fascinating subject with a nice mix of computer science, mathematics and human vision. I learned much about the subject reading John Russ's The Image Processing Handbook. My first serious projects were at PNNL where I learned ImageJ, obtained data for and experimented with the Visible Human Project, and researched stereoscopic volume rendering on ultrasound data.

Virtual Reality Volumetric Display Techniques for Three-Dimensional Medical Ultrasound
  R. J. Littlefield, R. W. Heiland, and C. R. Macedonia,
  Ultrasound in Health Care in the Information Age, H. Sieburg, S. Weghorst, 
and K. Morgan (Eds.), IOS Press and Ohmsha, 1996

scikit-image

The Python package scikit-image is very easy to use. Here's a simple example (I relied on matplotlib for visualization):

In [1]: from skimage import data,io,filter
In [2]: %pprint   #Pretty printing has been turned OFF
In [7]: dir(data)
Out[7]: ['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '_os', 
'camera', 'checkerboard', 'chelsea', 'clock', 'coffee', 'coins', 'data_dir', 'horse', 'immunohistochemistry', 
'imread', 'lena', 'load', 'moon', 'page', 'text']

In [3]: image1 = data.immunohistochemistry()
In [4]: io.imshow(image1)
In [5]: io.show()

We can then easily determine the shape of the data (3 components of RGB) and extract edges of the R component using a Sobel filter:


In [6]: image1.shape
Out[6]: (512, 512, 3)


In [7]: edgesRed = filter.sobel(image1[:,:,0])
In [8]: io.imshow(edgesRed)
In [9]: io.show()

Some of its filters include:

>>> from skimage import filter
>>> dir(filter)
['LPIFilter2D', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '_canny', '_ctmf', '_denoise', '_denoise_cy', '_gabor', '_gaussian', '_rank_order', 'canny', 'ctmf', 'denoise_bilateral', 'denoise_tv_bregman', 'denoise_tv_chambolle', 'edges', 'gabor_filter', 'gabor_kernel', 'gaussian_filter', 'hprewitt', 'hscharr', 'hsobel', 'inverse', 'lpi_filter', 'median_filter', 'prewitt', 'rank', 'rank_order', 'roberts', 'roberts_negative_diagonal', 'roberts_positive_diagonal', 'scharr', 'sobel', 'threshold_adaptive', 'threshold_otsu', 'thresholding', 'vprewitt', 'vscharr', 'vsobel', 'wiener']


ImageJ

ImageJ is very mature and widely used, especially in the life sciences (not surprising, given that it came out of the NIH). It started out as a Mac-only application but has evolved over time and is now a cross-platform Java-based application. It is primarily GUI-driven, but also has options for macros and scripting.


SimpleITK

  • SimpleITK, based on the amazingly rich Insight Segmentation and Registration Toolkit (ITK) project also provides Python bindings.
    
    from __future__ import print_function
    
    import SimpleITK as sitk
    import sys
    import os
    
    if len ( sys.argv ) < 4:
        print( "Usage: SimpleGaussian {input} {sigma} {output}" )
        sys.exit ( 1 )
    
    
    reader = sitk.ImageFileReader()
    reader.SetFileName ( sys.argv[1] )
    image = reader.Execute()
    
    pixelID = image.GetPixelIDValue()
    
    gaussian = sitk.SmoothingRecursiveGaussianImageFilter()
    gaussian.SetSigma ( float ( sys.argv[2] ) )
    image = gaussian.Execute ( image )
    
    caster = sitk.CastImageFilter()
    caster.SetOutputPixelType( pixelID )
    image = caster.Execute( image )
    
    writer = sitk.ImageFileWriter()
    writer.SetFileName ( sys.argv[3] )
    writer.Execute ( image );
    
    We can then run this script and provide various parameters:
    python SimpleGaussian.py gauss.png 2.0 gauss_2.0.png
    python SimpleGaussian.py gauss.png 4.0 gauss_4.0.png
    python SimpleGaussian.py gauss.png 9.0 gauss_9.0.png
    

    Original image from Wikimedia Commons.

    Other image processing packages

    Some other open source imaging packages include: