Here are the results of a MATLAB program I used to digitally flatten some images taken with my ST80 telescope.

Andromeda

Dumbbell Nebula

Firstly, we can see how much of the imaging area is lost as I have not edited the overall image size.

The results also show a reduction of stretching, particularly towards the edge of the images:

Here is a rough description of the process

The midpoint of the image is calculated, then for each point from the mid-point to the edge (for all possible edge points) a straight line of pixels is extracted. These pixels are then shifted inwards with the amount of shift depending on the distance from the midpoint. Pixels nearer the edge need to be shifted more than pixels in the middle. Through trial and error I derived this formula to squash the line of pixels.

Output = ceil(input/exp((input^1.2)/(6000*5)));

Where 6000 = the original image width

And where input and output can be seen as a function converting distance x to distance y on a graph (the red line is y=x). We can see that a pixel 3000 pixels from the centre gets shifted to about 1500 pixels from the centre whereas a pixel 500 pixels from the centre stays roughly where it was.

This is just a bit of rough work to exercise my computer programming. I did not bother coding a colour version. The results have not prevented me from buying an optical flattener which I now own!