filtering and enhancing images. major operations 1. matching an image neighborhood with a pattern or...

36
Filtering and Filtering and Enhancing Images Enhancing Images

Upload: gervase-ball

Post on 03-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Filtering and Enhancing Filtering and Enhancing ImagesImages

Major operationsMajor operations

1.1. Matching an image neighborhood Matching an image neighborhood with a pattern or maskwith a pattern or mask

2.2. Convolution (FIR filtering)Convolution (FIR filtering)

Why?Why?

• ImprovementImprovement

• Low level feature detectionLow level feature detection

DefinitionsDefinitions

• Image enhancement = improve the Image enhancement = improve the detectability of important featuresdetectability of important features– Noise reductionNoise reduction– SmoothingSmoothing– Contrast enhancementContrast enhancement– Edge detectionEdge detection

Noise reduction exampleNoise reduction example

Contrast enhancement Contrast enhancement exampleexample

DefinitionsDefinitions

• Image restoration = restore Image restoration = restore degraded imagedegraded image– Usually needs a model of degradationUsually needs a model of degradation

Image restoration examples Image restoration examples (deconvolution)(deconvolution)

POINT OPERATIONSPOINT OPERATIONS

DefinitionsDefinitions

• Point operation = output pixel is Point operation = output pixel is determined only by the input pixeldetermined only by the input pixel– Out[x,y] = f(In[x,y])Out[x,y] = f(In[x,y])

• Contrast stretching = point operator that Contrast stretching = point operator that uses a piecewise smooth function of the uses a piecewise smooth function of the input gray value to enhance important input gray value to enhance important details of the image.details of the image.

• What are some examples that we have What are some examples that we have already seen?already seen?

Examples of point Examples of point operations:operations:• Threshold (demo)Threshold (demo)

• Invert (demo)Invert (demo)Out[x,y] = max – In[x,y]Out[x,y] = max – In[x,y]

• RGB RGB gray conversion gray conversion

• Gamma correctionGamma correction

Gamma correction exampleGamma correction example

NEIGHBORHOOD NEIGHBORHOOD OPERATIONSOPERATIONS

Image smoothingImage smoothing

• Neighborhood operations = require Neighborhood operations = require more than a single image pointmore than a single image point

• Box filter = smoothing via equally Box filter = smoothing via equally weighted rectangular neighborhood weighted rectangular neighborhood (mask)(mask)

Image smoothingImage smoothing

• Gaussian filterGaussian filter

Lowpass (smoothing) filter Lowpass (smoothing) filter exampleexample

Highpass filter exampleHighpass filter example

Image smoothingImage smoothing

• Median filter (or more generally, Median filter (or more generally, order statistic or filter)order statistic or filter)

Median filter exampleMedian filter example

RECALL FROM A RECALL FROM A PREVIOUS DISCUSSION PREVIOUS DISCUSSION (HOLE AND OBJECT (HOLE AND OBJECT COUNTING) . . .COUNTING) . . .

MasksMasks

• Mask = set of pixel positions and Mask = set of pixel positions and corresponding values called weightscorresponding values called weights

• Mask origin = Mask origin = usuallyusually center center

• How?How?1.1. Calculate sum of productsCalculate sum of products

• BoundaryBoundary1.1. Replicate nearest pixel valueReplicate nearest pixel value

2.2. Use 0Use 0

2.2. Normalize or clamp (or an amplitude shift will Normalize or clamp (or an amplitude shift will occur)occur)

Applying masks to imagesApplying masks to images

Applying masks to imagesApplying masks to images

• Derived from convolution:Derived from convolution:

• Discrete form is cross correlation:Discrete form is cross correlation:

• where f is the input image, h is the mask/filter kernel, and g is the output image where f is the input image, h is the mask/filter kernel, and g is the output image resultresult

ydxdyxfyyxxhyxfyxh ,,,,yx,g

x y

yxfyyxxhyxfyxh ,,,,yx,g

ConvolutionConvolution

• See See http://en.wikipedia.org/wiki/Convolution for some nice animations. for some nice animations.

1*40+2*40+1*80+

2*40+4*40+2*80+

1*40+2*40+1*80

=800

1*40+2*80+1*80+

2*40+4*80+2*80+

1*40+2*80+1*80

=1120

But what about borders?But what about borders?

• When we are missing data at the edges, When we are missing data at the edges, we typically do one of the following:we typically do one of the following:1.1. Copy to the missing value, the nearest Copy to the missing value, the nearest

neighboring value.neighboring value.

2.2. Use 0 for the missing value(s).Use 0 for the missing value(s).

(Regardless, it really doesn’t matter, but (Regardless, it really doesn’t matter, but we need to consistently do something.)we need to consistently do something.)

1*40+2*40+1*40+

2*40+4*40+2*40+

1*40+2*40+1*40

=640

Method 1: copy nearest

The importance of The importance of normalizing or clamping the normalizing or clamping the result.result.

• Otherwise, the values might get Otherwise, the values might get larger and larger (brighter and larger and larger (brighter and brighter) or go out of the original brighter) or go out of the original range, depending on the filter.range, depending on the filter.

1+2+1+

2+4+2+

1+2+1

=16

640/16

1 2 1

2 4 2

1 2 1