binary morphology a method for … –dilation –erosion –opening –closing -750-

34
Binary Morphology • A method for … – Dilation – Erosion – Opening – Closing - 750-

Upload: abigayle-lindsey

Post on 17-Dec-2015

243 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Binary Morphology

• A method for …– Dilation– Erosion– Opening– Closing

-750-

Page 2: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Dilation

• 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

-751-

Page 3: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Erosion

-752-

Page 4: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

DilationExample: Suppose that the structuring element is a 3x3 square with the origin at its center

{ (-1,-1), (0,-1), (1,-1), (-1,0), (0,0), (1,0), ( 1,1), (0,1), (1,1) }

111

111

111

X =

K =

-753-

Page 5: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Dilation

Example: Suppose that the structuring element is a 3x3 square with the origin at its center

Note: Foreground pixels are represented by a color and background pixels are empty

-754-

Page 6: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Dilation

output

Structuring elementInput

-755-

Page 7: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Dilation

output

-756-

Page 8: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Dilation

output

-757-

Page 9: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Dilation

-758-

Page 10: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Dilation

-759-

Page 11: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Erosion

• Erosion is the dual of dilation i.e. eroding foreground pixels is equivalent to dilating the background pixels. -

760-

Page 12: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Erosion

• 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

-761-

Page 13: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Erosion

-762-

Page 14: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Erosion

-763-

Page 15: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Erosion

-764-

Page 16: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Erosion

-765-

Page 17: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Opening & Closing

• 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

-766-

Page 18: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Opening

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

-767-

Page 19: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

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

768-

Page 20: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Closing• 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.

-769-

Page 21: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Closing• Closing is opening performed in reverse. It is

defined simply as a dilation followed by an erosion using the same

-770-

Page 22: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Closing

-771-

Page 23: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

-772-

Page 24: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Detecting a Cell Using Image Segmentation

-773-

Page 25: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Step 1: Read Image

Read in 'cell.tif', which is an image of a prostate cancer cell.I = imread('cell.tif');figure, imshow(I), title('original image');

-774-

Page 26: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Step 2: Rescale the Image

We use the imadjust function to rescale the image so that it covers the entire dynamic range ([0,1]).

DI = imadjust(I, [], [0 1]);figure, imshow(DI), title('scaled image');

-775-

Page 27: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Step 3: Detect Entire Cell

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.

-776-

Page 28: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

BWs = edge(DI, 'sobel', (graythresh(DI) * .1));figure, imshow(BWs), title('binary gradient mask');

-777-

Page 29: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

Step 4: Fill Gaps

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.

se90 = strel('line', 3, 90); se0 = strel('line', 3, 0);

-778-

Page 30: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

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.

BWsdil = imdilate(BWs, [se90 se0]);figure, imshow(BWsdil), title('dilated gradient mask');

-779-

Page 31: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

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.

BWdfill = imfill(BWsdil, 'holes');figure, imshow(BWdfill); title('binary image with filled holes');

-780-

Page 32: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

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.

BWnobord = imclearborder(BWdfill, 4);figure, imshow(BWnobord), title('cleared border image');

-781-

Page 33: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

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.

seD = strel('diamond',1);BWfinal = imerode(BWnobord,seD);BWfinal = imerode(BWfinal,seD);figure, imshow(BWfinal), title('segmented image');

-782-

Page 34: Binary Morphology A method for … –Dilation –Erosion –Opening –Closing -750-

BWoutline = bwperim(BWfinal);Segout = imadd(I, immultiply(BWoutline, 255));figure, imshow(Segout), title('outlined original image');

-783-