Coded the minimization functions. Added a method to extract the neighborhood from image1 instead from 3D plane.