This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

这是imglib库中的函数,读不懂程序,它到底是如何实现膨胀操作的???



void IMG_dilate_bin_c
(
const unsigned char *restrict in_data,
unsigned char *restrict out_data,
const char *restrict mask,
int cols
)
{
int i;
unsigned long p0l, p3l, p6l;
unsigned p0, p1, p2, p3, p4, p5, p6, p7, p8, r;

/* -------------------------------------------------------------------- */
/* Iterate over the input, processing 32 pixels per iteration. */
/* -------------------------------------------------------------------- */
for (i = 0; i < cols; i += 4)
{
/* ---------------------------------------------------------------- */
/* Load in our 34-bit by 3-bit context for applying the 3x3 mask. */
/* ---------------------------------------------------------------- */
p0l = ((unsigned) in_data[i + 0] ) |
((unsigned) in_data[i + 1] << 8 ) |
((unsigned) in_data[i + 2] << 16) |
((unsigned) in_data[i + 3] << 24) |
((unsigned long)in_data[i + 4] << 32);

p3l = ((unsigned) in_data[i + cols + 0] ) |
((unsigned) in_data[i + cols + 1] << 8 ) |
((unsigned) in_data[i + cols + 2] << 16) |
((unsigned) in_data[i + cols + 3] << 24) |
((unsigned long)in_data[i + cols + 4] << 32);

p6l = ((unsigned) in_data[i + cols*2 + 0] ) |
((unsigned) in_data[i + cols*2 + 1] << 8 ) |
((unsigned) in_data[i + cols*2 + 2] << 16) |
((unsigned) in_data[i + cols*2 + 3] << 24) |
((unsigned long)in_data[i + cols*2 + 4] << 32);

/* ---------------------------------------------------------------- */
/* Generate 3 offset copies of each row so that we can perform */
/* ANDs between pixels that are neighbors. */
/* ---------------------------------------------------------------- */
p0 = p0l; p1 = p0l >> 1; p2 = p0l >> 2;
p3 = p3l; p4 = p3l >> 1; p5 = p3l >> 2;
p6 = p6l; p7 = p6l >> 1; p8 = p6l >> 2;

/* ---------------------------------------------------------------- */
/* Now sum the filtered pixels together by ORing. */
/* ---------------------------------------------------------------- */
r = 0;
if (mask[0] >= 0) r |= p0;
if (mask[1] >= 0) r |= p1;
if (mask[2] >= 0) r |= p2;
if (mask[3] >= 0) r |= p3;
if (mask[4] >= 0) r |= p4;
if (mask[5] >= 0) r |= p5;
if (mask[6] >= 0) r |= p6;
if (mask[7] >= 0) r |= p7;
if (mask[8] >= 0) r |= p8;

/* ---------------------------------------------------------------- */
/* Write the result as four bytes. */
/* ---------------------------------------------------------------- */
out_data[i + 0] = (r >> 0) & 0xFF;
out_data[i + 1] = (r >> 8) & 0xFF;
out_data[i + 2] = (r >> 16) & 0xFF;
out_data[i + 3] = (r >> 24) & 0xFF;
}
}

有明白的人吗???给我讲讲程序吧

  • 你好,

    膨胀的原理都是一样的,下面是网上找到的一些信息。

    胀是将与物体接触的所有背景点合并到该物体中,使边界向外部扩张的过程。

    可以用来填补物体中的空洞。
    膨胀的算法:
    用3x3的结构元素,扫描图像的每一个像素
    用结构元素与其覆盖的二值图像做“与”操作
    如果都为0,结果图像的该像素为0。否则为1
    结果:使二值图像扩大一圈

    这个代码的区别是一次处理4个像素.