Matlab Image Processing Code for IPA