110 likes | 235 Views
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.
E N D
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 • 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
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)
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)
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’);
Image Processing • Smoothing the image K = wiener2(N); • Invert an intensity image invImg = 255 - Img; invbImg = 1 - bImg; % inverts the binary image. • Crop the image cImg = Imcrop(Img); cImg = Img(100:200, 150:240);
Image Processing • Multiple-image display subplot(1, 2, 1) subimage(Img) subplot(1, 2, 2) subimage(bImg) • Write the image imwrite(invImg, ‘newImg.jpg’);
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