Professional Documents
Culture Documents
Lab- 1
Introduction
MatLab : Matrix Laboratory Numerical Computations with matrices Every number can be represented as matrix Why Matlab? User Friendly (GUI) Easy to work with Powerful tools for Complex Computations, including: linear algebra, data analysis, signal processing, polynomials and interpolation, numerical integration (quadrature), and numerical solution of differential equations It has Graphics, in 2-D and 3-D, including color, lighting, and animation It has collections of specialized functions, called DIP toolboxes, that extend its functionality.
Workspace
Command Window
Matrices in Matlab
To enter a matrix
1 2 3 4 5 6 7 8 9 >> A = [1 2 3 ; 4 5 6; 7 8 9]; or >> A = [1, 2, 3 ; 4, 5, 6; 7, 8, 9]; [Try to look at imshow(A)] >> B = [3, 5 ; 0, 2] Basic Mathematical Operations
Addition: >> C = A + B Subtraction: >> D = A B Multiplication: >> E = A * B (Matrix multiplication) >> E = A .* B (Element wise multiplication) Division: >> F = A . / B (Element wise division) >> F = A / B (A * inverse of B) >> F = A . \ B (Element wise division) >> F = A \ B (inverse of A * B)
IDENTITY Matrix:
>> I = EYE (r, c) r Rows c Columns zeros, ones, eye Matlab functions
Images in MATLAB
MATLAB can import/export several image formats
BMP (Microsoft Windows Bitmap) GIF (Graphics Interchange Files) HDF (Hierarchical Data Format) JPEG (Joint Photographic Experts Group) PCX (Paintbrush) PNG (Portable Network Graphics) TIFF (Tagged Image File Format) XWD (X Window Dump) MATLAB can also load raw-data or other types of image data Double (64-bit double-precision floating point) Single (32-bit single-precision floating point) Int32 (32-bit signed integer) Int16 (16-bit signed integer) Int8 (8-bit signed integer) Uint32 (32-bit unsigned integer) Uint16 (16-bit unsigned integer) Uint8 (8-bit unsigned integer)
I is r x c if gray scale I is r x c x 3 if color image (RGB) imshow(I) % displays image imwrite(I, filename.xyz) % writes image
Size of image
[r c] = size(I)
Examples:
>> I=imread(greens.jpg'); >> imshow(I) >> size(I) ans = 300 500 3 (RGB image) >> Igray = rgb2gray(I); >> imshow(Igray) >> imwrite(lgray, greens_gray.tif', 'tiff')