- 75 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about 'Introduction to Computer Vision' - lester

**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.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 - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

8:00-8:15: In class exercise – histogram equalization

- 8:15 – 8:50 Lecture
- 8:50 - 9:15 Quiz #2

Simple Histogram Equalization In Class Exercise

Roger S. Gaborski

Histogram Equalization

- Consider an image with the following gray level values:
- Construct the pdf
- Construct the cdf
- Equalize the image using the cdf (not histeq)

Roger S. Gaborski

Histogram Equalization

- Consider an image with the following gray level values:
- Construct the pdf

1/9 2/9 3/9 4/9 5/9

.1 .2 .3 .4 .5

Roger S. Gaborski

pdf

cdf

1/9 2/9 3/9 4/9 5/9

.1 .2 .3 .4 .5

Histogram EqualizationLook Up Table

1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 1

cdf

probability

.1 .2 .3 .4 .5

Gray level value

Gray level value

Roger S. Gaborski

Histogram Equalization

- Consider an image with the following gray level values:
- Construct the pdf
- Construct the cdf
- Equalize the image using the cdf (not histeq)

Roger S. Gaborski

Create a ‘color image’

First create three color planes of data

>> red = rand(5)

red =

0.0294 0.0193 0.3662 0.7202 0.0302

0.7845 0.3955 0.2206 0.4711 0.2949

0.7529 0.1159 0.6078 0.9778 0.5959

0.1586 0.1674 0.5524 0.9295 0.1066

0.7643 0.6908 0.3261 0.5889 0.1359

>> green = rand(5)

green =

0.2269 0.5605 0.6191 0.0493 0.1666

0.0706 0.4051 0.3297 0.7513 0.6484

0.9421 0.0034 0.8243 0.7023 0.8097

0.8079 0.5757 0.6696 0.9658 0.8976

0.0143 0.3176 0.6564 0.1361 0.0754

>> blue = rand(5)

blue =

0.6518 0.0803 0.8697 0.6260 0.9642

0.5554 0.2037 0.8774 0.5705 0.6043

0.8113 0.8481 0.5199 0.0962 0.8689

0.5952 0.2817 0.6278 0.7716 0.8588

0.5810 0.9290 0.2000 0.1248 0.7606

Roger S. Gaborski

0.0294 0.0193 0.3662 0.7202 0.0302

0.7845 0.3955 0.2206 0.4711 0.2949

0.7529 0.1159 0.6078 0.9778 0.5959

0.1586 0.1674 0.5524 0.9295 0.1066

0.7643 0.6908 0.3261 0.5889 0.1359

colorIm(:,:,2) =

0.2269 0.5605 0.6191 0.0493 0.1666

0.0706 0.4051 0.3297 0.7513 0.6484

0.9421 0.0034 0.8243 0.7023 0.8097

0.8079 0.5757 0.6696 0.9658 0.8976

0.0143 0.3176 0.6564 0.1361 0.0754

colorIm(:,:,3) =

0.6518 0.0803 0.8697 0.6260 0.9642

0.5554 0.2037 0.8774 0.5705 0.6043

0.8113 0.8481 0.5199 0.0962 0.8689

0.5952 0.2817 0.6278 0.7716 0.8588

0.5810 0.9290 0.2000 0.1248 0.7606

>> colorIm(:,:,1)=red;

>> colorIm(:,:,2)=green;

>> colorIm(:,:,3)=blue;

>> colorIm

figure

imshow(colorIm, 'InitialMagnification', 'fit')

Roger S. Gaborski

0.0294 0.0193 0.3662 0.7202 0.0302

0.7845 0.3955 0.2206 0.4711 0.2949

0.7529 0.1159 0.6078 0.9778 0.5959

0.1586 0.1674 0.5524 0.9295 0.1066

0.7643 0.6908 0.3261 0.5889 0.1359

colorIm(:,:,2) =

0.2269 0.5605 0.6191 0.0493 0.1666

0.0706 0.4051 0.3297 0.7513 0.6484

0.9421 0.0034 0.8243 0.7023 0.8097

0.8079 0.5757 0.6696 0.9658 0.8976

0.0143 0.3176 0.6564 0.1361 0.0754

colorIm(:,:,3) =

0.6518 0.0803 0.8697 0.6260 0.9642

0.5554 0.2037 0.8774 0.5705 0.6043

0.8113 0.8481 0.5199 0.0962 0.8689

0.5952 0.2817 0.6278 0.7716 0.8588

0.5810 0.9290 0.2000 0.1248 0.7606

Roger S. Gaborski

What are two methods to convert from a color image to a gray scale image?

Roger S. Gaborski

RECALL

- What are two methods to convert from a color image to a gray scale image?
- Average red, green and blue pixels

Roger S. Gaborski

Average

- For example:

>> colorImAverage = ( colorIm(:,:,1) + colorIm(:,:,2) + colorIm(:,:,3) )/3

colorImAverage =

0.3027 0.2200 0.6183 0.4651 0.3870

0.4701 0.3348 0.4759 0.5976 0.5159

