Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum PoleWzorca {
- P, _0, _1, X, Y
- };
- struct Wzorzec {
- PoleWzorca type[3][3];
- };
- Wzorzec wzorce[6] = {
- {
- {
- {X, X, X},
- {_0, P, _0},
- {Y, Y, Y}
- }
- },
- {
- {
- {X, _0, Y},
- {X, P, Y},
- {X, _0, Y}
- }
- },
- {
- {
- {X, X, X},
- {_0, P, X},
- {_1, _0, X}
- }
- },
- {
- {
- {X, X, X},
- {X, P, _0},
- {X, _0, _1}
- }
- },
- {
- {
- {X, _0, _1},
- {X, P, _0},
- {X, X, X}
- }
- },
- {
- {
- {_1, _0, X},
- {_0, P, X},
- {X, X, X}
- }
- }
- };
- struct PointOffset {
- int x, y;
- } ptsRound[3][3] =
- {
- {{-1, -1}, {0, -1}, {1, -1}},
- {{-1, 0}, {0, 0}, {1, 0}},
- {{-1, 1}, {0, 1}, {1, 1}}
- };
- #define __p0 255
- #define __p1 0
- #define __p2 160
- #define __p3 64
- bool BMPHandler::CheckWzorzec(int X, int Y, Wzorzec wz)
- {
- bool
- x_present = false,
- y_present = false,
- x_satisfied = false,
- y_satisfied = false;
- for (int x = -1; x < 2; x++) {
- for (int y = -1; y < 2; y++) {
- PoleWzorca currType = wz.type[y + 1][x + 1];
- switch (currType) {
- case BMPHandler::PoleWzorca::X:
- x_present = true;
- if (GetPixel8(X + x, Y + y) != __p0) x_satisfied = true;
- break;
- case BMPHandler::PoleWzorca::Y:
- y_present = true;
- if (GetPixel8(X + x, Y + y) != __p0) y_satisfied = true;
- break;
- case BMPHandler::PoleWzorca::_0:
- if (GetPixel8(X + x, Y + y) != __p0) return false;
- break;
- case BMPHandler::PoleWzorca::_1:
- if (GetPixel8(X + x, Y + y) == __p0) return false;
- break;
- case BMPHandler::PoleWzorca::P:
- break;
- }
- }
- }
- if (x_present && !x_satisfied) return false;
- if (y_present && !y_satisfied) return false;
- return true;
- }
- void BMPHandler::Pavlids()
- {
- Threshold(127);
- PointOffset pts[4] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1} };
- int imgWidth = ptrInfoHeader->biWidth;
- int imgHeight = ptrInfoHeader->biHeight;
- bool remain = true;
- while (remain == true)
- {
- remain = false;
- // For j := 1, 3, 5, 7
- for (int j = 0; j < 4; j++)
- {
- // For wszystkie piksele obrazu
- for (int x = 0; x < imgWidth; x++)
- {
- for (int y = 0; y < imgHeight; y++)
- {
- // If p = 1 and j-ty sasiad = 0
- if (GetPixel8(x, y) == __p1 && GetPixel8(x + pts[j].x, y + pts[j].y) == __p0)
- {
- bool skel = false;
- // For wszystkie wzorce W
- for (int wzNum = 0; wzNum < 6; wzNum++)
- {
- if (CheckWzorzec(x, y, wzorce[wzNum])) {
- skel = true;
- break;
- }
- }
- // If skel = true then p := 2
- if (skel) {
- SetPixel8(x, y, __p2);
- }
- else {
- SetPixel8(x, y, __p3);
- remain = true;
- }
- }
- }
- }
- // For wszystkie piksele obrazu jeżeli p == 3 to usun p (p == 0);
- for (int x = 0; x < imgWidth; x++)
- {
- for (int y = 0; y < imgHeight; y++)
- {
- if (GetPixel8(x, y) == __p3) SetPixel8(x, y, __p0);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement