Created
March 26, 2013 17:23
-
-
Save alexbilbie/5247310 to your computer and use it in GitHub Desktop.
This file contains 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
$regions = []; | |
$potentialRegion = 0; | |
function adjacentPixelIsBlack($x, $y) | |
{ | |
if ( ! isset($matrix[$x][$y+1])) | |
{ | |
return false; | |
} | |
return ($matrix[$x][$y+1] === 1); | |
} | |
// Get all of the horizontal regions | |
foreach ($matrix as $row => $pixels) { | |
$x = $row; | |
$previousBlack = 0; | |
$regionStart = null; | |
foreach ($pixels as $y => $colour) | |
{ | |
// If colour is white then just continue | |
if ($colour === 0) | |
{ | |
if ($previousBlack === 1) | |
{ | |
$regions[] = [$regionStart, [$x, $y]]; | |
} | |
$previousBlack = 0; | |
continue; | |
} | |
if ($previousBlack === 1) | |
{ | |
continue; | |
} | |
else | |
{ | |
$regionStart = [$x, $y]; | |
} | |
} | |
} | |
// Convert regions which are adjacent horizontally into just one region | |
// Can't work out how to do this bit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment