1. A method for registering a three-dimensional (3D) image dataset of a target region of a patient with a two-dimensional (2D) x-ray image of the target region recorded in an acquisition geometry, the method comprising: 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; determining at least one 2D gradient comparison image forward-projected in the acquisition geometry of the x-ray image using the test transformation from the 3D gradient dataset after the determining of the 2D gradient x-ray image and the 3D gradient dataset of the image dataset, wherein depth information describing a depth in a radiation direction of a central beam of the acquisition geometry is associated in the at least one 2D gradient comparison image with gradients described two-dimensionally in an image plane; carrying out a check for each image element of the at least one 2D gradient comparison image to determine whether the gradient described two-dimensionally in the image plane satisfies a selection criterion indicating the presence of a contour in the image element, wherein all image elements satisfying the selection criterion are selected as contour points; determining an environment that best corresponds to a local environment of the contour point based on a comparison measure, and extends around a comparison point in the gradient x-ray image for all contour points in the at least one gradient comparison image from a plurality of environments extending around test points; determining local 2D displacement information, the determining of the local 2D displacement information comprising comparing the contour points with the associated comparison points; and determining motion parameters of a 3D motion model that describe a movement of the target region between the acquisition of the image dataset and the x-ray image from the local 2D displacement information and a registration transformation describing the registration by correcting the test transformation based on the motion parameters.