Download presentation
1
Lecture 27: Image Processing
2
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
3
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
4
Images in MATLAB • Binary images : {0,1} • Intensity images : [0,1] or uint8, 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)
5
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. Check pixel values Img(100, 150) Img(50:60, 120:125)
6
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 = im2bw(Img, level); bImg = Img >75; Add noise N = imnoise(Img, ‘gaussian’);
7
Image Processing Smoothing the image Invert an intensity image
K = wiener2(N); Invert an intensity image invImg = Img; invbImg = 1 - bImg; % inverts the binary image. Crop the image cImg = Imcrop(Img); cImg = Img(100:200, 150:240);
8
Image Processing Multiple-image display Write the image
subplot(1, 2, 1) subimage(Img) subplot(1, 2, 2) subimage(bImg) Write the image imwrite(invImg, ‘newImg.jpg’);
9
Image Processing Color images rgbImg = imread(‘disc.png’);
%store in a 3D matrix imshow(rgbImg) imshow(rgbImg(:, :, 1) gImg = (rgbImg(:,:,1)+rgbImg(:,:,2)+rgbImg(:,:,3))/3; %convert to grey-scale
10
Practice Question
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.