Loading in 5 sec....

Introduction to Computer VisionPowerPoint Presentation

Introduction to Computer Vision

- 91 Views
- Uploaded on
- Presentation posted in: General

Introduction to Computer Vision

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Lecture 3

Dr. Roger S. Gaborski

Roger S. Gaborski

- In Class Exercise Today – end of class

Roger S. Gaborski

- Homework #1 Assigned
- Due March 19th at 8am
- Orange Flower image available on course webpage
- Late homework – Emailed by 8am the day after it is due -25%. (In this case, by 8am March20th. )

Roger S. Gaborski

- Image displaying
- Image types
- Image adjustment
- Gamma transformation
- Logarithmic transformation

- Component segmentation
- Histogram distribution

Roger S. Gaborski

>> ls *jpg

OrangeFlower.jpgPatternOne.jpg

>> I = imread('OrangeFlower.jpg');

>> whos I

Name Size Bytes Class Attributes

I 1880x2816x3 15882240 uint8

Roger S. Gaborski

>> mx = max(I(:))

mx =

255

>> mn = min(I(:))

mn =

0

Roger S. Gaborski

- Consider we would like to display a gray level image that has a possible range of values 0-255
- When we display the image we can arrange for each gray level value to be displayed as a different light level on the display
- Black would map to the gray level 0, white would map to the gray level 255.
- Gray level values between 0 and 255 would map to shades of gray.

Roger S. Gaborski

Roger S. Gaborski

- The gray level of images can also be represented by real value numbers between 0 and 1.
- 0 represents pixels that are black, 1 represents pixels that are white.
- Values between 0 and 1 represent gray level values.

Roger S. Gaborski

im = uint8([0 50 100; 100 125 200; 200 250 275])

im is of type uint8.

What values are min and max values contained in im ?

What is the ‘shape’ of variable im?

Roger S. Gaborski

im = uint8([0 50 100; 100 125 200; 200 250 275])

im is of type uint8.

What values are contained in im ?

>> im

im =

0 50 100

100 125 200

200 250 255

im is a 3x3 matrix

Roger S. Gaborski

>> figure, imshow(im, 'InitialMagnification' ,'fit')

>> title('im')

What is contrast?

Roger S. Gaborski

- The maximum range of values is [0,1] or [0,255] (for 8 bit images)
- It is possible for images to use the maximum range of gray level values, or a subset of possible values
- An image may only contain values between 0 and 0.6, or 0.3 and 0.9
- Is the contrast the same? How does the appearance differ?

Roger S. Gaborski

>> A = [.14 .15 ; .16 .17]

A =

0.1400 0.1500

0.1600 0.1700

>> figure, imshow(A, 'InitialMagnification' ,'fit')

Roger S. Gaborski

Roger S. Gaborski

The data in A didn’t change, only the display

Roger S. Gaborski

Change Actual Data Values:

mat2gray Convert matrix to intensity image.

I = mat2gray(A,[AMIN AMAX]) converts the matrix A to the

intensity image I.

The returned matrix I contains values in the range 0.0 (black)

to 1.0 (full intensity or white).

AMIN and AMAX are the values in A that correspond to 0.0 and

1.0 in I. Values less than AMIN become 0.0, and values

greater than AMAX become 1.0.

I = mat2gray(A) sets the values of AMIN and AMAX to the

minimum and maximum values in A.

Roger S. Gaborski

>> A

A =

0.1400 0.1500

0.1600 0.1700

>> A1 = mat2gray(A)

A1 =

0 0.3333

0.6667 1.0000 (Range is [0,1])

Roger S. Gaborski

B =

0 0.5000

5.0000 10.0000

>> B1 = mat2gray(B)

B1 =

0 0.0500

0.5000 1.0000 (Range is [0,1])

Roger S. Gaborski

C =

-10.0000 0.5000

5.0000 10.0000

>> C1 = mat2gray(B)

C1 =

0 0.5250

0.7500 1.0000

The original range is -10 to +10

mat2gray converts the range to

0 to +1

Roger S. Gaborski

>> Q=uint8([55, 100, 22])

Q =

55 100 22

>> whos Q

Name Size Bytes Class Attributes

