You are on page 1of 8

Mekelle Institute of Technology

Digital Image Processing


(CSE502 CrHr)

Department of Computer Science and Engineering

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.

Snap shot of matlab

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)

Generating basic matrices


Matrix with ZEROS:
>> Z = ZEROS (r, c)

Matrix with ONES:


>> O = ONES (r, c)

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)

Data types in MATLAB


Image processing Toolbox and MatLab


MatLab is easy to work with Images; as Images are matrices MatLab has Built in functions for complex operations and algorithms. Image processing tool box: Is a collection of functions that extend the capability of the MATLAB numeric computing environment. It supports a wide range of image processing operations, including: Spatial image transformations Morphological operations Neighborhood and block operations Linear filtering and filter design Transforms Image analysis and enhancement Image registration De-blurring Region of interest operations

To read and display images


I = imread(filename.xyz)

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')