Digital Image Processing Using MATLAB Introduo ao Matlab
Digital Image Processing Using MATLAB® Introdução ao Matlab © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Lendo imagens: f = imread (‘filename’), lê a imagem do arquivo para a matriz f. © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Exemplos de comandos em Matlab para ler uma imagem e obter informações: >> f = imread(‘Fig 0222(a)(face). tif’); >> size(f) >> [M N] = size(f) >> whos f >> figure, imshow(f, ‘Initial. Magnification’, ‘fit’); >> imwrite(f, ‘teste. tif’); M- function : function [output] = function_name(input) Exemplo : cria_imagem(x, y, filename) © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Sintaxe geral para imwrite(): imwrite(f, filename, ‘compression’, ‘parameter’, ‘resolution’, [colres, rowres] ); parameter: none – sem compressão packbits – default para imagens não binárias ccitt – default para imagens binárias [colres, rowres]: resolução na coluna e resolução na linha © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Considere uma imagem de 450 x 450 pixels a 200 dpi 2. 25 x 2. 25 inches. Queremos esta imagem em formato tif, sem compressão, com o mesmo numero de pixels e tamanho 1. 5 x 1. 5 inches: res = round(200*2. 25/1. 5) = 300; imwrite(f, ‘sf. tif’, ‘compression’, ‘none’, ‘resolution’, res); © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Obtendo informações sobre a imagem: >> imfinfo filename >> k = imfinfo(‘filename’); >> Xres = k. Xresolution © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Classes de dados: © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Tipos de imagens: imagens em tons de cinza; imagens binarias imagens indexadas imagens RGB © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Imagens em tons de cinza -é uma matriz de dados cujos valores representam níveis de cinza; - class unit 8 >> [0, 255] - class unit 16 >>[0, 65535] - class double >> [0, 1] f = [0 0 0 0; 0. 5 0. 5; 0. 5]; fg = im 2 uint 8(f); imshow(fg, ‘Initial. Magnification’, ‘fit’); © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab ff = rand(10, 10) ff = 0. 8147 0. 9058 0. 1270 0. 9134 0. 6324 0. 0975 0. 2785 0. 5469 0. 9575 0. 9649 0. 1576 0. 9706 0. 9572 0. 4854 0. 8003 0. 1419 0. 4218 0. 9157 0. 7922 0. 9595 0. 6557 0. 0357 0. 8491 0. 9340 0. 6787 0. 7577 0. 7431 0. 3922 0. 6555 0. 1712 0. 7060 0. 0318 0. 2769 0. 0462 0. 0971 0. 8235 0. 6948 0. 3171 0. 9502 0. 0344 © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins 0. 4387 0. 3816 0. 7655 0. 7952 0. 1869 0. 4898 0. 4456 0. 6463 0. 7094 0. 7547 0. 2760 0. 6797 0. 6551 0. 1626 0. 1190 0. 4984 0. 9597 0. 3404 0. 5853 0. 2238 0. 7513 0. 2551 0. 5060 0. 6991 0. 8909 0. 9593 0. 5472 0. 1386 0. 1493 0. 2575 0. 8407 0. 2543 0. 8143 0. 2435 0. 9293 0. 3500 0. 1966 0. 2511 0. 6160 0. 4733 0. 3517 0. 8308 0. 5853 0. 5497 0. 9172 0. 2858 0. 7572 0. 7537 0. 3804 0. 5678 0. 0759 0. 0540 0. 5308 0. 7792 0. 9340 0. 1299 0. 5688 0. 4694 0. 0119 0. 3371 www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab g = im 2 unit 8(ff) g= 208 231 32 233 161 25 71 139 244 246 40 248 244 124 204 36 108 234 202 245 167 9 217 238 173 193 189 100 167 44 180 112 70 192 214 90 19 8 97 173 65 65 212 14 71 195 167 129 208 149 135 12 203 41 178 62 140 199 25 48 30 227 234 238 210 125 127 245 89 73 33 177 114 245 140 50 193 145 81 165 87 35 64 192 120 242 181 149 38 157 97 3 9 192 57 66 121 145 86 Imshow(g, ’Initial. Magnification’, ’fit’); © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab bw = im 2 bw(g, 0. 5); T = threshold no intervalo [0, 1] bw = 1 1 0 0 1 1 1 0 1 0 0 1 1 0 0 0 1 1 1 0 0 0 1 0 © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins 1 0 1 1 1 0 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 0 0 www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Vetores (primeiro elemento é v(1)) definiçao de um vetor v = [1 3 5 7]; acesso ao 2º. elemelnto v(2) = 3; transposta de v w = v. ’ acesso a blocos v(1: 3) = 1 3 5; v(3: end) = 5 7; v(1: 2: end) = 1 5 v(end: -2: 1) = 7 3 gera vetor linearmente espaçado x = linspace(1, 10, 5) = 1. 0000 3. 2500 5. 5000 7. 7500 10. 0000 © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Matrizes ( primeiro elemento é mat(1, 1)) Cria matriz A = [1 2 3; 4 5 6; 7 8 9]; Acesso a um elemento A(2, 3) = 6; A(end, end) = 9 Acesso a uma coluna C = A(: , 3); Acesso a uma linha L = A(2, : ) = 4 5 6 Acesso a um bloco B = A(1: 2, 1: 3) = 1 2 3 456 © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Acesso a blocos A(2: end, end: -2: 1) = 6 4 97 arranja uma matriz na forma de vetor , coluna por coluna A(: ) = [1 4 7 2 5 8 3 6 9]t rebate matriz A(end: -1: 1, : ) © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab Exemplo: modifica_lena. m © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
Digital Image Processing Using MATLAB® Introdução ao Matlab gera_seno_vetorv 1(Ampli, tudo M, frequencia) gera_seno_vetorv 1(1, 512, 1/(4*pi)); f = gera_seno_2 d(1, 1/(4*pi), 512); © 2004 R. C. Gonzalez, R. E. Woods, and S. L. Eddins www. imageprocessingbook. com
- Slides: 26