I have an image data set consisting of pairs of JPG and RAW files. I was tasked with transforming JPG pixel coordinates (x, y) to RAW pixel coordinates (x_raw, y_raw). By comparing RAW and JPG images visually, it is clear that the device undistorts the images at some point of the image processing pipeline (RAW->JPG). Now, to undistort an image, you basically need a camera matrix and parameters of distortion (e.g. radial) that you get by calibration. This means that the device must store these parameters somehow.
My question is: how do cameras perform undistortion and how are calibration parameters derived?
Does each camera sensor get calibrated during the manufacturing process (and the parameters are written to memory of the device)? Or, perhaps, camera sensors of the same model store the same parameters that were derived by averaging parameters of many sensors?