An example of sporadic motion that causes difficulty in CT scanning is gas pockets moving around the rectum. The invention allows the automatic detection of such movements, by enhancing low density features around the prostate in the individual X-ray images, projecting these features on the cranio-caudal axis (assuming that the gas predominantly moves in this direction) to form a 1-dimensional image, and combining successive ID projections to form a 2D image. Moving gas will produce tilted lines in this image, identifying an angular range that needs to be discarded. Such a process can be used in an image processing apparatus of a CT scanner.