Detecting shapes in an image

Thanks for sharing ideas to optimize @Micka. Had been away due to a personal exigency.

Yes, had implemented this to short-circuit and fail-fast.

Will look at implementing other approaches for optimization.