The Emirates Mars Mission (EMM) has returned an abundance of whole disk images of Mars at visible wavelengths. Clouds and hazes are evident at the limb of the planet in many of these images, offering an opportunity to determine the vertical distribution of clouds on Mars over the course of a Martian year. However, there are challenges in determining the height of limb clouds due to uncertainty in the location of the Martian surface in the images. This uncertainty comes primarily from small uncertainties in the pointing of the instrument, coupled with the fact that the surface can be difficult to identify in the images due to the opacity of the atmosphere at low altitudes. With a typical pixel spanning roughly 5 km on the limb, the uncertainties in cloud height can be large. Here we present an algorithm for automatically detecting limb clouds and hazes in Emirates eXploration Imager (EXI) observations, while simultaneously detecting the location of the surface. The algorithm considers straight line ‘transects’ through the images that extend from space to the disk of the planet. The inflection point in the recorded intensity along the transect (i.e. from ‘space’ where the intensity is small, to ‘Mars’ where the intensity is large) is used to determine the location of the surface. The transect is also used to infer the presence of detached clouds, as well as surface hazes. The heights and thicknesses of clouds and hazes can be extracted from the transects. We will present the algorithm, as well as a comparison of how the results of the algorithm compare to manual analysis of EXI images. We will highlight where the algorithm does well and where it has difficulty, and how the algorithm might be used to analyze other planetary datasets.