A method includes, following specification of an initial transformation as a test transformation that is to be optimized, determining a 2D gradient x-ray image and a 3D gradient dataset of the image dataset, carrying out, for each image element of the gradient comparison image, a check for selection as a contour point, and determining an environment best corresponding to a local environment of the contour point and extending around a comparison point in the gradient x-ray image for all contour points in the at least one gradient comparison image. Local 2D displacement information is determined by comparing the contour points with the associated comparison points, and motion parameters of a 3D motion model describing a movement of the target region between the acquisition of the image dataset and the x-ray image are determined from the displacement information and a registration transformation describing the registration.