等下才上原理,买大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);
}
}
}
}
}
}
200字以内,仅用于支线交流,主线讨论请采用回复功能。