Since you have a bitmap, you can use a bitmap algorithm.
Here is a working example (in JSFiddle or see below). (Firefox, Chrome, but not IE)
pseudo code:
// part 1: occlusion mark all pixels as 'outside' for each pixel on the edge of the image draw a line from the source pixel to the edge pixel and for each pixel on the line starting from the source and ending with the edge if the pixel is gray mark it as 'inside' otherwise stop drawing this line // part 2: edge finding for each pixel in the image if pixel is not marked 'inside' skip this pixel if pixel has a neighbor that is outside mark this pixel 'edge' // part 3: draw the edges highlight all the edges
At first it sounds pretty awful ... But actually it is O(p) , where p is the number of pixels in your image.
The full code here works best on the page:
var c = document.getElementById('c'); c.width = c.height = 500; var x = c.getContext("2d");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script> <center><div id="d">Click on image to change point</div> <canvas id="c"></canvas></center>
Kaganar
source share