Created
June 1, 2016 18:49
-
-
Save cglosser/ec398ede219dec64cdc7cd6525eac505 to your computer and use it in GitHub Desktop.
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
(*Grab the image off the web*) | |
img = Import["http://i.imgur.com/XgrV1va.jpg"]; | |
(*Cut it down to just the maze*) | |
croppedImg = ImageTrim[ | |
img, | |
{ | |
{3097.716894977169`, 288.36529680365334`}, | |
{3033.4246575342463`, 1346.2648401826486`}, | |
{432.5114155251141`, 1355.0319634703199`}, | |
{350.68493150684935`, 273.7534246575344`} | |
} | |
]; | |
(*Make the maze black & white so it's easier to process*) | |
bwImg = Binarize[croppedImg]; | |
(*WatershedComponents[] will give the basins of attraction; the maze | |
solution lies on a boundary between basins, so this picks out that boundary*) | |
boundary = Image[Clip[1 - WatershedComponents[bwImg], {0, 1}]]; | |
(*Now just draw the path on top of the original image*) | |
HighlightImage[croppedImg, Dilation[boundary, 5], "HighlightColor" -> Purple] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Additional Comments: mazes may need borders, and thicker lines. Additional research on how the watershed algorithm actually works to create the boundary between basins would also be helpful. Additional note- tested with a maze that used loops rather than dead ends- disastrous results