Q 1x3 3 uint8

>> Qd = double(Q)

What is the value of Qd?

Roger S. Gaborski

>>> Qd = double(Q)

Qd =

55 100 22

>> whos Q Qd

Name Size Bytes Class Attributes

Q 1x3 3 uint8

Qd 1x3 24 double

>> Qid = im2double(Q)

What is the value of Qid?

Roger S. Gaborski

>> Qid = im2double(Q)

Qid =

0.2157 0.3922 0.0863

>> whos

Name Size Bytes Class Attributes

Q 1x1 1 uint8

Qd 1x1 8 double

Qid 1x1 8 double

Roger S. Gaborski

>>> Qd = double(Q)

Qd =

55 100 22

>> im2double(Qd) = ??????

Roger S. Gaborski

im2double(Qd) (Qd is already type double, no change)

ans =

55 100 22

Roger S. Gaborski

- Intensity images
- When elements are class uint8 or uint16 they have integer values in the range [0 255] or [0 65535]
- When elements are class double values are floating point numbers. Values are scaled in the range [0 1] by convention
- Pixels with value 0.0 are displayed as black
- Pixels with value 1.0 are displayed as white

- Binary images
- RGB images
- Indexed images

Roger S. Gaborski

>> Im = imread('Flag.jpg');

>> whos I

Name Size Bytes Class Attributes

Im 320x240 76800 uint8 % Image is of class uint8,

>> >> max(Im(:))

ans = 255

>> min(Im(:))

ans = 0 Range 0 to 255 (uint8)

>> Im1 = im2double(Im); % Convert to class double

>> max(Im1(:))

ans = 1

>> min(Im1(:))

ans = 0 Range now 0 to 1 (im2double)

which is default format of images read from disk

Roger S. Gaborski

>> Flag= im2double(imread(‘flag.jpg’));

>> figure, imshow(Flag), title(‘flag’);

Extract a Region of the Image

>> imRegion = imcrop(Flag);

>> figure, imshow(imRegion), title('imRegion')

>> size(imRegion)

ans =

321 321 3

>> imshow(imRegion(:, :, 1)), title(‘RED’);

>> imshow(imRegion(:, :, 2)), title(‘GREEN’);

>> imshow(imRegion(:, :, 3)), title(‘BLUE’);

Row of Data (red, green and blue)

imshow(Im) imshow(Im)

uint8 im2double(I)

Roger S. Gaborski

>> Im2 = Im1*2 +1;

>> min(Im2(:))

ans = 1

>> max(Im2(:))

ans = 3

>> figure, imshow(Im2)

Roger S. Gaborski

Reason: image Im2 is double class, which has the displaying range of [0, 1].

Range of image Im2: [1, 3]

So all pixels are displayed as white.

Roger S. Gaborski

imshow(Im2, [min(Im2(:)), max(Im2(:))])

imshow(Im2, [ ])

Roger S. Gaborski

