Apparatus, comprising: a probe configured to be inserted into a human patient; first sensors (24, 26) attached to the probe; I a sheath configured for the probe to be inserted therethrough; second sensors attached to the sheath; and I a processor, characterized in that the processor is configured to: calculate locations of the first sensors attached to the probe, calculate positions of the second sensors attached to the sheath, I calculate respective shapes of the probe and the sheath, to achieve a best fit to the calculated probe sensor locations and sheath sensor positions, while restricting the probe to pass through the sheath, wherein calculating the respective shapes of the probe and the sheath comprises minimizing a cost function to determine a best match between a calculated location and a measured location, the cost function being a weighted combination of intrinsic energy, position error and orientation error and incorporating a slide variable having a value related to a distance between distal ends of the probe and sheath into the cost function, and I correct image misalignment using the calculated respective shapes of the probe and the sheath to present an image of the sheath aligned with the probe. a probe configured to be inserted into a human patient; first sensors (24, 26) attached to the probe; I a sheath configured for the probe to be inserted therethrough; second sensors attached to the sheath; and I a processor, characterized in that the processor is configured to: calculate locations of the first sensors attached to the probe, calculate positions of the second sensors attached to the sheath, I calculate respective shapes of the probe and the sheath, to achieve a best fit to the calculated probe sensor locations and sheath sensor positions, while restricting the probe to pass through the sheath, wherein calculating the respective shapes of the probe and the sheath comprises minimizing a cost function to determine a best match between a calculated location and a measured location, the cost function being a weighted combination of intrinsic energy, position error and orientation error and incorporating a slide variable having a value related to a distance between distal ends of the probe and sheath into the cost function, and I correct image misalignment using the calculated respective shapes of the probe and the sheath to present an image of the sheath aligned with the probe. calculate locations of the first sensors attached to the probe, calculate positions of the second sensors attached to the sheath, I calculate respective shapes of the probe and the sheath, to achieve a best fit to the calculated probe sensor locations and sheath sensor positions, while restricting the probe to pass through the sheath, wherein calculating the respective shapes of the probe and the sheath comprises minimizing a cost function to determine a best match between a calculated location and a measured location, the cost function being a weighted combination of intrinsic energy, position error and orientation error and incorporating a slide variable having a value related to a distance between distal ends of the probe and sheath into the cost function, and I correct image misalignment using the calculated respective shapes of the probe and the sheath to present an image of the sheath aligned with the probe.