programming for image analysis program for the x window...
TRANSCRIPT
Programming for image analysis
Programs for:image ANALYSISimage processing
tools for writing your own programs
fundamental steps
knowledge base
CHAPTER 2imageacquisition
CHAPTER 3&4imageenhancement
CHAPTER 5imagerestoration
CHAPTER 6color imageprocessing
CHAPTER 7wavelets andmultiresolutionprocessing
CHAPTER 8compression
CHAPTER 9morphologicalprocessing
CHAPTER 10segmentation
CHAPTER 11representation& description
CHAPTER 12objectrecognition
problem
xv
• xv is an interactive image manipulation program for the X Window System
• grab
available at IT
http://www.trilon.com/xv/
grab image
ALGORITHMS• filters
• blur, sharpen, ...• geometric transforms
• rotate, ...
WINDOWS à color editor• histogram equalization, contrast stretch, ...
xv color editor
gimp
• GNU Image Manipulation Program – paint program, photo retouching, image
composition, ...
• free
”If you enjoy using Adobe's Photoshop® program, you'll love the GIMP” .....
http://www.gimp.org/
gimp example
layers
”enhancement”
ENVI
• ENvironment for Visualizing Images
• developed for remote sensing and GIS
http://www.rsinc.com/envi
image enhancement
IDL
• Interactive Data Language• for data analysis and visualization• used to write ENVI
http://www.rsinc.com/idl/
VIP
• Visual IDL Programming environment• programming IDL without knowing the
language
http://www.rsinc.com/vip/
khoros
• tool boxes for– visualization: multispectral, 3D– image processing– data manipulation
• visual programming
http://www.khoral.com/khoros/
VTK
• Visualization ToolKit• C++ class library, and
several interpreted interface layers (Tcl/Tk, Java, Python...)
• free
http://public.kitware.com/VTK/
MATLAB
• MATrix LABoratory– most suited for matrix operations
• not: for x=1:n for y=1:n, ...
• image processing toolbox– help images– helpdesk
http://www.mathworks.com/products/image/
available at IT
image processing toolbox
• from MATLAB and Signal Processing Toolbox
• read/write a number of image formats• predefined functions
– image transforms– filtering– enhancement– feature extraction
imagesbasic structure in MATLAB is the arrayà image is (often) stored as 2D array
each element in matrix (image I) = pixeladdressed I(x,y)
many predefined functions for image processing and analysis ((often) well described)
write your own programs!!!!
image representation
• indexed images– image array I, colormap C
(index à colour)
• intensity images– 2D array– element = pixel– intensity value [0,1]
• binary images– special kind of intensity
image– pixels have value 0 (white)
or 1 (black)
• RGB images– 3D array (MxNx3)– MxN intensity image for red,
green, blue component• uint8-type à 8-bit images
– each pixel is 1 byte with values from 0 to 255
• uint16-type à 16-bit images– each pixel is 2 byte with
values from 0 to 65535
double or uint8/uint16
I/O: read and write
• imread– I=imread(’imagename.tif’,’tif’)
• imwrite– imwrite(I,’imagename.tif’,’tif’)
X Windows Dump (XWD)'xwd'
Tagged File Format (TIFF)'tif' or 'tiff'
Portable Networks Graphics (PNG)’png'
Windows Paintbrush (PCX)'pcx'
Joint Photographic Experts Group (JPEG)
'jpg' or 'jpeg'
Windows Icon resources (ICO)'ico
Hierarchical Data Format (HDF)'hdf'
Graphics Interchange Format (GIF)'gif'
Windows Cursor resources (CUR)'cur'
Windows Bitmap (BMP)’bmp’
File TypeFormat
conversions
mat2graymatrix à intensity
rgb2grayRGBà intensity
im2bwindexed, intensity, RGB à BWTHRESHOLDING
im2uint8, im2uint16indexed, intensity, RGB à uint8
im2doubleuint8 à indexed, intensity, RGB
image arithmetics
• MATLAB arithmetic operators (+, -, ...) do not accept uint8 or uint16 data– ... out of range ...– new version: imadd,
imsubtract, ...• enhancement
– change brightness/add constant: brighten
– change contrast&brightness: imadjust
• image arithmetics– convert to double
• logical operations– binary image
• &, ~,...
coordinate system
I(row,column)x
y
upper left corner = (1,1)
pixel coordinatesdiscrete
spatial coordinates continuous
upper left corner = (0.5,0.5)
displaying imagesimshow(nameOfImage)
display by using image (& imagesc) functionà Handle Graphics imageobject
imshow automatically sets Handle Graphics properties and attributes to optimize display
spatial transformations
• interpolation– nearest neighbour (1)– bilinear (2x2)– bicubic (4x4)
• resizing– imresize
• rotation– imrotate
• cropping
imresizeimshow(bil)
bilX=imcrop(bil,[X Y cutSize cutSize]);imshow(bilX)
Small=0.6;bilSmall=imresize(bil, Small,'bilinear');bilSmallX=imcrop(imshow(bilSmallX)
Large=2.5;bilLarge=imresize(bil, Large,'bilinear');bilLargeX=imcrop(imshow(bilLargeX)
imrotate
imshow(bil)
rot=25;bilRotN=imrotate(bil,rot,'nearest');bilRotBL=imrotate(bil,rot,'bilinear');
imshow(bilRotN)
bilNX=imcrop(bilBLX=imcrop(
imshow(bilNX)
imshow(bilBLX)
histogram processing
• histogram of an image– imhist
• contrast stretching– imadjust
• histogram equalization– histeq
bil2=imadjust(bil,[10/255 210/255],[]);imshow(bil2)imhist(bil2)
bilEq=histeq(bil);imshow(bilEq)imhist(bilEq)
filtering
• predefined (fspecial)• design own filters
– MxN matrix with entries ∈[0,1]– centre in (M/2,N/2)
• apply filter using filter2• predefined edge filters: edge
bilEdge=edge(bil,'sobel');
fGaussian=fspecial('gaussian')bilGaussian=im2uint8(filter2(fGaussian,im2double(bil)));
filtSize=5;fMean=ones(filtSize,filtSize)/(filtSize*filtSize)bilMean=im2uint8(filter2(fMean,im2double(bil)));
fSobel = 1 2 10 0 0-1 -2 -1
fGaussian = 0.0113 0.0838 0.01130.0838 0.6193 0.08380.0113 0.0838 0.0113
image transforms
• image usually function of two (three) spatial variables f(x,y)
• transformation gives an alternative representation – Fourier transform– discrete cosine transform
Fourier transform
fft, fft2, and fftn implement fast Fourier transform algorithm for computing the one-dimensional DFT, two-dimensional DFT, and N-dimensional DFT, respectively.Functions ifft, ifft2, and ifftn compute the inverse DFT.
possible to create and applyfilters in frequency domain: highpass, lowpass, bandpass, ...
use FFT
freqdist=imread('images/freqdist.tif');
imshow(freqdist)
freqdistFFT=fft2(freqdist);
imshow(log(abs(fftshift(freqdistFFT))),[])
same as centreshift in IMP
binary image operations
• thresholding• labelling• simple descriptors
– area, perimeter, euler number
• morphological operators
create binary image
imshow(circles)
imhist(circles)
thresCircles=im2bw(circles,150/255);imshow(thresCircles)
invCircles=~thresCircles;imshow(invCircles)
label imageselect connected component
imshow(invCircles)
[circlesID nrCirc]=bwlabel(invCircles,8);
imshow(circlesID,[])
oneID=bwselect(circlesID,8);
imshow(oneID,[])
morphology
structuring element defined by • MxN matrix of 0s and 1s• origin in (M/2,N/2)
imshow(tower)
SE=[1 1 1; 1 1 1; 1 1 1];
towerShrink=erode(tower,SE);imshow(towerShrink)
towerGrow=dilate(tower,SE);imshow(towerGrow)
added
• distance transform with applications– watershed, ...
• more morphology• more image formats• image arithmetics
– imadd, imsubtract, imlincomb, ...
other tool boxes for MATLAB
• the 'Q' Software– http://www.cs.dartmouth.edu/~farid/tutorials/tutorials.html
• DIP image– http://www.ph.tn.tudelft.nl/DIPlib/
• [SDC Morphology Toolbox– http://www.mmorph.com/]
ImageJ
• image processing and analysis in Java• easy to add own (or others’) plugins• can be run as applet• free
http://rsb.info.nih.gov/ij/
thresholding
measurements
write own IJ plugins
• Java complier needed• added under Plugins• recorder function exists
ImagePlus – image object:COLOR_256COLOR_RGBGRAY32GRAY16GRAY8
• getPixel, setPixel, ...• ROI - region of interest to work on part of image• draw• use already exisiting functions• and more....