文号
t18137
阅读
3423
回复
3
收藏
2
咩咩咩 骨架算法 代码代码
2009/07/31
IP:广东
等下才上原理,买大M去了~~~~

public: void __gc* ThiningPic(Int32 __gc* dgGrayValue)
{
    Int32 __gc* lWidth = this->bmpobj->Width;
    Int32 __gc* lHeight = this->bmpobj->Height;
    Int32 __gc* neighbour __gc [,] = __gc new Int32 __gc*[5, 5];
    Boolean __gc* bModified = true;
    while (bModified)
    {
        bModified = false;
        for (Int32 __gc* j = 2; (j < (lHeight - 2)); j++)
        {
            for (Int32 __gc* i = 2; (i < (lWidth - 2)); i++)
            {
                Boolean __gc* bCondition1 = false;
                Boolean __gc* bCondition2 = false;
                Boolean __gc* bCondition3 = false;
                Boolean __gc* bCondition4 = false;
                if (this->bmpobj->GetPixel(i, j)->R > dgGrayValue)
                {
                    if (this->bmpobj->GetPixel(i, j)->R < 0xff)
                    {
                        this->bmpobj->SetPixel(i, j, Color::White);
                    }
                }
                else
                {
                    for (Int32 __gc* m = 0; (m < 5); m++)
                    {
                        for (Int32 __gc* n = 0; (n < 5); n++)
                        {
                            neighbour[m, n] = ((this->bmpobj->GetPixel(((i + m) - 2), ((j + n) - 2))->R < dgGrayValue) ? 1 : 0);
                        }
                    }
                    Int32 __gc* nCount = (((((((neighbour[1, 1] + neighbour[1, 2]) + neighbour[1, 3]) + neighbour[2, 1]) + neighbour[2, 3]) + neighbour[3, 1]) + neighbour[3, 2]) + neighbour[3, 3]);
                    if ((nCount >= 2) && (nCount <= 6))
                    {
                        bCondition1 = true;
                    }
                    nCount = 0;
                    if ((neighbour[1, 2] == 0) && (neighbour[1, 1] == 1))
                    {
                        nCount++;
                    }
                    if ((neighbour[1, 1] == 0) && (neighbour[2, 1] == 1))
                    {
                        nCount++;
                    }
                    if ((neighbour[2, 1] == 0) && (neighbour[3, 1] == 1))
                    {
                        nCount++;
                    }
                    if ((neighbour[3, 1] == 0) && (neighbour[3, 2] == 1))
                    {
                        nCount++;
                    }
                    if ((neighbour[3, 2] == 0) && (neighbour[3, 3] == 1))
                    {
                        nCount++;
                    }
                    if ((neighbour[3, 3] == 0) && (neighbour[2, 3] == 1))
                    {
                        nCount++;
                    }
                    if ((neighbour[2, 3] == 0) && (neighbour[1, 3] == 1))
                    {
                        nCount++;
                    }
                    if ((neighbour[1, 3] == 0) && (neighbour[1, 2] == 1))
                    {
                        nCount++;
                    }
                    if (nCount == 1)
                    {
                        bCondition2 = true;
                    }
                    if (((neighbour[1, 2] * neighbour[2, 1]) * neighbour[2, 3]) == 0)
                    {
                        bCondition3 = true;
                    }
                    else
                    {
                        nCount = 0;
                        if ((neighbour[0, 2] == 0) && (neighbour[0, 1] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[0, 1] == 0) && (neighbour[1, 1] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[1, 1] == 0) && (neighbour[2, 1] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[2, 1] == 0) && (neighbour[2, 2] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[2, 2] == 0) && (neighbour[2, 3] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[2, 3] == 0) && (neighbour[1, 3] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[1, 3] == 0) && (neighbour[0, 3] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[0, 3] == 0) && (neighbour[0, 2] == 1))
                        {
                            nCount++;
                        }
                        if (nCount != 1)
                        {
                            bCondition3 = true;
                        }
                    }
                    if (((neighbour[1, 2] * neighbour[2, 1]) * neighbour[3, 2]) == 0)
                    {
                        bCondition4 = true;
                    }
                    else
                    {
                        nCount = 0;
                        if ((neighbour[1, 1] == 0) && (neighbour[1, 0] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[1, 0] == 0) && (neighbour[2, 0] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[2, 0] == 0) && (neighbour[3, 0] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[3, 0] == 0) && (neighbour[3, 1] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[3, 1] == 0) && (neighbour[3, 2] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[3, 2] == 0) && (neighbour[2, 2] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[2, 2] == 0) && (neighbour[1, 2] == 1))
                        {
                            nCount++;
                        }
                        if ((neighbour[1, 2] == 0) && (neighbour[1, 1] == 1))
                        {
                            nCount++;
                        }
                        if (nCount != 1)
                        {
                            bCondition4 = true;
                        }
                    }
                    if (((bCondition1 && bCondition2) && bCondition3) && bCondition4)
                    {
                        this->bmpobj->SetPixel(i, j, Color::White);
                        bModified = true;
                    }
                    else
                    {
                        this->bmpobj->SetPixel(i, j, Color::Black);
                    }
                }
            }
        }
    }
}



+500
科创币
我说要有光
2009/07/31
有爱
17年6个月前IP:未同步
134520
1楼
那一堆"if ((neighbour[1, 1] == 0) && (neighbour[2, 1] == 1))"应该想法精简
引用
评论
93°作者
17年6个月前IP:未同步
134524
2楼
概念验证而已,不过懒得弄了 = = 看电影去……偶也
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的