460 likes | 694 Views
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
E N D
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-
Erosion -752-
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- 1 2 3 output
Dilation -756- 4 5 6 output
Dilation -757- 7 8 9 output
Dilation -757- 10 11 12 output
Dilation -758-
Example. Dilation -759-
Erosion • Erosion is the dual of dilation i.e. eroding foreground pixels is equivalent to dilating the background pixels. -760-
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-
Erosion -762-
Erosion 1 -763- 2 3
Erosion 4 -763- 5
Erosion 6 -763- 7 8
Erosion 9 -763- 10
Erosion 11 -763- 12 13
Erosion 14 -763- 15
Erosion 16 -763- 17 18
Erosion 19 -763- 20
Erosion 21 -763- 22 23
Erosion 24 -763- 25
Erosion -763-
Erosion -765-
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-
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-
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-
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-
Closing • Closing is opening performed in reverse. It is defined simply as a dilation followed by an erosion using the same -770-
Closing -771-
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-
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-
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-
BWs = edge(DI, 'sobel', (graythresh(DI) * .1)); figure, imshow(BWs), title('binary gradient mask'); -777-
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-
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-
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-
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 imclearborderfunction. 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-
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-
BWoutline = bwperim(BWfinal); Segout = imadd(I, immultiply(BWoutline, 255)); figure, imshow(Segout), title('outlined original image'); -783-