Image data from a camera and depth information from a depth sensor, such as a LiDAR system, are used to segment an image for decoding an optical pattern. The image data is spatially correlated with the depth information. The depth information is used to partition the image into one or more foreground segments and one or more background segments. Scanning for the optical pattern is performed on the one or more foreground segments.