Lecture 27 Image Processing Images in MATLAB An

Lecture 27: Image Processing

Images in MATLAB An image in MATLAB is treated as a matrix Every pixel is a matrix element All the operators in MATLAB defined on matrices can be used on images: +, -, *, /, ^, sqrt, sin, cos etc

Images in MATLAB can import/export several image formats n BMP (Microsoft Windows Bitmap) n GIF (Graphics Interchange Files) n HDF (Hierarchical Data Format) n JPEG (Joint Photographic Experts Group) n PCX (Paintbrush) n PNG (Portable Network Graphics) n TIFF (Tagged Image File Format) n XWD (X Window Dump) n MATLAB can also load raw-data or other types of image data

Images in MATLAB • • • Binary images : {0, 1} Intensity images : [0, 1] or uint 8, double etc. RGB images : m-by-n-by-3 Indexed images : m-by-3 color map Multidimensional images m-by-n-by-p (p is the number of layers)

Read and Display an Image Read in an image Img = imread(‘wholeimg. png’); Display an image imshow(Img) Check the image storage information whos See how wholeimg. png is stored into the MATLAB workspace. n Check pixel values Img(100, 150) Img(50: 60, 120: 125) n

Image Processing Histogram - display histogram of image data imhist(Img) Change a gray image into a binary image level = graythresh(Img) Computes a global threshold that can be used to convert an intensity image to a binary image. BW = im 2 bw(Img, level); b. Img = Img >75; Add noise N = imnoise(Img, ‘gaussian’);

Image Processing Smoothing the image K = wiener 2(N); Invert an intensity image inv. Img = 255 - Img; invb. Img = 1 - b. Img; % inverts the binary image. Crop the image c. Img = Imcrop(Img); c. Img = Img(100: 200, 150: 240);

Image Processing Multiple-image display subplot(1, 2, 1) subimage(Img) subplot(1, 2, 2) subimage(b. Img) Write the image imwrite(inv. Img, ‘new. Img. jpg’);

Image Processing Color images rgb. Img = imread(‘disc. png’); %store in a 3 D matrix imshow(rgb. Img) imshow(rgb. Img(: , 1) g. Img = (rgb. Img(: , 1)+rgb. Img(: , 2)+rgb. Img(: , 3))/3; %convert to grey-scale

Practice Question
- Slides: 10