0.8354 0.3224 0.6507 0.5921 0.7582

0.5206 0.3416 0.6166 0.8890 0.6210

0.4532 0.6458 0.3942 0.2833 0.3240

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

Roger S. Gaborski

Color and Gray scale Images

Roger S. Gaborski

Color and Gray scale Images

Conversion to gray scale results in a loss of information

Roger S. Gaborski

What are two methods to convert from a color image to a gray scale image?

- Average red, green and blue pixels
- Matlab’s rgb2gray function

Roger S. Gaborski

MATLAB’s rgb2gray Function

>> colorIm_rgb2gray = rgb2gray(colorIm)

colorIm_rgb2gray =

0.2163 0.3439 0.5721 0.3156 0.2168

0.3393 0.3792 0.3596 0.6469 0.5377

0.8706 0.1333 0.7249 0.7155 0.7525

0.5895 0.4202 0.6298 0.9328 0.6567

0.3031 0.4989 0.5056 0.2702 0.1716

Roger S. Gaborski

colorIm and rgb2gray(colorIm)

Roger S. Gaborski

How does rgb2gray work?

rgb2gray converts RGB values to grayscale values by forming a weighted sum of the R, G, and B components:

Gray = 0.2989 * R + 0.5870 * G + 0.1140 * B

Roger S. Gaborski

Segmentation – separate an image into its parts

Separate the coins

from the background

Form two classes:

Class 1: coins

Class 2: background

Roger S. Gaborski

Thresholding

- Create a mask where coins have a value 1 and background has a value of 0

Roger S. Gaborski

Histogram of coins image

Roger S. Gaborski

>> figure, imshow(It75)

>> whos

Name Size Bytes Class Attributes

I 246x300 590400 double

It75 246x300 73800 logical

Roger S. Gaborski

Histogram of thresholded image

Roger S. Gaborski

Threshold = .5

Roger S. Gaborski

Background Problems

Roger S. Gaborski

Coin Problem

Roger S. Gaborski

graythreshGlobal image threshold using Otsu's method.

LEVEL = graythresh(I) computes a global threshold (LEVEL) that can be

used to convert an intensity image to a binary image with IM2BW. LEVEL

is a normalized intensity value that lies in the range [0, 1].

graythresh uses Otsu's method, which chooses the threshold to minimize

the intraclass variance of the thresholded black and white pixels.

[LEVEL EM] = graythresh(I) returns effectiveness metric, EM, as the

second output argument. It indicates the effectiveness of thresholding

of the input image and it is in the range [0, 1]. The lower bound is

attainable only by images having a single gray level, and the upper

bound is attainable only by two-valued images.

Roger S. Gaborski

>> I = im2double(I);

>> level = graythresh(I)

level =

0.4941

>> BW = I>level;

>> figure, imshow(BW)

>> [level,em] = graythresh(I)

level =

0.4941

em =

0.9168

Roger S. Gaborski

Convert Image to Grayscale

Roger S. Gaborski

>> I = im2double(I);

>> Ig = rgb2gray(I);

[level,em] = graythresh(Ig)

level =

0.5529

em =

0.6971 (relatively low number)

>> BW = Ig>level;

>> figure, imshow(BW)

Roger S. Gaborski

Histogram of Grayscale Image

level = 0.5529

impixel()

impixel Pixel color values.

impixel returns the red, green, and blue color values of

specified image pixels. In the syntaxes below, impixel

displays the input image and waits for you to specify the

pixels with the mouse:

P = impixel(I)

Select Pixels From Grayscale Image

>> figure, imshow(Ig)

>> K=impixel();

>> K

K =

0.8588 0.8588 0.8588

0.8398 0.8398 0.8398

0.7695 0.7695 0.7695

0.7225 0.7225 0.7225

0.7852 0.7852 0.7852

0.7842 0.7842 0.7842

0.8548 0.8548 0.8548

0.8514 0.8514 0.8514

0.7852 0.7852 0.7852

0.7375 0.7375 0.7375

figure, imshow(Ig>.45)

Lower threshold than graythresh

Background now detected along with more of object

Potential Improvements:

- Multilevel GrayscaleThresholding
- Use of Color
- Edge Detection

A Quick Look Ahead

- Threshold image to obtain 0/1 pixels
- Detect skew and rotate image
- Segment characters
- Label individual components of characters
- Identify characters

Roger S. Gaborski

Threshold

- ImageThreshold = image>thresholdValue
- Convert a double image with pixels in the range [0 1] to a binary image
- Pixels have either a 0 or 1 value
- The choice of thresholdValue in combination with quality of original image will determine binary image quality:
- Broken characters
- Filled in characters, such as, a, q, o,
- Touching characters

Roger S. Gaborski

Korean Text

% readKorean.m

image = imread('Korean1.jpg');

Convert to grayscale image

image1

figure, imshow(image1)

Gray scale image

Roger S. Gaborski

Line Profile and Image1 Histogram

Generate profile of text page at line 372

figure, plot(1:cols,image1(372,:));

Roger S. Gaborski

