Method and system for acquisition of optimal images of object in multi-layer sample