2008년 6월 2일 월요일

오후 1:40

Erosion and dilation

|

MIL User Guide

2007.05.21 19:09

ypk2001

http://cafe.naver.com/visionsystem/172

Especially during cell analysis, it can be important to know the growth stages of cell particles. Using the image processing erosion and dilation operations, you can view the possible growth stages of these particles.

  • Erosion operations peel off layers from objects or particles, removing extraneous pixels and small particles from the image.
  • Dilation operations add layers to objects or particles, enlarging any particle. Dilation can return eroded particles to their original size (but not necessarily to their exact original shape).

Erosion and dilation are neighborhood operations that determine each pixel's value according to its geometric relationship with neighborhood pixels, and as such, are part of a group of operations known as morphological operations.

   

This section describes basic erosion and dilation performed using MimErode() and MimDilate(). Both these functions use pre-defined kernels to perform operations. For a description of advanced erosion and dilation, performed by MimMorphic(), see the Custom morphological operations section in Chapter 4: Advanced image processing.

   

They are also the basic operations used to perform the opening and closing operations discussed in the following section.

Note, zero pixels are considered background, while non-zero pixels are considered foreground and part of objects.

Basic erosion

You can perform a basic erosion operation on 3 by 3 neighborhoods, using MimErode().

  • If the erosion mode is set to M_BINARY, any pixel whose neighborhood is not completely white (any non-zero pixel is considered white) is changed to black (0 is considered black).
  • If the erosion mode is set to M_GRAYSCALE, each pixel is replaced with the minimum value in its neighborhood.

You can use the iteration parameter of MimErode() to perform an erosion on larger neighborhoods. Iterating the erosion is the equivalent to performing an erosion on a (1 + (2* i)) by (1 + (2* i)) neighborhood where i is the number of iterations. For example, two iterations of a 3x3 erosion is equivalent to a 5x5 erosion, and three iterations is equivalent to a 7x7 erosion.

Basic dilation

You can perform a basic dilation operation on 3 by 3 neighborhoods, using MimDilate().

  • If the dilation mode is set to M_BINARY, any pixel that has one or more white pixels (any non-zero pixel is considered white) in its neighborhood is set to white (0xff in an 8-bit image).
  • If the dilation mode is set to M_GRAYSCALE, each pixel is replaced with the maximum value in its neighborhood.

The MimDilate() function is similar to the MimErode() function in that iterating it will effectively cause a dilation on larger neighborhoods. Iterating the dilation is the equivalent to performing a dilation on a (1 + (2* i)) by (1 + (2* i)) neighborhood where i is the number of iterations. For example, two iterations of a 3x3 dilation is equivalent to a 5x5 dilation, and three iterations is equivalent to a 7x7 dilation.

An example

You can use erosion or dilation to find the perimeter of objects. Erode or dilate a binary image and `XOR' the result with the original image, using MimArith().

The following example shows how to obtain the exoskeletons of objects in an image.

   

MImPerimeter.c

   

/*******************************************************************************/
/*
* File name: MImPerimeter.c
*
* Synopsis: This program finds the exoskeletons of the perimeters of
* dark objects in an image.
*/
#include <mil.h>
#include <conio.h>

/* Source MIL image file specifications. */
#define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("cell.mim")
#define IMAGE_WIDTH 512L
#define IMAGE_HEIGHT 480L
#define IMAGE_THRESHOLD_VALUE 128L

/* Small particle radius (in pixels). */
#define SMALL_PARTICLE_RADIUS 2L

main(void)
{
MIL_ID MilApplication, /* Application identifier. */
MilSystem, /* System identifier. */
MilDisplay, /* Display identifier. */
MilImage, /* Image buffer identifier. */
BinImage, /* Binary image buffer identifier. */
DilBinImage; /* Dilated binary image buffer identifier. */

/* Allocate defaults. */
MappAllocDefault(M_SETUP, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);

/* Restore source image into an image buffer and displays it. */
MbufRestore(IMAGE_FILE, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);

/* Allocate 2 binary image buffers for fast processing. */
MbufAlloc2d(M_DEFAULT, IMAGE_WIDTH, IMAGE_HEIGHT, 1+M_UNSIGNED, M_IMAGE+M_PROC, &BinImage);
MbufAlloc2d(M_DEFAULT, IMAGE_WIDTH, IMAGE_HEIGHT, 1+M_UNSIGNED, M_IMAGE+M_PROC, &DilBinImage);

/* Pause to show the original image. */
printf("\nThis program finds the exoskeletons of the particles in the displayed image.\n");
printf("Press <Enter> to continue.\n\n");
getch();

/* Binarize the image. */
MimBinarize(MilImage, BinImage, M_LESS_OR_EQUAL, IMAGE_THRESHOLD_VALUE, M_NULL);

/* Remove small particles. */
MimOpen(BinImage, BinImage, SMALL_PARTICLE_RADIUS, M_BINARY);

/* Dilate image (adds one pixel around all objects). */
MimDilate(BinImage, DilBinImage, 1L, M_BINARY);

/* XOR the dilated image with the original image. */
MimArith(BinImage, DilBinImage, BinImage, M_XOR);

/* Convert the binary image to a visible grayscale image (0-0xFF). */
MimBinarize(BinImage, MilImage, M_GREATER, 0, M_NULL);

/* Pause to show the resulting image. */
printf("Exoskeletons of the object's perimeters are being calculated.\n");
printf("Press <Enter> to end.\n");
getch();

/* Free all allocations. */
MbufFree(BinImage);
MbufFree(DilBinImage);
MbufFree(MilImage);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
}

신고
Posted by Frys

티스토리 툴바