Binary Morphology

Download Report

Transcript Binary Morphology

Binary Morphology
• A method for …
Dilation
Erosion
Opening
Closing
-750-
–
–
–
–
Dilation
-751-
• The dilation operator takes two pieces of data as input
– A binary image, which is to be dilated
– A structuring element (or kernel), which determines the
behavior of the morphological operation
• Suppose that X is the set of Euclidean coordinates of the
input image, and K is the set of coordinates of the
structuring element
• Let Kx denote the translation of K so that its origin is at x.
• The DILATION of X by K is simply the set of all points x
such that the intersection of Kx with X is non-empty
Erosion
-752-
Dilation
Example: Suppose that the structuring element is a
3x3 square with the origin at its center
X=
{ (-1,-1), (0,-1), (1,-1),
(-1,0), (0,0), (1,0),
( 1,1), (0,1), (1,1) }
-753-
K=
1 1 1
1 1 1
1 1 1
Dilation
Example: Suppose that the structuring element is a
3x3 square with the origin at its center
-754-
Note: Foreground pixels are represented by a color and
background pixels are empty
Dilation
Structuring element
Input
-755-
output
Dilation
-756-
output
Dilation
-757-
output
Dilation
-758-
Dilation
-759-
Erosion
-760-
• Erosion is the dual of dilation i.e. eroding
foreground pixels is equivalent to dilating
the background pixels.
Erosion
-761-
• To compute the erosion of a binary input image by
the structuring element
• For each foreground pixel superimpose the
structuring element
• If for every pixel in the structuring element, the
corresponding pixel in the image underneath is a
foreground pixel, then the input pixel is left as it is
• Otherwise, if any of the corresponding pixels in
the image are background, however, the input
pixel is set to background value
Erosion
-762-
Erosion
-763-
Erosion
-764-
Erosion
-765-
Opening & Closing
-766-
• Opening and Closing are two important operators
from mathematical morphology
• They are both derived from the fundamental
operations of erosion and dilation
• They are normally applied to binary images
Opening
-767-
• Opening is defined as an erosion followed by a dilation
using the same structuring element
• The basic effect of an opening is similar to erosion
• Tends to remove some of the foreground pixels from the
edges of regions of foreground pixels
• Less destructive than erosion
• The exact operation is determined by a structuring element.
Opening
-768-
• Erosion can be used to eliminate small clumps of
undesirable foreground pixels, e.g. “salt noise”
• However, it affects all regions of foreground pixels
indiscriminately
• Opening gets around this by performing both an erosion
and a dilation on the image
Closing
-769-
• Closing, like its dual operator opening, is derived from the
fundamental operations of erosion and dilation.
• Normally applied to binary images
• Tends to enlarge the boundaries of foreground regions
• Less destructive of the original boundary shape
• The exact operation is determined by a structuring element.
Closing
• Closing is opening performed in reverse. It is
defined simply as a dilation followed by an
erosion using the same
-770-
Closing
-771-
-772-
-773-
Detecting a Cell Using Image Segmentation
Step 1: Read Image
-774-
Read in 'cell.tif', which is an image of a prostate
cancer cell.
I = imread('cell.tif');
figure, imshow(I), title('original image');
Step 2: Rescale the Image
We use the imadjust function to rescale the
image so that it covers the entire dynamic range
([0,1]).
-775-
DI = imadjust(I, [], [0 1]);
figure, imshow(DI), title('scaled image');
Step 3: Detect Entire Cell
-776-
Two cells are present in this image, but only one cell
can be seen in its entirety. We will detect this cell.
Another word for object detection is segmentation. The
object to be segmented differs greatly in contrast from
the background image. Changes in contrast can be
detected by operators that calculate the gradient of an
image. One way to calculate the gradient of an image is
the Sobel operator, which creates a binary mask using a
user-specified threshold value.We determine a threshold
value using the graythresh function. To create the binary
gradient mask, we use the edge function.
BWs = edge(DI, 'sobel', (graythresh(DI) * .1));
figure, imshow(BWs), title('binary gradient mask');
-777-
Step 4: Fill Gaps
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
-778-
The binary gradient mask shows lines of high contrast in the
image. These lines do not quite delineate the outline of the
object of interest. Compared to the original image, you can see
gaps in the lines surrounding the object in the gradient mask.
These linear gaps will disappear if the Sobel image is dilated
using linear structuring elements, which we can create with the
strel function.
Step 5: Dilate the Image
The binary gradient mask is dilated using the
vertical structuring element followed by the
horizontal structuring element. The imdilate
function dilates the image.
-779-
BWsdil = imdilate(BWs, [se90 se0]);
figure, imshow(BWsdil), title('dilated gradient
mask');
Step 6: Fill Interior Gaps
The dilated gradient mask shows the outline of the
cell quite nicely, but there are still holes in the
interior of the cell. To fill these holes we use the
imfill function.
-780-
BWdfill = imfill(BWsdil, 'holes');
figure, imshow(BWdfill);
title('binary image with filled holes');
Step 7: Remove Connected Objects on Border
The cell of interest has been successfully segmented, but
it is not the only object that has been found. Any objects
that are connected to the border of the image can be
removed using the imclearborder function. The
connectivity in the imclearborder function was set to 4 to
remove diagonal connections.
-781-
BWnobord = imclearborder(BWdfill, 4);
figure, imshow(BWnobord), title('cleared border image');
Step 8: Smooth the Object
Finally, in order to make the segmented object look
natural, we smooth the object by eroding the image twice
with a diamond structuring element. We create the
diamond structuring element using the strel function.
-782-
seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
figure, imshow(BWfinal), title('segmented image');
BWoutline = bwperim(BWfinal);
Segout = imadd(I, immultiply(BWoutline, 255));
figure, imshow(Segout), title('outlined original image');
-783-