Segmentation of Korean Characters

Roger S. Gaborski

Simple 1 D Averaging Example

- 3 point moving average
- 5 point moving average

Simple 1 D Averaging Example

- 3 point moving average
- 5 point moving average
- NEED FOR PADDING

Padding an array -- padarray

- fp = padarray(f, [r c], method, direction)
- f is input image
- fp is padded image
- [r c] is number of rows and columns to pad f
- method and direction – next slide

Roger S. Gaborski

padarray Example

>> f = [1 2; 3 4]

f =

1 2

3 4

>> fp = padarray(f, [3 2], 'replicate', 'post')

fp =

1 2 2 2

3 4 4 4

3 4 4 4

3 4 4 4

3 4 4 4

Post – pad after the last element in both directions

[3 2] – pad 3 rows and 2 columns

Roger S. Gaborski

>> fp = padarray(f, [2 1], 'replicate', 'post')

fp =

1 2 2

3 4 4

3 4 4

3 4 4

Post – pad after the last element in both directions

[2 1] – pad 2 rows and 1 columns

Roger S. Gaborski

f =

1 2 3

1 2 3

1 2 3

>> fp = padarray(f, [2 2], 'symmetric', 'both')

fp = ??????

Roger S. Gaborski

f = 1 2 3

1 2 3

1 2 3

>> fp = padarray(f, [2 2], 'symmetric', 'both')

fp =

2 1 1 2 3 3 2

2 1 1 2 3 3 2

2 1 1 2 3 3 2

2 1 1 2 3 3 2

2 1 1 2 3 3 2

2 1 1 2 3 3 2

2 1 1 2 3 3 2

Roger S. Gaborski

Spatial Filtering

- Neighborhood processing
- Define center point (x, y)
- Perform operations involving only pixels in the neighborhood
- Result of operation is response to process at that point
- Moving the pixel results in a new neighborhood
- Repeat process for every point in the image

Roger S. Gaborski

Linear and Nonlinear Spatial Filtering

- Linear operation
- Multiply each pixel in the neighborhood by the corresponding coefficient and sum the results to get the response for each point (x, y)
- If neighborhood is m x n , then mn coefficients are required
- Coefficients are arranged in a matrix, called
- filter / filter mask / kernel / template
- Mask sizes are typically odd numbers (3x3, 5x5, etc.)

Roger S. Gaborski

Correlation and Convolution

- Correlation
- Place mask w on the image array f as previously described
- Convolution
- First rotate mask w by 180 degrees
- Place rotated mask on image as described previously
- Convolution = 180 degree rotation + correlation

Roger S. Gaborski

Example: 1D Correlation

- Assume w and f are one dimensional
- Origin of f is its left most point
- Place w so that its right most point coincides with the origin of f
- Pad f with 0s so that there are corresponding f points for each w point (also pad end with 0s)
- Multiply corresponding points and sum
- In this case (example on next page) result is 0
- Move w to the right one value, repeat process
- Continue process for whole length of f

Roger S. Gaborski

Reminder

- ‘full’ is the result we obtain from the operations on the previous slide. If instead of aligning the left most element of f with the right most element of w we aligned the center element of w with the left most value of f we would obtain the ‘same’ result, same indicating the result is the same length of the original w

Roger S. Gaborski

Example - Convolution

- Convolution is the same procedure, but the filter is first rotated 180 degrees.
- Convolution = 180 degree rotation + correlation
- If the filter is symmetric, correlation and convolution results are the same

Roger S. Gaborski

Linear Filtering in MATLAB

g = imfilter(f, w, filtering mode, boundary, size)

- filters the imput image f with the filter mask w.
- f is input image. It can be of any class (logical/numeric) and dimension.
- g is output image
- filter mode:

- 'corr' : correlation, and default mode

- 'conv' : convolution

Roger S. Gaborski

Parameters

- g = imfilter(f, w, filtering mode, boundary, size)

Boundary options

- X pad boundary with value X. Default X = 0.

- 'symmetric' symmetric padding

- 'replicate' replicate padding

- 'circular' circular padding

Size options

- 'same' g is the same size of f (default mode)

- 'full' g is full filtered by w, so size of g is increased

Roger S. Gaborski

MATLAB function for filtering: imfilter

- g = imfilter(f, w, ‘replicate’)
- Correlation is the default filtering mode.
- If filters are pre-rotated 180 degrees, can simply use default(corr) for convolution
- If filter is symmetric, doesn’t matter

Roger S. Gaborski

Example:Smoothing

- w = ones(31); (31x31 filter)
- % Normally the coefficients (w) are scaled to sum to one
- % In this example only coefficients are not scaled by 312
- % Convolution should result in a blurred result
- gd = imfilter(f, w);
- % Default mode: correlation filtering
- imshow(gd, [ ]);

Roger S. Gaborski

www.prenhall.com/gonzalezwoodseddins

Input Default padding ‘replicate’

‘symmetric’ ‘circular’ ‘replicate’, uint8

Roger S. Gaborski

Download Presentation

Connecting to Server..