- Intensity images
- Binary images
- A logical array of 0s and 1s
- An array of 0s and 1s that are of type uint8 is NOT a binary image
- If A is a numeric array of 0s and 1s can create a logical array B using statement:
B = logical(A) (all non zero values converted to 1s, entries with value 0 converted to logical 0s

- RGB images
- Indexed images

Roger S. Gaborski

>> BW = imread('circles.png');

>> whos BW

Name Size Bytes Class Attributes

BW 256x256 65536 logical

>> imshow(BW)

Roger S. Gaborski

- Intensity images
- Binary images
- RGB images
- RGB color image is an MxNx3 array of color pixels
- Each pixel is a triplet corresponds to the red, green and blue components at a specific spatial location
- Can be interpreted as 3 planes of gray scale images fed into red, green and blue inputs of a color monitor
- Class double, range of values [0,1]
- Class uint8 or uint16 ranges are [0 255], [0 65535]

- Indexed images

Roger S. Gaborski

Chapter 2 – Fundamentals

www.prenhall.com/gonzalezwoodseddins

Roger S. Gaborski

- Intensity images
- Binary images
- RGB images
- Indexed images
- Two components: data matrix of integers, X, and a color map matrix, map
- Map matrix is an mx3 array of class double floating point numbers in the range [0,1]
- m is the number of colors defined for the image
- Each row of m specifies the r,g and b components of a single color
- Example: imshow(X,map)

Roger S. Gaborski

- Indexed images
- Indexed images use a direct mapping of pixel intensities to color map values
- Color of each pixel is determined by using the corresponding values of integer matrix X as a pointer into map
- If X is class uint8 or uint16 then all components with value 0 point to first row of map, value of 1 point to second row

Roger S. Gaborski

Chapter 2 – Fundamentals

www.prenhall.com/gonzalezwoodseddins

Roger S. Gaborski

- Image Enhancement
- Brightness mapping
- Contrast stretching/enhancement
- Histogram modification
- Noise Reduction

- Mathematical Techniques
- Convolution
- Filtering

- Edge and Line Detection and Extraction
- Region Segmentation
- Contour Extraction
- Corner Detection
- Higher Level Features

Roger S. Gaborski

- Intensity – modify each pixel in the image independent of its neighbors
- Spatial – modify a pixel as a function of its neighbors (spatial convolution)

Roger S. Gaborski

Roger S. Gaborski

Roger S. Gaborski

If you look at a pixel of an intensity (gray level image- Next Slide) in isolation what can you tell me about the image?

The brightness or intensity value at that spatial location

Roger S. Gaborski

Roger S. Gaborski

Depends on the neighborhood

Sky Region Flag Region (2 rows, 3 columns)

The ‘flag region’ contains more information about the image

– There is a horizontal line in this region

Roger S. Gaborski

Can we modify the intensity values to change the image (improve in some way) or extract information from the image (edges, shapes, etc.)?

Roger S. Gaborski

- The general spatial domain processing equation:
g(x, y) = T [ f (x, y)]

- f (x, y) is the input image
- g(x, y) is the output image
- T is an operator on f defined over a specific neighborhood

Roger S. Gaborski

Chapter 3

www.prenhall.com/gonzalezwoodseddins

- Define spatial neighborhood about a point, (x, y)

- Neighborhood is typically a square or rectangle, but could be other shapes

- Center of neighborhood is moved from pixel to pixel starting at the upper left hand corner of the Image

- Operator T is applied at each location (x, y) to yield g(x, y) at that location

Roger S. Gaborski

- Let the neighborhood be reduced to a size of 1 x 1 pixel
- Now the transformation is only a function of the pixel itself.
- This is commonly called an intensity transformation or gray level transformation function:
s = T(r)

where r is the intensity of f at (x, y) and s is the resulting intensity of g at (x, y)

Roger S. Gaborski

- Assume the range of pixel intensity values is [0,1]
- What can be accomplished with transformation T ?

Roger S. Gaborski

>> R = rand([1 4])

R =

0.0272 0.7937 0.9992 0.1102

>> R2 = R .* R ( note .* and not simply * )

R2 =

0.0007 0.6299 0.9985 0.0122

(small numbers are much smaller)

>> RSR = sqrt(R)

RSR =

0.1649 0.8909 0.9996 0.3320

Roger S. Gaborski

R = rand(1, 4) R2 = R .* R RSR = sqrt(R)

In this case the data is actually changed

Not the only display as in previous lecture

Roger S. Gaborski

- Characteristics:
- y = x2: all pixels become darker
- y = sqrt(x): all pixels become brighter
- y = x: all pixels remain the same value

Output (y)

Input (x)

Roger S. Gaborski

- Function imadjust
- intensity transformation of gray scale images

- g = imadjust( f, [low_in high_in], [low_out, high_out], gamma)
- Input - output defined in [0,1] range:
- [low_in high_in] [0 1] (min max)
- [low_out high_out] [0 1] (min max)

- Input - output defined in [0,1] range:

Roger S. Gaborski

- Characteristics:
- gamma >1: all pixels become darker
- gamma <1: all pixels become brighter
- gamma =1: linear transform

Gamma specifies the shape of the curve

Brighter Output (gamma<1) Darker Output (gamma>1)

Chapter 3

www.prenhall.com/gonzalezwoodseddins

Roger S. Gaborski

>> I = imread('mammogram.tif');

>> figure, imshow(I)

Roger S. Gaborski

>> I2 = imadjust(I, [.5 .75], [0 1]);

>> figure, imshow(I2)

Roger S. Gaborski

Reduce the amount of tissue Mapped to black:

>> I3 = imadjust(I, [.25 .75], [0 1]);

>> figure, imshow(I3)

Roger S. Gaborski

Output

.25.50.751.0

I3

I2

Input

.25.50.751.0

Roger S. Gaborski

I4 = imadjust(I, [0, 1], [0, 1], 2)

Gamma=2

Roger S. Gaborski

Negative of image:

>> I4 = imadjust(I,[0 1], [1 0]);

>> figure, imshow(I4)

Or

I4 = imcomplement(I);

Roger S. Gaborski

H = [.5 .5 .6 .7 .8 .2; .6 .3 .8 .9 .2 .4 ]

H =

0.5000 0.5000 0.6000 0.7000 0.8000 0.2000

0.6000 0.3000 0.8000 0.9000 0.2000 0.4000

b = imadjust(H, [.3 .7],[.1 .9],1)

Roger S. Gaborski

0 .1 2 .3 .4 .5 .6 .7 .8 .9 1.0 OUTPUT

Roger S. Gaborski

0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0

INPUT

0 .1 2 .3 .4 .5 .6 .7 .8 .9 1.0 OUTPUT

Roger S. Gaborski

0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0

INPUT

0 .1 2 .3 .4 .5 .6 .7 .8 .9 1.0 OUTPUT

Roger S. Gaborski

0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0

INPUT

H = [.5 .5 .6 .7 .8 .2; .6 .3 .8 .9 .2 .4 ]

H =

0.5000 0.5000 0.6000 0.7000 0.8000 0.2000

0.6000 0.3000 0.8000 0.9000 0.2000 0.4000

b=imadjust(H, [.3 .7],[.1 .9],1)

b =

0.5000 0.5000 0.7000 0.9000 0.9000 0.1000

0.7000 0.1000 0.9000 0.9000 0.1000 0.3000

Roger S. Gaborski

- g=log(f ),where f is the input image
- Issue: log(0) =-Inf
- Any zeros in the input will be mapped to -Inf
- Note: log(1) = 0
- g=log(1+f )
- This ensures that log(f )is never mapped to -Inf
- Similar to gamma transformation
- Commonly used for dynamic range compression

Roger S. Gaborski

- Creates an image with higher contrast than the input image:
- r: intensities of input;
- s: intensities of output;
- m: threshold point (see graph) ;
- E: controls slope.

Roger S. Gaborski

Chapter 3

www.prenhall.com/gonzalezwoodseddins

E controls the slope of the function

Roger S. Gaborski

>> I = imread('mammogram.tif');

>> figure, subplot(2,2,1), imshow(I), title('I')

>> E= 1;

>> g = 1./(1+(m./(double(I)+eps)).^E);

>> subplot(2,2,2), imshow(g),title('E=1')

>> E= 3;

>> g = 1./(1+(m./(double(I)+eps)).^E);

>> subplot(2,2,3), imshow(g),title('E=3')

>> E= 5;

>> g = 1./(1+(m./(double(I)+eps)).^E);

>> subplot(2,2,4), imshow(g),title('E=5')

Roger S. Gaborski

Output(s)

Input(r)

Roger S. Gaborski

Roger S. Gaborski

Chapter 3

www.prenhall.com/gonzalezwoodseddins

InputOutput

Roger S. Gaborski

>> I = imread('Flags.jpg');

>> figure, imshow(I) % uint8

>> Im= im2double(I); % convert to double

>> Igray = (Im(:,:,1)+Im(:,:,2)+Im(:,:,3))/3;

>> figure, imshow(Igray)

There is also the rgb2gray function that results

in a slightly different image

Roger S. Gaborski

First, convert to NTSC components:

Y .299 .587 .114 R

I = .596 -.274 -.322 G

Q .211 -.523 .312 B

Set I and Q components to zero, convert back to rgb:

R 1.000 .956 .621 Y

G = 1.000 -.272 -.647 I

B 1.000 1.106 1.703 Q

This will result in a gray image

Roger S. Gaborski

- In class exercise

Roger S. Gaborski