Sie sind auf Seite 1von 50

SSG 512

INTENSITY TRANSFORMATIONS
AND SPATIAL FILTERING
GROUP 3
J A C K S O N Q U E E N E TT E E .
110407023
O L A G U N J U A B D U L - H A M M I D O.
110407039
E KW U R I B E C H I S O M
110407019
OLALEYE LOVE
110407040
IKEDIASHI JAMES
L E C T U R E R : D R . FA S H A N U

Function adapthisteq
This toolbox function performs contrast-limited

adaptive histogram equalization (CLAHE), expressed


g1 = adapthisteq(f);
g = adapthisteq (f, param1, va11, param2, va12, ... )
It processes small regions of the image (tiles) using

histogram specification for each tile individually


Neighbouring tiles are then combined using bilinear

interpolation to eliminate artificially induced


boundaries

Parameters and corresponding values for use in function


adapthiseq

MATLAB CODES
>> f =
imread('C:\Users\RO
QEEB A.
RAHEEM\Desktop\us
-map2.gif');
>> g1 = adapthisteq(f);
>> imshow(f)
>> figure, imshow(g1)
>> g2 = adapthisteq (f,
'NumTiles', [25 25]);
>> figure, imshow(g2)
>> g3 = adapthisteq(f,
'NumTiles', [25 25],
'ClipLimit', 0.10);
>> imshow(g3)

Slight Increase in detail

Slight increase in sharpness

Significant Enhancement

SPATIAL FILTERING
Spatial filtering term is the filtering operations

performed directly on the pixels of an image


Principal terms used for creating new neighborhoods

are neighbourhood processing and spatial filtering


SPATIAL FILTERING

LINEAR NON-LINEAR
(Spatial Convolution)

LINEAR SPATIAL FILTERING


Linear operations consist of multiplying each pixel

in the neighborhood by a corresponding coefficient


and summing the results to obtain the response at
each point (x, y)
If the neighborhood is of size m X n, mn
coefficients are required
The coefficients are arranged as a matrix, called a
filter, mask or filter mask
The process consists of moving the center of the
filter mask, w, from point to point in an image, f

LINEAR SPATIAL FILTERING


Modes for performing linear spatial filtering

Correlation is the process of passing the mask W by the image


array f

AND

Convolution is the same process, except that W is rotated by


180 prior to passing it by f

Linear spatial filtering is implemented using

g = imfilter(f, w, filtering_mode,
boundary_options, size_options)
The most common syntax for imfilter is

g = imfilter(f, w,'replicate) to implement standard


linear spatial filters

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

NON LINEAR SPATIAL FILTERING


The "filter" is visualized as a nonlinear function that

operates on the pixels of a neighborhood, whose response


constitutes the result of the nonlinear operation
Functions for general nonlinear filtering: nlfilter and colfilt
g = colfilt(f, [m n], 'sliding', fun)
In colfilt, the input image must be padded explicitly before

filtering using padarray, for 2-D functions;


fp = padarray(f, [r c), method, direction)
where f = input image
fp = padded image
[r c) = number of rows and columns by which to pad f

MATLAB CODES AND RESULTS

MATLAB CODES AND RESULTS

restore the gray tones lost


g = f2 - g2; imshow(g);
convert f to floating point before
filtering it;
f2
= tofloat(f); g2 = imfilter(f2,
w, 'replicate');

imshow(g2, [ ])

Generate and display the Laplacian


filter: W =
fspecial( 'laplacian', 0)

Apply w to the input image:


g1 = imfilter(f, w, 'replicate');
imshow(g1, [ ])

W = fspecial( 'type',
parameters)
generates a filter mask
W, also a number of
predefined 2-D linear
spatial filters, expressed
Function fspecial

LINEAR SPATIAL FILTERS

NON LINEAR SPATIAL FILTERS


Function ordfilt2, computes

order-statistic filters (rank


filters); non-linear spatial
filters
g = ordfilt2(f, order, domain)

Median t filter (50th

NOISE
CORRUPTED
IMAGE
>>fn=imnoise(f,
salt & pepper,
0.2);

IMAGE
WITH
REDUCED
SALT &
PEPPER
NOISE

percentile) is the best-known


order-statistic filter in digital
image processing
g = ordfilt2(f, (m*n + 1)/2,
ones(m, n))
for odd m and n

Median filtering g =

medfilt2(f) is a useful tool


for reducing salt-and-pepper
noise

MEDIAN
FILTER >>gm =
medfilt2(fn)

MATLAB CODES
>> f = imread('C:\Users\ROQEEB A.

RAHEEM\Desktop\us-map2.gif');
>> imshow(f)
>> PSF = fspecial('gaussian',7,10);
>> g = imfilter(f,PSF,'symmetric','conv');
>> figure;imshow(g);title('Blurred Image');
>> w = fspecial('laplacian', 0)
w =

0 1
1 -4
0 1

0
1
0

>> g1 = imfilter(f, w, 'replicate');


>> figure, imshow(g1, [])
>> f2 = im2double(f);
>> g2 = imfilter(f2, w, 'replicate');
>> figure, imshow(g2,[])
>> g3 = f2 - g2;
>> figure, imshow(g3)
>> INITPSF = padarray(UNDERPSF,[2

2],'replicate','both');
Undefined function or variable 'UNDERPSF'.

>> UNDERPSF = ones(size(PSF)-4);


>> [J1, P1] =

deconvblind(Blurred,UNDERPSF);
Undefined function or variable 'Blurred'.

>> [J1, P1] =

deconvblind(g,UNDERPSF);
>> figure;imshow(J1);title('Deblurring
with Undersized PSF');
>> INITPSF = padarray(UNDERPSF,[2
2],'replicate','both');
>> [J3, P3] =
deconvblind(Blurred,INITPSF);
Undefined function or variable 'Blurred'.

>> [J3, P3] = deconvblind(g,INITPSF);


>> figure;imshow(J3);title('Deblurring

with INITPSF');
>>

Input image

Gaussian blur

Deblurring with undersized psf

Deblurring with init psf

MATLAB CODES
>> f = imread('C:\Users\ROQEEB A.
RAHEEM\Desktop\us-map2.gif');
>> imshow(f)
>> len = 21;
>> theta = 11;
>> psf = fspecial('motion', len,
theta);
>> g = imfilter(f, psf, 'conv',
'circular');
>> subplot(1, 2, 1);
>> subimage(f);
>> title('input image');
>> subplot(1,2,2);
>> subimage(g);
>> title('blurred image');
>> figure, imshow(g)
>> imshow(f), figure, imshow(g)

>> w = fspecial('laplacian', 0)
w=
0 1 0
1 -4 1
0 1 0
>> g1 = imfilter(f, w, 'replicate');
>> imshow(g1, [])
>> f2 = im2double(f);
>> g2 = imfilter(f2, w, 'replicate');
>> imshow(g2,[])
>> g = f2 - g2;
>> imshow(g)

Input image

Blurred image using motion blur

Laplacian filter

Laplacian filter 2

Laplacian filter 3

MATLAB CODES
>> f = imread('C:\Users\ROQEEB A.
RAHEEM\Desktop\us-map2.gif');
>> fn = imnoise(f, 'salt & pepper', 0.2);
>> imshow(fn)
>> gm = medfilt2(fn);
>> imshow(gm)
>> gms = medfilt2(fn, 'symmetric');
>> imshow(gms)

Noisy image

Noise removed

Noise removed symmetric

Using Fuzzy Techniques for Intensity Transformations


and Spatial Filtering
Fuzzy sets provide a formalism for dealing with

imprecise information
A fuzzy set, A, is an ordered pair consisting of values
of z and a membership function that assigns a grade
of membership in A to each z. That is,
A = {z, A (z)|z z}
This membership function is infinite-valued, thus
allowing a gradual transition
Fundamental problem with crisp sets (membership
is either true or false) that limits their use in many
practical applications is lack of flexibility

MEMBERSHIP FUNCTIONS

Defuzzify the final output fuzzy set: obtain a crisp, scalar output by computing the center of gravity of
the aggregated set from step 4 --- function out = defuzzify(Qa, vrange)
vo = vQ(v)dv
Q(v)dv

Apply an aggregation method to the fuzzy sets from step 3: approach used is to form the union (OR) of
the individual outputs, so the max operation is employed
function Qa =
aggfcn(Q)

Apply an implication method: The single output of the antecedent of each rule is used to provide the
output corresponding to that rule
function Q =
implfcns(L, outmf, varargin)

Perform any required fuzzy logical operations: outputs of all parts of an antecedent must be combined to
yield a single value using the max or min operation

Fuzzify the inputs: For each scalar input, find the corresponding fuzzy values by mapping that input to
the interval [0, 1]

4
3
2
1

Application of rule-based fuzzy logic

Using Fuzzy Techniques for Intensity Transformations


and Spatial Filtering
Using nested functions allows function lambdafcns

compute the rule strengths


lambdafcns outputs a set of lambda functions
instead of numerical outputs
lambdafcns provides rule strengths in "general"
terms
To carry out implication we need to provide specific

inputs
function Q = implfcns(L, outmf, varargin)

Improving performance
The fuzzy system function created by fuzzysysfcn

gives the exact output for any set of inputs


useful for exploration and plotting purposes, it is too
slow for large inputs
Function approxfcn creates an approximation (uses
a lookup table and runs faster) to the fuzzy system
function
MATLAB's function waitbar provides provide a
visual cue to the user indicating percent completion
h = waitbar(c, 'message')
displays a waitbar of fractional length c, where c is
between 0 and 1

Using Fuzzy Sets for Spatial Filtering


Basic approach is to define fuzzy neighborhood properties that

"capture" the essence of what the filters are supposed to detect


Example, a fuzzy boundary detection (enhancement) algorithm based

on the following fuzzy statement: If a pixel belongs to a uniform region,


then make it white; else make it black

To express "uniform region" in fuzzy terms, consider the intensity differences


between the pixel at the center and its neighbours
The following four IF-THEN rules & ELSE rule implement the fuzzy
statement above:
If d2 is zero AND d6 is zero THEN Zs is white, If d6 is zero AND d8
is zero THEN Zs is white, If ds is zero AND d4 is zero THEN Zs is
white, If d4 is zero AND d2 is zero THEN Zs is white, ELSE Zs is
black
where d; denotes the intensity difference between the ith neighbor and the
center point

Das könnte Ihnen auch gefallen