Docsity

Image Processing - Fundamental Programming Concepts - Lecture Slides, Slides of Computer Programming

Partial preview of the text

Download Image Processing - Fundamental Programming Concepts - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

Today is Lena Day

Colors, RGB

Image files

MATLAB Demos

Pixel and Bitmaps

Pixel = Picture Element

Bitmaps store color information of pixels

Anatomy of Files

Text Files vs. Binary Files

Example Text files:

.txt (plain), .html (markup)

Example Binary files:

.exe .bmp .png .zip

X-raying Binary Files

Use hexdump

File formats

File headers

MATLAB Image Formats

imformats

shows information about the image formats MATLAB can

work on

imfinfo

shows information related to an image file

Reading Image Files

imread

reads an image file and returns image data in an array

Usage

% A = imread(FILENAME, FORMAT)

data = imread('lena.png','png');

[Red, Green, Blue] Lena

l = imread('lena.png');

r = l; r(:,:,2:3) = 0; figure imshow(r)

g = l; g(:,:,1:2:3) = 0; figure imshow(g)

b = l; b(:,:,1:2) = 0; figure imshow(b)

[Red, Green, Blue] Lena

Converting to Gray Scale

Writing Image Files

imwrite

writes the image to a file

Usage

% imwrite(A, FILENAME, FORMAT)

imwrite(data, 'lena gray.png', 'png');

Applying the Filter

function pdata = filter lena(fname, fmt, F) data = imread([fname,'.',fmt], fmt); [n m c] = size(data); pdata = zeros(n,m,c); ddata = double(data); %convert from uint8 to double % ignoring a thin frame around the picture for i = 2:n− 1 % move to the next row for j = 2:m− 1 % move to the next column for k = 1:3 % apply the filter to all 3 layers pdata(i,j,k) = ... sum(sum(F .* ddata(i−1:i+1, j−1:j+1, k))); end end end pdata = uint8(floor(pdata)); %convert back to uint imwrite(pdata, [fname,' filtered.',fmt], fmt);

Applying the Filter

Fa = ones(3)/9; Fb = ones(3)/5; Fb([1 3],[1 3]) = 0;

I = imread('lena.png'); Ia = filter lena('lena','png',Fa); Ib = filter lena('lena','png',Fb);

subplot(1,3,1); imshow(I) subplot(1,3,2); imshow(Ia) subplot(1,3,3); imshow(Ib)

Edge Detection

Fx =

 Fy =

Dx = Fx. ∗ I Dy = Fy. ∗ I |∇I | =

D x^2 + D y^2

Edge Detection