0% found this document useful (0 votes)
30 views32 pages

Image Segmentation

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views32 pages

Image Segmentation

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Medical Image Processing II

Image Segmentation

1
Image Segmentation
Segmentation subdivides an image into its regions
or objects

Level of subdivision depends on the problem

Subdivision should stop when objects of interest


have been isolated

Segmentation of monochrome images are based on


intensity value discontinuity or similarity

2
Point, Line and Edge Detection
Points, Lines and Edges are three types of intensity
discontinuities in a digital image
Common way to find discontinuities is to pass a
mask through the image
For a 3×3 mask the response of the mask is given
by R = w1z1 + w2z2 + ….. + w9z9
Where zi is the intensity of the pixel associated with
mask coefficient wi
Response of the mask is defined with respect to its
center

3
Point Detection

Point detection is implemented in MATLAB using


imfilter function

An isolated point has been detected at the location


of the mask center if | R | ≥ T

Where T is the threshold value

4
Point Detection
Laplacian mask used for point detection
w = [-1 -1 -1; -1 8 -1; -1 -1 -1]
g = abs(imfilter(double(f), w);
T = max(g(:));
g = g >= T;
imshow(g)

A B
A: Image with nearly invisible isolated black point in the dark
area of the northeast quadrant
B: Detected point
5
Line Detection
Lines are detected using the following masks

Preferred direction is weighted with a larger


coefficients (i.e. 2) than other directions
Coefficients of each mask sum to zero, indicating a
zero response from the mask in areas of constant
intensity
6
Line Detection
f = imread(‘wirebond.tif’);
imshow(g, [ ]); % Figure 1
w = [2 -1 -1; -1 2 -1; -1 -1 2]; % -45° line detector
g = imfilter(double(f), w);
imshow(g, [ ]); % Figure 2
gtop = g(1:120, 1:120);
gtop = pixeldup(gtop, 4);
figure, imshow(gtop, [ ]); % Figure 3
gbot = g(end-119:end, end-119:end);
gbot = pixeldup(gbot, 4);
figure, imshow(gbot, [ ]); % Figure 4
g = abs(g);
figure, imshow(g, [ ]); % Figure 5
T = max(g(:));
g = g >= T;
figure, imshow(gbot, [ ]); % Figure 6 7
Edge Detection Using Function edge

Edge detection is the most common approach for


detecting discontinuities in intensity values

Discontinuities are detected using first and second


order derivatives

Syntax [g, t] = edge(f, ‘method’, parameters)

Available ‘method’ are given in the table of next slide

8
Edge Detectors Available in Function edge

9
Some edge detector masks and first order
derivatives they implement

10
Prewitt Edge Detector
Prewitt edge detector uses the mask shown below
to approximate digitally the first derivatives G x and
Gy

Syntax [g, t] = edge(f, ‘prewitt’, T, dir)


Parameters are identical to Sobel parameters

11
Roberts Edge Detector
Roberts edge detector uses the mask shown below to
approximate digitally the first derivatives Gx and Gy

Syntax [g, t] = edge(f, ‘roberts’, T, dir)


Parameters are identical to Sobel parameters
One of the oldest and simplest edge detector
Not symmetric, cannot use to detect edges of multiples of
45°. Usage is less than other detectors
Still used in hardware implementations where simplicity and
speed are dominant factors
12
Laplacian of a Gaussian (LoG) Detector
Consider the Gaussian function

This function will smooth an image if convolved with


it. Amount of smoothing is determined by σ.

13
Laplacian of a Gaussian (LoG) Detector
Laplacian of this function with respect to r is

Because second derivative is a linear operation,


filtering an image with is the same as
convolving the image with the smoothing function
first and then computing the Laplacian of the result

14
Laplacian of a Gaussian (LoG) Detector
LoG detector has two effects
1. It smoothens the image reducing noise
2. It computes the Laplacian, which yields a double-
edge .

Locating the edges then consists of finding the zero


crossing between the double edges

Syntax [g, t] = edge(f, ‘log’, T, sigma)


Where sigma is the standard deviation

15
Zero-Crossing Detector

Based on the same concept as LoG method, but


convolution is carried out using a specified filter
function H

Syntax [g, t] = edge(f, ‘zerocross’, T, H)

Other parameters are as for LoG detector

16
Canny Edge Detector
Most powerful edge detector provided by function
edge

Syntax [g, t] = edge(f, ‘canny’, T, sigma)

Where T is a vector, T =[T1, T2] containing the two


threshold explained in step 3,. If T is not supplied,
thresholds are computed automatically

sigma is the standard deviation of the smoothing


filter, default value is 1
17
Edge Detection
close all;
f = imread(‘building.tif’);
f = tofloat(f);
[gSobel, ts] = edge(f, ‘sobel’);
[gLog, ts] = edge(f, ‘log’);
[gCanny, ts] = edge(f, ‘canny’);

figure, imshow(f, [ ]); % Figure 1


figure, imshow(gSobel, [ ]); % Figure 2. Using default parameters
figure, imshow(gLoG, [ ]); % Figure 3. Using default parameters
figure, imshow(gCanny, [ ]); % Figure 4. Using default parameters

18
Thresholding

Thresholding is a method used to segment an


image depending on the pixel values to light objects
and dark objects

Threshold value can be selected manually or


automatically

19
Thresholding
Suppose that intensity histogram corresponds to an
image f(x, y) composed of light object on a dark
background

Object and background


pixels have intensity levels
in two dominant modes
Then object can be extracted from the background
by selecting a threshold T that separates these
modes
Then any point with f(x, y) ≥ T is called an object
point, otherwise called as background point 20
Thresholding
Threshold image g(x, y) is defined as
g(x, y) = 1 if f(x, y) ≥ T
g(x, y) = 0 if f(x, y) < T

Pixels labeled 1 corresponds to objects, pixels


labeled 0 corresponds to background
When T is a constant, approach is called global
thresholding.

21
Function graythresh
Function graythresh takes an image, computes its
histogram and then finds the threshold value that
maximizes the σ2.
Threshold is returned as a normalized value
between 0.0 and 1.0
Syntax T = graythresh(f)

Where f is the input image and T is the resulting


threshold

If f is class uint8 we must multiply T by 255 before


using it 22
Function imfill

After segmenting an image using a threshold value,


pixels with 0s (holes) can be present inside the
segmented image

Function imfill is used to fill holes in a segmented


binary image

Syntax g = imfill(f, ‘holes’)

23
Region-Based Segmentation

Segmentation techniques that are based on finding


regions directly using the input image are called
Region-Based Segmentation

24
Region Growing

Region growing is a procedure that groups pixels or


sub regions into larger regions based on predefined
criteria for growth

Start with a set of “seed” points and from these grow


regions by appending to each seed those
neighboring pixels that have predefined properties
similar to the seed points

25
Function regiongrow
Function regiongrow is used to do the region
growing
Syntax [g, NR, SI, TI] = regiongrow (f, S, T)

g is the segmented image.


For other output parameters refer the help page
26
Function roipoly
Function roipoly is used to select a polygonal ROI
Syntax B = roipoly(f, c, r)

Where f is the input image and c and r are vectors


of column and row coordinates of the vertices of the
polygon. B is a binary image the same size as f with
0’s outside the ROI and 1’s inside

Image B is used as a mask to limit operation to


within the ROI

27
Function roipoly
To specify a polygonal ROI interactively use the
syntax B = roipoly(f)

Which displays the image f on the screen and let


the user specify the polygon using the mouse.

Select the vertices by clicking the left mouse button


and finally double clicking or clicking the right button
on the first vertex create the ROI.

28
Function roipoly
To obtain the binary image and a list of the polygon
vertices, use the syntax
[B, c, r] = roipoly(f)

c and r are vectors of column and row coordinates


of the vertices of the polygon

This format is useful when the same polygon is


used in other programs

29
Function histroi
Function histroi computes the histogram of an
image within a polygonal region whose vertices are
specified by vectors c and r.

c and r are calculated using roipoly function

Syntax [h, npix] = histroi(f, c, r)

h is the histogram and npix is the number of pixel in


the ROI

30
Generating Histogram of an ROI

Histogram of the pixel in the ROI can also be


calculated using
h = imhist(f(B));

B is the binary image ROI obtained using


B = roipoly(f);

31
Function statmoments
Function statmoments computes the mean and
central moments up to order n
Syntax [v, unv] = statmoments(h, n)
where p is the histogram vector and n is number of
moments to compute. Normalized values are given
in v, actual values are given in unv.
Mean and variance of the region masked by B can
be obtained as
>> [v, unv] = statmoments(h, 2);
>> v % Display the normalized values
>> unv % Display the actual values
32

You might also like