Created
March 28, 2013 13:42
-
-
Save jaydp17/5263201 to your computer and use it in GitHub Desktop.
The array version
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
public Boundaries CheckBoundaries(int[] pixels) { | |
// check left | |
double boundayFactor = 0.1; //10% of the image width/height | |
Boundaries b = new Boundaries(); | |
b.Left = CheckLeft(pixels, boundayFactor); | |
b.Right = CheckRight(pixels, boundayFactor); | |
b.Top = CheckTop(pixels, boundayFactor); | |
b.Bottom = CheckBottom(pixels, boundayFactor); | |
return b; | |
} | |
private bool CheckLeft(int[] bmp, double bf) | |
{ | |
for (int i = 0; i < (int)(this.width*bf); i++) | |
{ | |
int count = 0; | |
for (int j = 0; j < this.height-1; j++) | |
{ | |
if (GetPixel(bmp,i, j) != 0) | |
{ | |
count++; | |
} | |
} | |
if (count > 12) | |
return true; | |
} | |
return false; | |
} | |
private bool CheckRight(int[] bmp, double bf) | |
{ | |
for (int i = this.width-1; i > (int)(this.width * (1-bf)); i--) | |
{ | |
int count = 0; | |
for (int j = 0; j < this.height-1; j++) | |
{ | |
if (GetPixel(bmp,j, i) != 0) | |
{ | |
count++; | |
} | |
} | |
if (count > 12) | |
return true; | |
} | |
return false; | |
} | |
private bool CheckTop(int[] bmp, double bf) | |
{ | |
for (int i = 0; i < (int) (this.height*bf); i++) | |
{ | |
int count = 0; | |
for (int j = 0; j < this.width-1; j++) | |
{ | |
if (GetPixel(bmp,j, i) != 0) | |
{ | |
count++; | |
} | |
} | |
if (count > 12) | |
return true; | |
} | |
return false; | |
} | |
private bool CheckBottom(int[] bmp, double bf) | |
{ | |
for (int i = this.height - 1; i > (int)(this.height * (1 - bf)); i--) | |
{ | |
int count = 0; | |
for (int j = 0; j < this.width-1; j++) | |
{ | |
if (GetPixel(bmp,j, i) != 0) | |
{ | |
count++; | |
} | |
} | |
if (count > 12) | |
return true; | |
} | |
return false; | |
} | |
private int GetPixel(int[] pixels, int i, int j) | |
{ | |
return pixels[((this.width-1) * i) + j]; | |
} | |
public class Boundaries { | |
public bool Left { get; set; } | |
public bool Right { get; set; } | |
public bool Top { get; set; } | |
public bool Bottom { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment