Wood density is an important quality variable, closely related to the mechanical properties of the wood. Precise wood density measurements in the log sorting would enable density sorting of logs for products such as strength-graded wood and finger-jointed wood. Density sorting of logs would also give more homogeneous drying properties and thus improve the quality of the final products. By compensating the radiographs from an X-ray log scanner for the varying path lengths using outer shape data from a three-dimensional (3D) scanner, it is possible to make precise estimates of both green and dry density. Measurements on simulated industrial data were compared with densities measured in computed tomographic (CT) images for 560 Scots pine (Pinus sylvestris L.) logs. It was found that green sapwood density could be measured with predictability R 2=0.65 and root mean square error (RMSE) of 25 kg m-3. Green and dry heartwood densities were measured with similar precision: R 2=0.79 and RMSE=32 kg m-3 for green density and R 2=0.83 and RMSE=32 kg m-3 for dry density.