Since a few people have asked how to get a chain code from an image I have written a simple script to do this.
You can download the script here: https://raw2.github.com/maximilianallan/mk_chain/master/mk_chain.m
The script is really simple and makes some assumptions about a single contour in the image but should be easy to modify if needed.
>> chain = mk_chain('path/to/image.png');
>> [cc] = chaincode(chain);