Created
May 5, 2013 08:30
-
-
Save azmfaridee/5520132 to your computer and use it in GitHub Desktop.
Proof of concept of detecting edge in a 2 bit bitmap image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <iostream> | |
using namespace std; | |
/* | |
* | |
*/ | |
int main(int argc, char** argv) { | |
int bitmapImage[3][10] = { { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, | |
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, | |
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }; | |
for (int i = 0; i < 3; i++) { | |
for (int j = 0; j < 10; j++) { | |
cout << bitmapImage[i][j] << " "; | |
} | |
cout << endl; | |
} | |
for (int i = 0; i < 3; i++) { | |
bool flipped = false; | |
for (int j = 0; j < 8; j++) { | |
if (bitmapImage[i][j+1] == 1 && bitmapImage[i][j+2] == 1) { | |
if (flipped == true && (bitmapImage[i][j] == 0)) { | |
// check for 011 and flipped true, i.e. again 111 | |
bitmapImage[i][j+1] = 0; | |
flipped = true; | |
} else if (flipped == false && (bitmapImage[i][j] == 1)) { | |
//flipped = false so check for 111 | |
bitmapImage[i][j+1] = 0; | |
flipped = true; | |
} else { | |
// u did nothing, so set flipped to false | |
flipped = false; | |
} | |
} else { | |
// u did nothing, so set flipped to false | |
flipped = false; | |
} | |
} | |
} | |
cout << "After change" << endl; | |
for (int i = 0; i < 3; i++) { | |
for (int j = 0; j < 10; j++) { | |
cout << bitmapImage[i][j] << " "; | |
} | |
cout << endl; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment