Canopy height models (CHMs) derived from lidar data have been applied to extract forest inventory parameters. However, variations in modeled height cause data pits, which form a challenging problem as they disrupt CHM smoothness, negatively affecting tree detection and subsequent biophysical measurements. These pits appear where laser beams penetrate deeply into a tree crown, hitting a lower branch or the ground before producing the first return. In this study, we develop a new algorithm that generates a pit-free CHM raster, by using subsets of the lidar points to close pits. The algorithm operates robustly on high-density lidar data as well as on a thinned lidar dataset. The evaluation involves detecting individual trees using the pit-free CHM and comparing the findings to those achieved by using a Gaussian smoothed CHM. The results show that our pit-free CHMs derived from highand low-density lidar data significantly improve the accuracy of tree detection.