Getting transformation (6D) between two frames

Depending only on the IMU (No GPS or other sensors), I want to get transformation that happened between two frames (two moments) which includes YAW, PITCH, ROLL, X, Y, Z.

How to do it with Ardupiolet?

P.S. I am aware that the transformation is not accurate. I just need it as an initial guess.

use the LOCAL_POSITION_NED and ATTITUDE mavlink messages. And subtract the two moments in time

Thanks for your reply. For attitude, it is OK. However, for LOCAL_POSITION_NED, does the x,y and z come from IMU? The GPS is not part of it?