I have a challenge to propose for the skilled programmers out there: implement an automatic perspective correction tool.
Actually I am in the process of porting Darktable’s perspective correction tool into PhotoFlow, and I thought it would be great to add some sort of auto-guessing of the optimal perspective correction transform, based on the pattern of straight lines found in the image.
Now I’m perfectly aware that this might be much easier to say than to implement, but who knows? Maybe some skilled and experienced programmers in this community could come up with a neat solution…
Darktable’s perspective correction works by defining the four corners of a quadrilater that should be transformed into a rectangle in the corrected image. Therefore the goal would be to automatically “guess” the most appropriate corners for a given image.
Of course this could also be backported into Darktable, if the developers are interested!
AFAIK huggin already contains something like that. Might be a fun hack, but I do somewhat doubt that it will be reliable enough to actually be useful given that the manual correction is not a lot of work either.
That’s right if you do it for one image. But if you have to do it for 100 images it could be a big improvement.
A similar tool would be cool to rotate an image to make the horizon straight.
Thanks, I will look into the OpenCV option in more detail…
Concerning hugin, it adjusts roll and pitch, but I think that for a complete perspective correction one also needs to correct the yaw, right?
This is why one needs to start from a generic quadrangle, and transform it into a rectangle (if I understood the underlying math well enough ;-)).
Based on all the suggestions and examples I’ve received so far, I’ve started to figure out a possible scheme:
Detect edges (with sobel, difference of gaussians, g’mic “gradient norm” or whatever works best)
Split the edge image into tiles, and for each tile search for straight lines
Merge straight lines across tiles, and rank lines in terms of number of crossed tiles
Build all possible quadrilateral regions with the detected lines, and rank the regions in terms of surface, number of edge pixels along the borders of the region, similarity with a rectangle (assuming the distortion we want to correct is not “too extreme”), and maybe something more
Assuming that the object we want to straighten occupies a significant fraction of the frame, and that it is not extremely distorted, we are looking for a quadrilateral region with one corner in each image quadrant and with sides that are approximately perpendicular.
Still rather vague, but maybe a good starting point for further discussions.