This lecture covers key MATLAB concepts for computer vision, including vectors, matrices, and built-in functions. Explore matrix operations such as point-by-point multiplication, square roots, and data manipulation techniques. Learn plotting for visualizing data, including sine and cosine curves, and 3D plots. Understand how digital images are represented and the importance of sampling and quantization. The session prepares students for an upcoming quiz on these essential topics.
01 / 74Introduction to MATLAB for Image Processing and Matrix Operations
1 / 17
Télécharger la présentation
Introduction to MATLAB for Image Processing and Matrix Operations
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
REMINDER: As stated on webpage: Quiz Thursday • MATLAB • Vectors and Matrices in MATLAB • Scripts and User Defined Functions • MATLAB Built-in Functions • Plotting • Data Classes • Basic image operations RS Gaborski
A Few Matlab Details • Scalar: Single number • Vector: Ordered list of numbers • May be a column or a row • Matrix: Rectangle array of number • Rows and Columns • Multidimensional Rows, Columns and Planes Example: Image(R.C,3) three planes, each R x C RS Gaborski
Matrix Operations • Point by Point Matrix Multiply =1*5 = 5 =2 * 6 = 12 Etc. .* = RS Gaborski
Another Example f * g vs f .* g >> f=[1 2;3 4]; g=[1 2; 2 1]; >> f .* g ans = 1 4 6 4 >> f=[1 2;3 4]; g=[1 2; 2 1]; >> f * g ans = 5 4 11 10 Element by Element True Matrix Multiply RS Gaborski
Calculating Square Root of Each Member of a Matrix Given the matrix C, calculate the square root of each member of the matrix (with LOOPS) >> [rows columns] = size(C); >> for r = 1:rows for c = 1:columns SqC(r,c) = sqrt(C(r,c)); end end >> SqC SqC = 1.0000 2.0000 1.4142 2.2361 1.7321 2.4495 2.0000 2.0000 C = 1 4 2 5 3 6 4 4 RS Gaborski
MATLAB Built-in Functions Rounds towards nearest integer, either up or down Rounds towards minus infinity Rounds towards positive infinity >> round(7.8) ans = 8 >> round (7.2) ans = 7 >> floor(7.8) ans = 7 >> ceil(7.8) ans = 8 >> sqrt(64) ans = 8 RS Gaborski
>> help linspace • LINSPACE Linearly spaced vector. • LINSPACE(X1, X2) generates a row vector of 100 linearly • equally spaced points between X1 and X2. • LINSPACE(X1, X2, N) generates N points between X1 and X2. • For N < 2, LINSPACE returns X2. • Class support for inputs X1,X2: • float: double, single • See also logspace, :. RS Gaborski
Sum, continued >> C (Defined on previous slide) C = 1 4 2 5 3 6 4 4 >> sumC = sum(C) sumC = 10 19 BUT: We want the sum of the matrix, not of the columns RS Gaborski
Sum, continued >> sumC = sum(sum(C)) sumC = 29 >> CC = C(:)(convert to column) CC = 1 2 3 4 4 5 6 4 >> sumC = sum(C(:)) sumC = 29 RS Gaborski
IMAGES:Sampling and Quantization • In the real world images are represented by continuous functions • Images are continuous in both in their spatial coordinates and amplitude • To create digital images must convert both the coordinates and the amplitude • Sampling: digitizing the coordinate values • Quantization: digitizing amplitude values RS Gaborski
Grayscale and Color Images • Grayscale refers to monochrome images • Color images are formed from combination of individual 2 D images • Common color images consists of three planes of data: red, green and blue • RGB is referred to as a color space • Other color spaces are also used, for example HSV (Hue, Saturation and Value) RS Gaborski
Digital Image • Has a finite number of spatial coordinates • 1200 x 1600 rows x columns • Rows M • Columns N • Image size is M x N • Has a finite number of amplitude levels • Typically 8 bits • Medical images: 12 bits • A digital camera image may have 1200 rows and 1600 columns and 256 ( 8 bits) levels of intensity for each color • 1200x1600x8x3 = 46,080,000 bits = 5,760,000 bytes RS Gaborski
MATLAB Matrix Representation • Image size is M x N • Origin is either (0,0) or (1,1) • MATLAB uses (1,1) as the original and refers to a spatial coordinate as (r,c) • Image has a range of: r=1to M and c=1 to N f(1,1) f(1,2) … f(1,N) f(2,1) f(2,2) … f(2,N) . . . f(M,1) f(M,2) … f(M,N) f = RS Gaborski
Reading Images in MATLAB >> help imread IMREAD Read image from graphics file. A = IMREAD(FILENAME,FMT) reads a grayscale or color image from the file specified by the string FILENAME, where the string FMT specifies the format of the file. See the reference page, or the output of the function IMFORMATS, for a list of supported formats. If the file is not in the current directory or in a directory in the MATLAB path, specify the full pathname of the location on your system. If IMREAD cannot find a file named FILENAME, it looks for a file named FILENAME.FMT. IMREAD returns the image data in the array A. If the file contains a grayscale image, A is a two-dimensional (M-by-N) array. If the file contains a color image, A is a three-dimensional (M-by-N-by-3) array. The class of the returned array depends on the data type used by the file format. RS Gaborski
Reading Images in MATLAB • imread(‘filename’) • At Command line: >> f = imread(‘chestxray.jpg’); The semicolon suppresses the output. Without the semicolon the output is displayed Without path information imread reads the image from the current directory, if not found, then searches the MATLAB search path Include path: >> f = imread(‘D:\images\chestxray.jpg’); RS Gaborski
Digital Image >> Size(f) ans = 1600 1200 3 Digital image: 1600 rows x 1200 columns x 3 planes Planes: red, green and blue (RGB) impixel() Pixel values: 1: 217 184 29 2: 108 93 90 3: 122 73 68 3 1 2 RS Gaborski
who >> whos A Name Size Bytes Class A 1600x1200x3 5760000 uint8 array Grand total is 5760000 elements using 5760000 bytes uint8 is a data class RS Gaborski
Displaying Images • imshow( f ) • f is image array • imshow( f, [ low high ] ) • Displays as black values less than low • Displays as white all values equal or greater than high • imshow( f, [ ] ) • Sets variable low to lowest value in f • Sets variable high to highest value in f RS Gaborski
IMPORTANT POINT • In the previous slides the data values for each image didn’t change, but how they were displayed did change. RS Gaborski
Writing Images to Disk- Syntax • Syntax: • imwrite( f, ‘filename’ ) string filename must contain file format extension imwrite( f, ‘xray1.tif’) OR, third input argument can specify format • imwrite( f, ‘xray1’, ‘tif’) RS Gaborski
Writing Images to Disk- Parameters • imwrite(f, ‘filename.jpg’, ‘quality’, q) • jpg (jpeg) are compressed images • There is a trade off between file size (degree of compression) and image quality • Highly compressed images have small file sizes, but poorer image quality • q is an integer between 0 and 100 • Smaller numbers result in more compression RS Gaborski
Data Classes • Eight numeric data classes • One character class • One logical class • All numeric operations in MATLAB are done using double quantities • Class uint8 is common in reading data from devices RS Gaborski
help class help class CLASS Return class name of object. S = CLASS(OBJ) returns the name of the class of object OBJ. Possibilities are: double -- Double precision floating point number array (this is the traditional MATLAB matrix or array) single -- Single precision floating point number array logical -- Logical array char -- Character array cell -- Cell array struct -- Structure array function_handle -- Function Handle int8 -- 8-bit signed integer array uint8 -- 8-bit unsigned integer array int16 -- 16-bit signed integer array uint16 -- 16-bit unsigned integer array int32 -- 32-bit signed integer array uint32 -- 32-bit unsigned integer array int64 -- 64-bit signed integer array uint64 -- 64-bit unsigned integer array RS Gaborski
Converting Between Data Classes • B = data_class_name(A) where data_class_name is from first column of Table 2.2 • If A is an array of class uint8. Can generate a double precision array B by command: B = double(A); RS Gaborski
Example >> A = imread(''image20.JPG''); >> whos A Name Size Bytes Class Attributes A 640x480x3 921600 uint8 640 rows, 480 columns and three planes of data Data class uint8 RS Gaborski
Connexion au compte
Connectez-vous pour publier votre contenu sur SlideServe.