Dr. Yoram Tal! " # $ $ % & ' Visualization (human) Enhancement, Restoration Analysis (computer) Documents, Textures, Biometrics, Object recognition There are fundamental differences between them 3 Dr. Yoram Tal ( ) * * + 4 2
Dr. Yoram Tal, -.. / 5 Dr. Yoram Tal, -.. / 0 1 1 2 Lena Soderberg (ne Sjooblom) was last reported living in her native Sweden, happily married with three kids and a job with the state liquor monopoly. In 1988, she was interviewed by some Swedish computer related publication, and she was pleasantly amused by what had happened to her picture. That was the first she knew of the use of that picture in the computer business. 6 3
Dr. Yoram Tal 3 4 5 5 6 7 8 4 9 : 6 5 ; Thomas Colthurst O dear Lena, your beauty is so vast It is hard sometimes to describe it fast. I thought the entire world I would impress If only your portrait I could compress. Alas! First when I tried to use VQ I found that your cheeks belong to only you. Your silky hair contains a thousand lines Hard to match with sums of discrete cosines. And your lips, sensual and tactual Thirteen Crays found not the proper fractal. And while these setbacks are all quite severe I might have fixed them with hacks here or there But when filters took sparkle from your eyes I said, Damn all this, Ill just digitize. 7 Dr. Yoram Tal < = >? @ A > B C D B 8 4
Dr. Yoram Tal E F G H I J K L F G M N K O External Irradiation Electromagnetic Acoustic Visible IR UV MW File Degradation Reflected Transmitted X-Rays A/D Sensor Array Focus Emitted Object 9 Dr. Yoram Tal P Q R Q S T U V W T R X Y A digital image is an ordered set of pixels (picture elements, also called pels). A pixel is actually a point that has two components: position and color. Further, pixel position has two components (X,Y) while color is represented by three components, which makes a total of five independent components. The screen representation of an image pixel may contain more (sometimes less) than a single screen point (or screen pixel) per image pixel 10 5
Dr. Yoram Tal Z [ \ ] ^ _ ` a b c d e f g h e g g i 4 neighborhood 8 neighborhood In most cases an image is represented by a 2D matrix Picture Element (pixel) 11 Dr. Yoram Tal j k l k m n o p q In MATLAB, colormaps are tables (2D matrices) of size Mx3, M being the number of colors (rows). By default M=64. Each color (row) is represented by three numbers in [0,1] corresponding to the intensities of the [Red, Green, Blue] components. For example [1,0,0] is red, [1,1,0] is yellow, [0,0,0.5] is dark blue, and so on. In Graylevel maps R=G=B. There are many predefined colormaps (in \matlab\graph3d) such as jet, hsv,hot,pink, autumn, copper, gray, 12 6
Dr. Yoram Tal r s t u u v w u x y u z { z { } ~ ƒ ˆ Š Š Œ Category # of functions Image Display 11 Image File I/O 5 Spatial Transformations 13 Pixel Values and Statistics 10 Image Analysis 4 Image Arithmetic 7 Image Enhancement (Deblurring) 7 Image Registration 5 Linear Filtering 6 Linear 2-D Filter Design 6 Image Transforms 11 ( == major upgradings in MATLAB 6.1 ) Category # of functions Neighborhood and Block Processing 6 Morphological Operations (Intensity and Binary Images) 18 Morphological Operations (Binary Images) 18 Structuring Element (STREL) Creation and Manipulation 8 Deblurring 7 Array Operations 2 Region-Based Processing 4 Colormap Manipulation 6 Color Space Conversions 6 Image Types and Type Conversions 22 Toolbox Preferences 2 See also: IP Toolbox Demos at matlabroot\toolbox\images\imdemos 13 Dr. Yoram Tal Ž Ž š œ ž œ Ÿ ª «± ² ³ µ ³ ¹ º» ¼ ½ ¾ À Á Â Ã Ä Å Æ Ç ¹ È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ á ç è é ç ê ç è é ç ë á â ì í à î 14 7
Dr. Yoram Tal ï ð ñ ò ð ó ô õ ö ø ù ú û ü õ (multi-dimensional) Packed binary Image Data ý þ ÿ 15 Dr. Yoram Tal! " # $ % $ #! & ' ( $ ) >> [x, map] = imread( trees.tif ); >> imshow(x,map) 1 2 3 4 5 6 3 7 3 * +, + -. / 0 16 8
Dr. Yoram Tal 8 9 : ; < = : > =? @ A ; < >> x1 = ind2gray(x,map); >> imshow(x1) 17 Dr. Yoram Tal 8 9 : ; 9 < = : > =? @ A ; < 0.0 0.4 0.6 1.0 9
Dr. Yoram Tal B C D E F G H I J 19 Dr. Yoram Tal B C D K F G H I J Three intensity matrices: R, G, and B 10
Dr. Yoram Tal L M N O P Q R S T U N V image imagesc imshow - Create and display image object. - Scale data and display as image. - Display image. colorbar getimage truesize warp zoom - Display colorbar. - Get image data from axes. - Adjust display size of image. - Display image as texture-mapped surface. - Zoom in and out of image or 2-D plot. 21 Dr. Yoram Tal L M N O P W X Y imread imwrite imshow Z Z [[ [[ \\ ]] ^ ^ `` aa bb aa cc dd ee - Read image type files. - Write image type files. - Load and display an image. - Interactive loading of different files (MATLAB 6). - image file info (IP toolbox 3) 22 11
w Dr. Yoram Tal f g h i j k l m n o p q r s t q s r n.tif.bmp.jpg.png.pcx.gif Header Image Data raster fields blocks u Magic number v width Height Compression info comments colormap Bits per pixel Formats:.tif.bmp.jpg.png.pcx.gif 23 Dr. Yoram Tal x y z { } ~ { } ~ gray2ind im2bw Im2double im2uint8 Im2uint16 ind2gray ind2rgb mat2gray rgb2gray rgb2ind - intensity image to indexed image. - image to binary image by thresholding. - image to double precision. - image to 8-bit unsigned integers. - image to 16-bit unsigned integers. - indexed image to intensity image. - indexed image to RGB image. - matrix to intensity image. - RGB image or colormap to grayscale. - RGB image to indexed image. 24 12
Dr. Yoram Tal ƒ ˆ Š Œ Š Ž Image data Colormap (figure property) Display Direct (indexed) Clim (axes property, NA for direct) scaled scaled...... CDataMapping: scaled or direct (image property) 25 Dr. Yoram Tal ˆ Š Š š œ ž Ÿ ž œ œ Ÿ Ÿ œ 26 13
Dr. Yoram Tal ª «± ² ± ³ µ ¹ º» ¼ ½ ¾ À À Á » Ã Ä Å ½ Æ Ç È É Ê Ë É Ì Í Î Î Ï Ð Ë Ñ É Ê Ò Ó å æ ç è é ê ë ì í î ç ï Ô ÕÖ Õ Ø Ù Ú Û Ü Ù Ý Þ Ô ß à á Ü â ã ä 27 Dr. Yoram Tal ð ñ ò ó ó ô õ ö ó ø ô ô ù ó ô ó ö ú û ü õ ý ú ü ó ö ò þ ÿ 28 14
Dr. Yoram Tal 29 Dr. Yoram Tal! " # $ % 1 2 3 4 2 5 6 7 7 8 9 : ; < Core C D E F G H H I J * +, -. / 0 Interpreter & ' ( ) & ' = >? @ A B User 30 15
Dr. Yoram Tal K L M N O P Q R P S N R T U M P V Selection Vectorization Sparse Matrices 31 Dr. Yoram Tal W X Y X Z [ \ ] ^ _ ` a b c d e f g h i c e h i d j e h k g j l m n o p f i h q r s t u s v r w x u x y z { z u } ~ u t y ƒ ˆ š œ Š Œ Ž ˆ 32 16
Í Ø, Dr. Yoram Tal ž Ÿ Ÿ ¹ º» ¼ ½ ¾ À Á Â Ã Ä Å Æ Ç È É Ê È Ë Ì Í Î ÏÐ Ñ Ò Ó Î Í Î Ô Õ Ë Ì ÏÎÖ Ð Ñ [ ] ª ª ª ª ««± ± ² ² ³ ³ ««ªª ªª ³³ ³ ³ ª ª ³³ ² ² µ µ ³ ³ é ê ëì í î ï ï ð ï ð ñ ð ò ó ô õ ö ø ù ú û ü ý þ ÿ ù û ü Ù Ú Û Ü Ý Þ ß Û à á â ã ä å æ ç è æ ç è å â ã ä 33 Dr. Yoram Tal 2 3 4 ( / 5 6 * 7 8 ) 2 3 4 ( / 5 6 4 / * 5 7 8 ( ) +,!! "" ## $ $ $$ %% $ $ $$ ## && $ $ ' ( ) 0 1 * +, -. / 2 3 ( 9/ 9, 7 8 4 ' 6-6 + 6 ) 5 [ ] 2 3 4 ( / 5 6 4 * * * 5 7 8 ) ) ) [ ] [,,, ] 34 17
Dr. Yoram Tal : ; < ; = >? @ A B C D N O E F G H I J K L M U V [ \ ] ^ _ ` a b c d e f g W X Y Z ƒ Y Œ ƒ ˆ ˆ W ˆ ƒ Š Š W a h i j k l m l i n o j p q r i l o l s j h p t u v w x y z { x x } ~ z { S T Q QRP Dr. Yoram Tal Ž š œ ž Ÿ ž ž x y 1. 0.0804 0.7751 2. 0.0986 0.8062 3. 0.1626 0.8206 4. 0.2311 0.8206 5. 0.3361 0.8182 6. 0.3498 0.9211 7. 0.3817 0.8206 8. 0.4114 0.7632............. n 2 i+ 1 i i i+ 1 ± ² ª «³ ± ² i= 1 µ ¹ º µ ¹ 9. 0.4091 0.7081 S = ( x y x y ) 18
` ` b b a a ` ` Dr. Yoram Tal» ¼ ½ ¾ À Á Â Ã ¾ Á Ä Å Æ Ç È É Ê Ë È Ì Í Î Ï Ð È È É Ñ Ò Ó Ô Õ Ö Ô Ó Ø Ù Ô Ú Û Ü Ý Ú Ô Þ Ò Ó Ô Õ Ö ß à Ó á Ö à ß Ø â ã ä å æ ç è é ê ë ì í é ê î ï í ð ñ ò è é ê ë ï í é ê î ó ë ô î õ ö ø ù ú û ë é üñ ý þ ÿ þ 37 ^ _ Dr. Yoram Tal! " # $ % & ' & ( & " ) * & ' & ( & " +, -. b c d ^ b _ ` e ^ f _ b e ^ g _ f h ^ ` _ b h ^ b _ f h ^ f _ g / 0 1 2 3 4 5 4 6 7 8 9 : ; < = >? @ A B C D E F G E H I F J K L M E F G N O P Q R S T U V W W X Y Z Y [ \ ] 38 19
Dr. Yoram Tal i j k l m n o p q l o m r s t u v w x y v z { } y z z ~ w v x ƒ ˆ Š Œ Ž ˆ Š Œ ˆ Š Œ Ž ˆ Š Œ ƒ ƒ 39 Dr. Yoram Tal š œ 40 20
Background Command Window Workspace = set of variables Workspace Browser = shows variables Array Editor = double click on variable for more info current directory search path for m files; set path from file menu Command History Windows = current and previous sessions
Background MATLAB editor = edit in command window HELP - click on? on desktop toolbar - type help browser navigator pane display pane e.g. search tab doc e.g. doc format shows format command
Images picture is given as a matrix (0,0) or (1,1) is upper left corner (0,1) is top row second column second index is rows (C) f(x,y) is intensity at (x,y)=(r,c) types: TIFF,JPEG,GIF,BMP,PNG,XWD PNG: Portable Network Graphics;.png XWD: X Window Dump;.xwd
Simple Commands read image: f=imread( chestxray.jpg ); f=imread ( d:\ myimages\ chestxray. j pg ); [M, N] = size(f); whos; imshow(f); use impixel to get intensity of individual pixel - use with mouse MATLAB replaces next picture in same spot. To get a new graph use figure
imshow(f), figure, imshow(g) imwrite(f, patient, tif ); or else imwrite(f, patient.tif ); options to change intensity range and compression imfinfo bubbles25.jpg or K=imfinfo( bubbles25.jpg );
Data Classes double = double precision; 8 bytes per element uint8 = unsigned 8 bit integer [0,255] byte per element uint16= unsigned 8 bit integer [0,65535] 2 bytes per element uint32= unsigned 8 bit integer [0,65535] 4 bytes per element int8 = signed 8 bit integer [-128,127] int16 int32
single = single precision; 4 bytes per element char = Characters ; 2 bytes per element logical= 0 or 1; 1 byte per element
Image Types intensity images binary images indexed images RGB images conversion between classes im2uint8 : to uint8 im2uint16: to uint16
mat2gray: from double to double in [0,1 ] im2double: to double im2bw : to logical (binary)
Array indexing v=[1 3 5 7 9]; row vector w= v. ; column vector v(1:3) ----- 1 3 5 v(3:end) ----- 5 7 9 v(:) column vector v(1:end) row vector v(1:2:end) all odd components 1 5 9
v(end:-2:1) all odd components backwards 9 5 1 x = linspace(a, b, n); reshape changes size of matrix In general, RESHAPE(X,SIZ) returns an N-D array with the same elements as X but reshaped to the size SIZ. PROD(SIZ) must be the same as PROD(SIZE(X)).
Matrix indexing A=[1 2 3; 4 5 6; 7 8 9]; 3 x 3 matrix A(2, 3 ) ----- 6 C3 = A(:,3) yields 3rd column (column vector) R2 = A(2, : ) yields 2nd row (row vector) s= sum(a); column vector with sum of each row s= sum(a(:)); or sum(sum(a)) sum of entire matrix
Applications to Images fp = f(end:-1:1, :); flips image vertically (1 st index is columns) fc = f(257:768, 267:768); crops picture fs = f(1:2:end, 1:2,end) subsample
standard matrices zeros(m,n) M columns N rows ones (M, N ) true (M,N) false(m, N ) - rand (M,N) uniformly distributed in [0 1] randn(m,n) normally (Gaussian) distributed - mean 0 variance 1
m files filename.m created with text editor function body comments
function [s, p] = sumprod (f,g) where f,g are two images and s and p are their sum and product H1 is first text line. It is a single comment line help sumprod H 1 line for example: SUMPROD computes the sum and product of two images m files can be created with any text editor edit sumprod opens meditor editor
Arithmetic Operators A*B matrix multiplication A.*B element by element multiplication imadd adds 2 images imsubtract, immultiply,imdivide (element by element)
Relational Operators A==B gives 1 where the elements are the same and 0 otherwise > = gives 1 where the elementof A is larger than B otherwise 0 A&B gives 1 where the both elements are zero and 0 otherwise pi and i=sqrt(-1) are pre-defined
Flow Control if expression statements end for index=start:increment:end while expression statements end break switch expression case end
Loops Example: if (isinf (x) isreal (x) disp ( Bad input ) y = Nan; elseif (x==round (x) ) && (x>0) y = prod (1 : x-1) ; else y = gamma (x) ; end && ( logical AND ) ( logical OR) ( logical (NO
switch units case length disp ( meters ) case volume disp ( liters ) case time disp ( seconds ) otherwise di sp ( I give up ) end
x=1:100; s=0; for j=find (isprime (x) ) s = s+ x(j); end Finds sum of all primes less than 100 (alternativesum(find(iprime(1:100))); ) n=0 while x>1 x=x/2; n=n+1 i f ( n> 5 0, break, end end
Vectorization x=1:m f(x)=sin((x-1)/(2*pi)) [C,R] =meshgrid(c,r); rows of C are copies of c and columns of R are copies of r example r=[0 1 2] c=[0 1] h=r.ˆ2 + C.ˆ2yields 01 12 45 preallocate arrays f=zeros(1024);
Interactive I/O disp(a); displays matrix A on screen t=input( message ); n=str2num(t)