Revert "Removed experimental code on cropping flags"

This reverts commit 31882d19c497310d344fb3340ffad17abf379961.
Fixed cropping test
Fixing gradient vector computation