Here is one way to add a “sticker effect” to your image ...
A Demo: http://jsfiddle.net/m1erickson/Q2j3L/

Start by drawing the original image on the main canvas.

Divide the image into "discrete elements".
Discrete elements consist of groups of pixels that are related to each other but not related to other elements. For example, each individual sprite on a sprite will be a discrete element.
You can find discrete groups of pixels using an edge detection algorithm such as marching squares.
Place each discrete item on its own canvas for further processing. Also remove this discrete element from the main canvas (so that it is not processed again).

Define a path for each discrete element.
You can use the marching squares algorithm again to detect the edge. The result of the marching squares is an array of x / y coordinates that form the outer contour of the element
Create a Sticker Effect
You can create a sticker effect by placing a stroked white outline around each element. Do this by stroking the contour of the contour that you calculated above. You can optionally add a shadow to the stroke.
Note: strokes in the canvas are always drawn half inside and half out of the way. This means that the barcode sticker will invade the element. To fix this: after you have drawn the sticker, you must redraw the element on top. This overwrites the minor part of the sticker.

Rearrange final image including sticker effect
Rearrange the final image by overlaying each element canvas on the main canvas

Here is the code for the annotated code:
<!doctype html> <html> <head> <link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <script src="http://code.jquery.com/jquery.min.js"></script> <script src="marching squares.js"></script> <style> body{ background-color:silver; } canvas{border:1px solid red;} </style> <script> $(function(){ </script> </head> <body> <canvas id="canvas" width=300 height=300></canvas><br> </body> </html>
This is the marching square edge detection algorithm (from the excellent open source d3 library):
/** * Computes a contour for a given input grid function using the <a * href="http://en.wikipedia.org/wiki/Marching_squares">marching * squares</a> algorithm. Returns the contour polygon as an array of points. * * @param grid a two-input function(x, y) that returns true for values * inside the contour and false for values outside the contour. * @param start an optional starting point [x, y] on the grid. * @returns polygon [[x1, y1], [x2, y2], ...] */ (function(){ geom = {}; geom.contour = function(grid, start) { var s = start || d3_geom_contourStart(grid), // starting point c = [], // contour polygon x = s[0], // current x position y = s[1], // current y position dx = 0, // next x direction dy = 0, // next y direction pdx = NaN, // previous x direction pdy = NaN, // previous y direction i = 0; do { // determine marching squares index i = 0; if (grid(x-1, y-1)) i += 1; if (grid(x, y-1)) i += 2; if (grid(x-1, y )) i += 4; if (grid(x, y )) i += 8; // determine next direction if (i === 6) { dx = pdy === -1 ? -1 : 1; dy = 0; } else if (i === 9) { dx = 0; dy = pdx === 1 ? -1 : 1; } else { dx = d3_geom_contourDx[i]; dy = d3_geom_contourDy[i]; } // update contour polygon if (dx != pdx && dy != pdy) { c.push([x, y]); pdx = dx; pdy = dy; } x += dx; y += dy; } while (s[0] != x || s[1] != y); return c; }; // lookup tables for marching directions var d3_geom_contourDx = [1, 0, 1, 1,-1, 0,-1, 1,0, 0,0,0,-1, 0,-1,NaN], d3_geom_contourDy = [0,-1, 0, 0, 0,-1, 0, 0,1,-1,1,1, 0,-1, 0,NaN]; function d3_geom_contourStart(grid) { var x = 0, y = 0; // search for a starting point; begin at origin // and proceed along outward-expanding diagonals while (true) { if (grid(x,y)) { return [x,y]; } if (x === 0) { x = y + 1; y = 0; } else { x = x - 1; y = y + 1; } } } })();
Note. This code separates the process of applying a label outline to a single function. This is done if you want to have several layers around your discrete element. For example, you may need a second gray frame on the outside of the sticker. If you don’t need to apply “layers”, you can apply a sticker in the moveDiscreteElementToNewCanvas function.