Since erosion and dilatation also work on non-binary images, you can write
img = imread('http://i.stack.imgur.com/qPiA3.png'); ei = imerode(img,ones(3)); di = imdilate(img,ones(3)); boundaries = ei~=img | di~=img;
The result is a bw image that has a border on the edge of each color area (so the line border will be two pixels wide).

Note that this will not return an ordered list of pixels as bwboundaries , but rather a bwboundaries boolean mask that imoverlay needs for input.
Jonas source share