1 / 70

Images and MATLAB

Images and MATLAB. Matlab Advantages. Every variable in Matlab is a multidimensional matrix. Highly modular. No memory allocation is necessary. Matlab enables its own garbage collection. Simple interface for complex mathematical concepts. Image Types.

zeroun
Download Presentation

Images and MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Images and MATLAB

  2. Matlab Advantages • Every variable in Matlab is a multidimensional matrix. • Highly modular. • No memory allocation is necessary. • Matlab enables its own garbage collection. • Simple interface for complex mathematical concepts.

  3. Image Types • Intensity imagesscaled to represent intensities (uint8 – [0,255], double [0,1]) • Binary imageslogical array of 0s and 1s • Indexed imagesLook up table [x, map] • RGB imagestruecolor, array of (m*n*3) Checking the image type : isind, isbw, isgray, isrgbConverting image types: rgb2ind, rgb2gray, gray2ind, ind2gray,….

  4. Data Classes Converting between types : B = data_class_name(A)for example: B = double(A)

  5. Conversions • When converting between data classes and types it is important to keep the value range for each data class >> img = double(img)/255; >> img = im2double(img);

  6. MATLAB supported image formats • JPEG: Joint Photographics Experts Group • TIFF: Tagged Image File Format • GIF: Graphics Interchange Format • BMP: Microsoft Bitmap Format • PNG: Portable Network Graphics • …

  7. Displaying an image(cont.) • Spatial domain

  8. Matlab Basics • Digital image representation : 2D function f(x,y) -> finite discrete quantities • Coordinate Conventions img(r,c)r – rows (height)c – cols (width) • The first pixel:img(1,1)

  9. Matlab 內建影像 • C:\MATLAB7\toolbox\images\imdemos • 皆為Matlab Help中範例的原始影像。 • 使用時只需直接在指令中輸入檔名,即可使用。 • 適用於觀察影像處理結果

  10. Different Image Types • Indexed images • Intensity (grayscale) images • Binary images • RGB (true-color) images

  11. Reading an image • imread() • 功用:將影像載入並存成array格式備用 • 用法:[I,map] = imread(filename); I = imread(filename); ex: I = imread('pout.tif'); I為指向影像的變數 不指定變數,則為ans

  12. Displaying an image • imshow() • 功用:開啟一個視窗顯示影像 用法: imshow(I) imshow(I,map) • Figure, imshow() 功用:開啟一個新視窗顯示影像 用法: figure,imshow(I)

  13. Displaying an image(cont.) • imshow(I, [low, high]) • imshow(I, [ ]) 功用:displays I as a grayscale intensity image, specifying the data range for I. The minimum value in I is displayed as black, and the maximum value is displayed as white. • pixval : 功能:cursor on image to show pixel values 用法: imshow(I),pixval

  14. Displaying an image(cont.) • colorbar • 功能:To display an image with a colorbar that indicates the range of intensity values. • 用法: imshow(I), colorbar ex: I = imread('pout.tif'); imshow(I) , colorbar

  15. Writing an image • imwrite() • 功能:將影像寫入成檔案 • 用法: imwrite(I,filename,format) ex: imwrite(I,'pout.jpg','JPEG');

  16. Image information • Image size: size() ex: I= imread('saturn.png'); size(I) [M,N] = size(I) M=影像I的高 N=影像I的寬

  17. Image information • whos 功用:display information about an image . • ex: whos I • Imfinfo( filename ) 功用: display information about image file . • ex: info = imfinfo('saturn.png')

  18. Digital Image processing • 影像二元化 • g = im2bw(I, T); • 功用:Convert intensity image I to binary image g using threshold T, where T must be in range [0, 1]. ex: I= imread('pout.tif'); g = im2bw(I, 0.4); imshow(g); colorbar

  19. Digital Image processing(cont.) • 彩色轉灰階 • Rgb2gray() • 功用:將RBG彩色影像轉換成gray-level影像。ex: I2= imread ('onion.png'); figure,imshow(I2); colorbar g2 = rgb2gray(I2); figure,imshow(g2); colorbar

  20. Digital Image processing(cont.) • 反相 • imcomplement( ) • 功用:The negative of an image. ex: I2= imread ('onion.png'); figure,imshow(I2); colorbar J2 = imcomplement(g2); figure, imshow(J2); colorbar

  21. Grayscale images 灰階影像 • Matlab example: • w=imread('pout.tif'); • figure, imshow(w), pixval on • figure: create a window to place graphic object • imshow: display matrix • Data type of w? • 291x240 uint8 (unsigned integer 8 bits

  22. Binary image 二元影像 • Matlab example: • w2=imread('circles.png'); • figure, imshow(w2), pixval on • Data type of w? • 256x256 logical • Pixel value is 0 or 1

  23. RGB (true color) images 全彩影像 • Matlab example: • w3=imread('peppers.png'); • figure, imshow(w3), pixval on • size(w3) • w3(100,200,2) • w3(100,200,1:3) • w3(100,200,:)

  24. RGB color model

  25. Pixel depth • Pixel depth: the number of bits used to represent each pixel in RGB space • Full-color image: 24-bit RGB color image • (R, G, B) = (8 bits, 8 bits, 8 bits)

  26. Indexed color image 彩色索引影像 • Matlab example: • wI=imread('trees.tif'); • figure, imshow(w), pixval on • What’s wrong?

  27. Indices Color Map

  28. Indexed color image • Matlab example: • [wI,wmap]=imread('trees.tif'); • figure, imshow(wI, wmap) • How do we know it’s an indexed image?

  29. Indexed color image 彩色索引影像 • Matlab example: • w=imread(‘emu.tif’); • figure, imshow(w), pixval on • What’s wrong?

  30. 0.1211 0.1211 0.1416 0.1807 0.2549 0.1729 0.2197 0.3447 0.1807 0.1611 0.1768 0.1924 0.2432 0.2471 0.1924 0.2119 0.1963 0.2002 6 10 15 12 5 11 20 10 4 6 10 7 … indices Color map Indexed color image

  31. Indexed color image • Matlab example: • [w,wmap]=imread(‘emu.tif’); • imshow(w, wmap) • How do we know it’s an indexed image?

  32. Get information about image • imfinfo('emu.tif'); Filename: 'emu.tif' FileModDate: '12-Jul-2004 11:40:00' FileSize: 119804 Format: 'tif' FormatVersion: [] Width: 331 Height: 384 BitDepth: 8 ColorType: 'indexed' ByteOrder: 'little-endian' NewSubfileType: 0 BitsPerSample: 8 Colormap: [256x3 double]

  33. Get information about image • imfinfo(‘emu.tif’); Filename: 'emu.tif' FileModDate: '12-Jul-2004 11:40:00' FileSize: 119804 Format: 'tif' FormatVersion: [] Width: 331 Height: 384 BitDepth: 8 ColorType: 'indexed' ByteOrder: 'little-endian' NewSubfileType: 0 BitsPerSample: 8 Colormap: [256x3 double]

  34. Data types and conversion • uint8 image must be converted to double before any arithmetic operation • w=imread('pout.tif'); • w=w+1; % fail • w=double(w); % data type is also conversion func. • w=w+1; % ok

  35. Write image matrix to file • Matlab code • w=imread('pout.tif'); • imwrite(w, 'pout.jpg','jpg'); • General form • imwrite(X, map, ‘filename’, ‘format’);

  36. Zooming and Shrinking Digital Images • Zooming: • Create a new pixel location. • Assign a gray-level to those new locations • Nearest neighbor interpolation • Pixel replication: a checkboard effect • Bilinear interpolation using four nearest neighbors • v(x’, y’)=ax’+by’+cx’y’+d • where a, b, c, and d are determined from the gray-level of the four neighbors. • Shrinking: • Direct shrinking causes aliasing • Expansion then Shrinking: blurring the image before shrinking it and reduce aliasing.

  37. Sampling Methods of Inverse Mapping • If transformed pixel ‘X’ locates among • P1, P2, P3 and P4 • Nearest neighbor method: • I(‘X’) = I(P3 ) • where I(p) is the intensity value of pixel p • Bi-linear interpolation: I(‘X’) = (1-a)(1-b)I( P1 ) + a(1-b)I(P2 ) + (1-a)bI(P3 )+ abI(P4 ) where a, b are the fractional parts of ‘X’ • Bi-cubic interpolation: based on cubic splines P2 P1 P3 P4

  38. Nearest neighbor interpolation • The closest neighbor is chosen , by rounding the “new” indexes to original image’s coordinates .

  39. Digital Image processing(cont.) • 變更影像大小 • imresize(I,scale,method); • 功用:To change the size of an image. • interpolation Method: -'nearest‘ :Nearest-neighbor interpolation -'bilinear‘ :Bilinear (the default) -'bicubic‘ :Bicubic interpolation

  40. Digital Image processing(cont.) • 變更影像大小 • imresize(I,scale,method); • 功用:To change the size of an image. • interpolation Method: -'nearest‘ :Nearest-neighbor interpolation -'bilinear‘ :Bilinear (the default) -'bicubic‘ :Bicubic interpolation

  41. Digital Image processing(cont.) • ex: I3 = imread('circuit.tif'); J3 = imresize(I3,1.25); figure, imshow(I3) figure, imshow(J3) • ex: I3 = imread('circuit.tif'); J4= imresize(I3,[100 150], 'bilinear'); figure, imshow(I3) figure, imshow(J4)

  42. Digital Image processing(cont.) • 旋轉影像 • imrotate(I, angle); • 功用:To rotate an image. • ex: I = imread('pout.tif'); J5 = imrotate(I,35); figure, imshow(J5)

More Related