Made code_parts a bit faster by using integral images for edge counts.