Remove parallax from picture

This is something my iPhone pdf scanner does really well. I am trying to make my code do this in Igor. I suspect ImageInterpolate is the way to go, but may be I am missing something better? 

I need to straighten edges of object which is viewed under angle by camera. Manually, with user help... I imported object as image. Next I would like to have user somehow designate the four corners (object is always rectangle) and ideally give them real world dimensions (e.g., {0,0}, {0,200}, {300,0} and {300,200} are meaningful dimensions in mm). And have image modified (warped?) so the object is now rectangle with proper size ratio and I can trim outside and set its dimensions to 200mm and 300mm. 

I played with the Image Warping demo, but I am not that smart after this. How should I approach this? I do not need code, I am looking for sequence of steps and easy to use method (for user!) to get input from user. 

Image processing is not something I do routinely and there are much better experts in here... 

That's an interesting problem to solve. I would think I is always better to turn to image manipulation software which is already very good at this kind of problem (e.g., gimp, imagemagick, even photoshop i guess). There is even a script which fixes perspective distortion automatically: http://www.fmwconcepts.com/imagemagick/unperspective/index.php  I think you could run it from Igor with ExecuteScriptText, then process the result further.

But If you want to do it in Igor manually, then I think the process like shown in the Image Warping demo would be the best choice:

1) Display the image and overlay 4-point X- and Y-coordinate waves onto the image as markers. Keep a copy of the coordinate waves as reference for later.

2) Create some method to move the waves marker points with the mouse, and ask the user to set the markers onto the 4 corners of your projected paper.

3) Interpolate the image with ImageInterpolate by using the original and moved coordinates.

Alternatively, you can use 4 graph cursors instead of wave marker, which are easy to move with the mouse (but might disappear from the graph). Then read the current cursor positions as one coordinate wave-set while the initial positions will give the reference coordinate wave-set.

Do you have an example where this could be tested?

Thanks for suggestions 

I hate running executeStripttext - this is always fragile and platform dependent. Have done that more than I wish to remember... 

I have simply paralaxed image of a empty page for now. It is here: https://www.dropbox.com/s/8lzl2haep4tqos3/DistortedPage.jpeg?dl=1 Needlessly too large resolution, but it should be standard letter page. If you want to play, I always appreciate smarts of others.

I'll try to follow instructions, these steps make the process bit more clear.

User input is something I have been thinking a lot about first - may be cursor and button, with sets of values for distorted and wished position? User picks corner, reads values by button and assigns corrected x/y values... That seems easiest. 

Hi,

What I have done in the past to guide the user takes advantage of some knowledge of the incoming image. From a control panel I start the process with a button that changes text as you progress through so they are always looking at the same spot.  For my images, typically SEM (scanning electron images) I need to set the magnification and the scale bar is in the lower right hand side.  So when I first start the process I enlarge the image around the expected bar making sure to keep the XY scaling the same so they don't get disoriented.  I put some hair cursors in roughly the expected position and ask them to fine position.  In the example image here, both ends are set. The next step opens a dialog to enter the measured value with a default given.  I have used the similar technique to do orientation and positioning of image rotation for alignment purposes using similar methods.  I just walked the user through.

Another technique is to look at the igor thief procedure for stealing data from a image graph.

Andy

cursors.png