Matlab code for crystal shape estimation