Computer assisted Image Analysis VT04 Programming for Image Analysis/Processing Tools and guidelines to write your own IP/IA applications Why this lecture? Introduction To give an overview of What is needed when you start an IP/IA project What are some of the available tools that can help you along the way 29 april 2004 Lecture 10 (part 2) Xavier Tizon Programming and IP: what do you need to know to start? Your choice of environment will depend on: Image format Algorithm(s) Data structures Graphical User Interface (GUI) + Performance requirements File Some common format TIFF, JPG, GIF, PNG, BMP, Raw files Some exotic format Acquisition system (camera, ) Real-time applications Feedback between system and IP application Image format Dimensions 2D 3D More color, time, features, modality, Algorithms and data structures Typical data structures: Arrays (images) Stacks and queues (ex: region growing) Graphs, trees, lists, Needs for GUI Does the application require user interaction? Typical algorithms: Convolution Numerical (ex: matrix computations, integration) Transforms (ex: FFT) Geometry (ex: convex hull) 1
*My* choice of available tools Windows survival kit for non-serious image processing. Matlab ImageJ ITK There are a lot of other possibilities out there (often customized by application) Open and convert images Irfanview (freeware) Survival kit Manipulate, create Adobe Photoshop (commercial 7000 SEK) Paint Shop Pro (shareware - $100) XV (freeware) The Gimp (open source) The Gimp Matlab Photoshop -like www.gimp.org Open source with big community Plugins Developed under Unix. Windows port available at www.gimp.org/win32 MATrix LABoratory Optimized for matrix computation Bottom line: NO FOR LOOPS www.mathworks.com Image Processing Toolbox Prices: Matlab IP Toolbox Complete Matlab 8000 SEK 3500 SEK 30.000 SEK File formats JPG, TIFF, GIF, PNG, BMP + + Support for DICOM Raw files Matlab: IO imread, imwrite I=imread( imagename.tif imagename.tif, tif ) imwrite(i, imagename.tif imagename.tif, tif ) fid=fopen( file.raw','r') img=fread(fid_in,'uchar'); img=reshape(img,x,y,z); Matlab: basic functions Image arithmetics Work directly with matrices: +,-, Work with uint8, uint16 data: imadd, imsubstract, Image enhancement Change brightness / contrast: imadjust Histogram equalization: histeq Image acquisition Toolbox Direct feed from cameras, microscopes,... 2
Matlab: basic functions Geometric transformations imrotate, imcrop imtransform (affine, projective, ) Resizing, Interpolation imresize Interpolation methods: nearest (neighbour( neighbour) Bilinear (2x2), bicubic (4x4) Spline (if Spline toolbox) Matlab: basic functions Feature extraction Linear filtering: filter2 Classical edge operators: edge f=fspecial('gaussian') bilg=filter2(fgaussian,bil)); biledge=edge(bil,'sobel'); Matlab: advanced Filtering (FIR filters creation SP toolbox) Inverse filtering (restoration) Image transforms (FFT, PCA, Radon ) fft,, fft2, fftn ifft,, ifft2, ifftn Binary and grayscale morphology Segmentation Watershed (also on color images) IP toolbox 3
Matlab: visualization Matlab: GUI 2D display imshow imagesc 3D surface rendering isosurface,, patch isocaps, isonormals Guide Matlab: more Matlab code can be integrated/reused: Matlab C compiler COM objects creation JAVA Image processing applications the 'Q Software www.cs.dartmouth.edu/~farid/tutorials/tutorials.html DIP image www.ph.tn.tudelft.nl/diplib/ SDC Morphology Toolbox www.mmorph.com/ Matlab pros and cons + Language very easy to learn + All basic tools are in IP toolbox + Size of community + Multi-platform (*.m scripts) + nd What for then? - Not optimal for non vectorizable algorithms (ex: region growing) - Memory handling (algos are written for matrices of DOUBLE) not suited for big 3D datasets MATLAB 7.0 switches to SINGLE precision! - prototyping of IP/IA programs - easy to advanced 2D IP/IA -simple 3D ImageJ Originally developed on Mac for cell analysis of microscopic images (NIH image) rsb.info.nih.gov/ij/ ImageJ: IO File formats TIF (even 16 bits), GIF, JPG, RAW + Support for DICOM via a plugin Lots of plugins for different microscopes Open source (actually public domain) 4
ImageJ: basic functions Image enhancement Image measurements ROI tools: draw, count, measure Edge extraction, binary & grayscale morphology ImageJ: extensions Add plugin in JAVA TransformJ: geometric transformations FeatureJ: gradient, 2 nd derivative, VolumeJ: volume renderer Scripting language (record function + edit script) Ex: bouncingbar Use ImageJ as a toolbox within another applet ImageJ pros and cons + JAVA: easy to learn + JAVA: runs on all platforms + Open Source: FREE (public domain) + Extension by JAVA plugins or scripting + FAST (??) What for then? - Data type not originally meant for 3D - complete user-interfaced solution - easy to mid-advanced 2D IP/IA -simple 3D ITK Insight Segmentation & Registration Toolkit Project at the National Library of Medicine at the National Institute of Health (NIH) Goals: Support the Visible Human Project. Create a repository of fundamental algorithms. Develop a platform for advanced product development. Grow a self-sustaining sustaining community of software users and developers. the data pipeline File Reader ITK: 2 principles Image Gaussian Image Generic programming with templates ITK images are N-dimensionalN ITK handles arbitrary pixel type Writer File In the SAME code!! ITK: available algorithms Binary and grayscale morphology watershed Partial differential equations methods Anisotropic diffusion filters see IP 2 Level sets, fast marching Advanced data structures Mesh, point clouds, vector images 5
ITK example: Segmentation ITK example: 2D-3D registration Geodesic active contours Extending ITK ITK pros and cons Write new filters (C++) GUI: fltk, Qt, windows MFC Visualization: VTK + Growing and very active community + Can handle N-dim N data smoothly + Open Source: FREE + Very advanced algos in preprocessing / segmentation / registration - Learning curve is steep - No built-in in GUI Scripting: tcl, Python What for then? - Serious IP/IA needs - multi-dim algos See also Khoros IDL VTK Intel IP library Microsoft Vision SDK Image++ (www.image( www.image-integration.com) www.magic-software.com : source code repository The best way to learn to play the drums is to play the drums Richard Feynman 6