lecture 06 roger s gaborski n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to Computer Vision PowerPoint Presentation
Download Presentation
Introduction to Computer Vision

Loading in 2 Seconds...

play fullscreen
1 / 85

Introduction to Computer Vision - PowerPoint PPT Presentation


  • 79 Views
  • Uploaded on

Lecture 06 Roger S. Gaborski. Introduction to Computer Vision. 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. Solution For In Class Histogram Equalization Exercise. In class exercise.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
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
lecture 06 roger s gaborski
Lecture 06

Roger S. Gaborski

Introduction to Computer Vision

Roger S. Gaborski

slide2

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

  • 8:15 – 8:50 Lecture
  • 8:50 - 9:15 Quiz #2
solution for in class histogram equalization exercise
Solution For In Class

Histogram Equalization Exercise

Roger S. Gaborski

in class exercise
In class exercise
  • Histogram PDF  CDF Equalized Image

Roger S. Gaborski

histogram equalization
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 equalization1
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

histogram equalization2
pdf

cdf

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

.1 .2 .3 .4 .5

Histogram Equalization

Look 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 equalization3
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
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

slide11

colorIm(:,:,1) =

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

colorim
colorIm

colorIm(1,1,: )

colorIm(4,4,: )

Roger S. Gaborski

slide13

colorIm(:,:,1) =

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

recall
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
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

gray scale version of color image
Gray scale version of color image

.5976

.5921

Roger S. Gaborski

color and gray scale images1
Color and Gray scale Images

Conversion to gray scale results in a loss of information

Roger S. Gaborski

slide20

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

how does rgb2gray work
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
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
Thresholding

>> I = imread('coins.png');

>> I=im2double(I);

>> figure, imshow(I)

Roger S. Gaborski

thresholding1
Thresholding
  • Create a mask where coins have a value 1 and background has a value of 0

Roger S. Gaborski

histogram of c oins image
Histogram of coins image

Roger S. Gaborski

select a threshold value
Select a threshold value

Threshold t = .75

Roger S. Gaborski

slide30

>> It75 = I>.75;

>> figure, imshow(It75)

>> whos

Name Size Bytes Class Attributes

I 246x300 590400 double

It75 246x300 73800 logical

Roger S. Gaborski

threshold 5
Threshold = .5

Roger S. Gaborski

background problems
Background Problems

Roger S. Gaborski

coin problem
Coin Problem

Roger S. Gaborski

slide35

>> help graythresh

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

slide36

>> I = imread('coins.png');

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

slide39

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

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

simple threshold result
Simple Threshold Result

BACKGROUND

DETECTED

Roger S. Gaborski

i mpixel
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
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

min and max of selected points
Min and Max of Selected Points

>> MN = min(K(:,1))

MN =

0.7225

>> MX = max(K(:,1))

MX =

0.8588

figure imshow ig mn title ig mn
>> figure, imshow(Ig>MN),title('Ig>.MN')

MOST BACKGROUND

NOT DETECTED

figure imshow ig 45
figure, imshow(Ig>.45)

Lower threshold than graythresh

Background now detected along with more of object

potential improvements
Potential Improvements:
  • Multilevel GrayscaleThresholding
  • Use of Color
  • Edge Detection
a quick look ahead
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
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

threshold 7
Threshold = .7

SKEW

Roger S. Gaborski

korean text
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
Line Profile and Image1 Histogram

Generate profile of text page at line 372

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

Roger S. Gaborski

image rotation
Image Rotation

>> figure, imshow(imrotate(d,10));

Roger S. Gaborski

labeled components of korean characters
Labeled Components of Korean Characters

Input image Output image

Roger S. Gaborski

simple 1 d averaging example
Simple 1 D Averaging Example
  • 3 point moving average
  • 5 point moving average
simple 1 d averaging example1
Simple 1 D Averaging Example
  • 3 point moving average
  • 5 point moving average
  • NEED FOR PADDING
padding an array padarray
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

slide62

Chapter 3

www.prenhall.com/gonzalezwoodseddins

Roger S. Gaborski

padarray example
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

slide64

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

slide65

>> f = [1 2 3; 1 2 3; 1 2 3]

f =

1 2 3

1 2 3

1 2 3

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

fp = ??????

Roger S. Gaborski

slide66

>> f = [1 2 3; 1 2 3; 1 2 3]

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

slide69

Image origin

y

Kernel coefficients

mask

x

Image region under mask

Roger S. Gaborski

correlation and convolution
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
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
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

slide73

Chapter 3

www.prenhall.com/gonzalezwoodseddins

Roger S. Gaborski

slide74

‘Full’

correlation

Roger S. Gaborski

slide77

‘Same’

correlation

etc.

Roger S. Gaborski

example convolution
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

slide79

Chapter 3

www.prenhall.com/gonzalezwoodseddins

This can be simply extend to images

Roger S. Gaborski

linear filtering in matlab
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
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
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

slide83

Chapter 3

www.prenhall.com/gonzalezwoodseddins

Roger S. Gaborski

example smoothing
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

slide85

Chapter 3

www.prenhall.com/gonzalezwoodseddins

Input Default padding ‘replicate’

‘symmetric’ ‘circular’ ‘replicate’, uint8

Roger S. Gaborski