Optimized code for calculating chain code, so it will provide more similar values for identical characters.
Added code to normalize chain codes, so all chain codes will be of equal length.