Photoshop solution to keystoning, etc.

Discussions, questions, comments, ideas, and your projects having to do with DIY Book Scanner software. This includes the Stereo Data Maker software for the cameras, post-processing software, utilities, OCR packages, and so on.

Moderator: peterZ

Post Reply
spamsickle
Posts: 596
Joined: 06 Jun 2009, 23:57

Photoshop solution to keystoning, etc.

Post by spamsickle »

I know it isn't free, but I've seen Photoshop CS2 selling on eBay for around $100, so it isn't necessarily exorbitant either. I thought I'd share a quick tutorial on the batch processing which is available in Photoshop to automate post-processing of DIY Book Scanner scans. While different people are using different hardware, these scanners tend to produce scans in which right-hand pages are generally consistent with each other as far as size, keystoning, illumination, etc.. The same is true for left-hand pages. The right-hand pages are usually not consistent with the left-hand pages, but Photoshop can help correct the inconsistencies.

I start by creating a new folder on my computer for the book. Within that folder, I create 5 sub-folders: RRAW, LRAW, R, L, and Both. I begin by loading the right-hand images from my camera's SD card to RRAW, and the left-hand images to LRAW. Then, I'll create a Photoshop action which will process the images in RRAW and write the processed images to R, and run that as a batch process to automatically process each page.

Begin by opening a regular page from the RRAW directory. I generally wouldn't choose the cover of a hardback book, because it will be a bit bigger than the pages you want to process. If the "Actions" panel is not visible, you can add it from the Window menu, or toggle it on with Alt-F9.
S_1.JPG
S_1.JPG (135.15 KiB) Viewed 18106 times
Click on the "Create New Action" button at the bottom of the "Actions" panel. It's the square-within-a-square next to the trash can.
S_2.JPG
S_2.JPG (34.99 KiB) Viewed 18106 times
That will open the "New Action" dialogue.
S_3.JPG
S_3.JPG (20.48 KiB) Viewed 18106 times
I give the new action a descriptive name ("Right"), and just for the heck of it, associate it with Shift-F2 as a hotkey. The set to which the action belongs remains "Default Actions". Click the "Record" button to begin recording the new action.
S_4.JPG
S_4.JPG (21.46 KiB) Viewed 18106 times
The first thing I want to do is rotate the page into an upright orientation. This is done from the "Image" menu.
S_5.JPG
S_5.JPG (73.99 KiB) Viewed 18106 times
Next, I want to get rid of that greywash background. There are many possible ways to accomplish this in Photoshop. I've seen folks contemplate taking a "blank" page, subracting it from a "white" page, and adding the difference to the target page. Or something like that. My own approach is quite a bit cruder: I just use a "Curves" adjustment.
S_6.JPG
S_6.JPG (84.44 KiB) Viewed 18106 times
And not a particularly sophisticated curve either.
S_8.JPG
S_8.JPG (35.62 KiB) Viewed 18106 times
Which yields this result:
S_7.JPG
S_7.JPG (129.5 KiB) Viewed 18106 times
It's not as washed-out as it appears, though there is obviously room for improvement. It's a bit brighter toward the edge than toward the center; maybe a gradient would fix that, but I'm blessed with low standards, and as it is it's good enough for me. Those whose standards are more exacting can work out this bit for themselves.

Now -- finally -- we're ready to address the keystoning. Photoshop CS2 was the first release which offered perspective correction, and this is the first time I've had occasion to use it. Choose the "crop" tool:
S_9.JPG
S_9.JPG (40.77 KiB) Viewed 18106 times
Drag a quick selection from corner to corner -- no need to be too precise, we'll refine it in a moment. Once the selection is made, click the "perspective" box in the toolbar to enable each of the corners to be dragged independently.
S_10.JPG
S_10.JPG (89.96 KiB) Viewed 18106 times
Now I zoom way in, scroll to all four corners, and drag my selection points into place.
S_12.JPG
S_12.JPG (37.73 KiB) Viewed 18106 times
S_13.JPG
S_13.JPG (37.49 KiB) Viewed 18106 times
S_14.JPG
S_14.JPG (35.77 KiB) Viewed 18106 times
S_15.JPG
S_15.JPG (37.4 KiB) Viewed 18106 times

Then zoom back out and see how it looks.
S_16.JPG
S_16.JPG (58.09 KiB) Viewed 18106 times
Looks okay to me (there's those standards again), so I press "Enter" to complete the perspective crop.
S_17.JPG
S_17.JPG (131.55 KiB) Viewed 18106 times
Bingo! Let's zoom in again and see what we have.
S_18.JPG
S_18.JPG (78.15 KiB) Viewed 18106 times
See? I told you it wasn't as washed-out as it looked. Nice crisp anti-aliased text on a nice bright background. Easy on the eyes. And it looks like it's lined up right, too. Good enough for spamsickle, anyway.

Before I save it and close it, there's one more thing I want to do. I mentioned earlier that there may be discrepancies between the left pages and the right pages, and one of those discrepancies may be in the size of the images, due to camera placement, zoom, whatever. I'd like to make the images the same in the final product, and I do that here by modifying image size.
S_19.JPG
S_19.JPG (65.63 KiB) Viewed 18106 times
I specify the width, and let the length stay proportional. I'll specify the same width on the left side, so at least my output images will have the same width. The length may vary a bit, but, well, you know...
S_20.JPG
S_20.JPG (40.2 KiB) Viewed 18106 times
And that's the meat of it. Now I just save the file...
S_21.JPG
S_21.JPG (75.77 KiB) Viewed 18106 times
... to a different directory (we got it from RRAW, and we'll save it in R) ...
S_22.JPG
S_22.JPG (65.76 KiB) Viewed 18106 times
--- with the quality I want.
S_23.JPG
S_23.JPG (33.19 KiB) Viewed 18106 times
When I close the file, this is how my completed action looks:
S_24.JPG
S_24.JPG (34.56 KiB) Viewed 18106 times
I click on the little square beside the red "Recording" indicator to stop recording, and my new action is ready to use. To use it, I choose "Automatic ... Batch" from the "File" menu.
S_25.JPG
S_25.JPG (63.65 KiB) Viewed 18106 times
That brings up the "Batch" dialogue, with my new action ("Right") already selected. I want to apply this action to all the files in my RRAW directory, so I choose Source as "Folder" and click "Choose" to specify which one it is. I'll be saving the images to a new folder ("R"), so I also specify Destination as "Folder" and choose that one too. All that's left to do now is to click "Okay" and go get a cup of coffee.
S_26.JPG
S_26.JPG (73.67 KiB) Viewed 18106 times
It runs fairly fast (on my not-so-speedy laptop, it takes just over 15 minutes to do 175 pages), and if your images are consistent, the output will be pretty much what you want. If they're not -- well, that's a hardware problem, isn't it? Get your scanner straight...

I create a separate "Left" action, and run that too, so I have anti-aliased de-keystoned formatted-just-like-the-originals images in two separate directories. At this point, you can go different ways -- convert them to PDFs, run OCR software, process them some more with an eye to making DJVu files or some other format. For me, I just run a script to rename them and faro-shuffle them into my "Both" directory, and I'm done. I'm perfectly happy reading my new book with IRFanView or some other image viewing program, and my design objectives have already been met.

There are some things you can do if your images aren't quite aligned and you can't (or don't want to) reshoot them -- the "Crop" step can be made interactive for every image by clicking the "modal" box next to that step in the script, or you can process them in smaller batches -- but this little tutorial is already too long, and who knows if anyone will even be interested.

I will say, setting up the action and running it takes no time at all, despite the fact that reading about it may have caused you to nod off. If you have Photoshop CS2 or later, and have any interest at all in quick-and-dirty get-it-done post-processing, you owe it to yourself to at least give it a try.
User avatar
Misty
Posts: 481
Joined: 06 Nov 2009, 12:20
Number of books owned: 0
Location: Frozen Wasteland

Re: Photoshop solution to keystoning, etc.

Post by Misty »

Interesting, I didn't know you could perspective skew while cropping.

For perspective transformations without cropping, I like using Martin Vicanek's free Perspective Transformations plug-in.
The opinions expressed in this post are my own and do not necessarily represent those of the Canadian Museum for Human Rights.
univurshul
Posts: 496
Joined: 04 Mar 2014, 00:53

Re: Photoshop solution to keystoning, etc.

Post by univurshul »

Excellent work here. I'm assuming the same features are onboard the Mac OS X version. What happens with photos and images that have no borders next to the page edge? Or is this workflow best for text with white margins?
spamsickle
Posts: 596
Joined: 06 Jun 2009, 23:57

Re: Photoshop solution to keystoning, etc.

Post by spamsickle »

The content of the page shouldn't really matter for this transformation. As long as you can identify the four corners of the page, it should work. Verifying how well it's worked may be easier when there are clear horizontal and vertical lines on the page, but for me, if there is nothing on the page which would cause me to suspect keystoning in the first place, I'm not going to obsess about how well I've "fixed" it.

Also, I was wrong about when this feature was introduced. Photoshop CS2 introduced a "vanishing point" tool, which can be used for more sophisticated perspective effects. The perspective crop tool I used here has been available since Photoshop 6.
univurshul
Posts: 496
Joined: 04 Mar 2014, 00:53

Re: Photoshop solution to keystoning, etc.

Post by univurshul »

Very great software utilization headway and the workflow examples above are fantastic. I'm spending the week to learn this flow. --Regards

Forward looking: what are your thoughts with this process and implementing it into a single camera rig that captures images directly overhead on an open facing book with a wide angle platen? The largest hurdle here is keystone-correction, so I think Photoshop could perform and crop...maybe even page split under the same batch process?
spamsickle
Posts: 596
Joined: 06 Jun 2009, 23:57

Re: Photoshop solution to keystoning, etc.

Post by spamsickle »

I have a couple of reservations about that design, which I'll save for the Hardware forum should you decide to start a thread about it there.

From the software side, I don't think Photoshop would have a problem creating de-keystoned left and right page images from a single overhead camera shot. The one reservation I'd mention here is that "wide-angle platen" part. Flatbed scanners shooting two pages at once are wide angle -- 180 degrees wide -- and while they don't have a problem with keystoning per se, they do have a problem with warping where the pages curve into the spine. Photoshop has warping tools, and it could probably be made to flatten that inner curl, but it would be a lot more work than this simple perspective transform. I'm lazy. I'd rather avoid the need to de-warp by keeping my pages flat when I shoot, and the 90-degree platen does a pretty good job of that.

If I have time, I'll shoot a "right-angle platen" overhead image later this week and see how well Photoshop handles the keystoning.
Innov8r
Posts: 10
Joined: 04 Mar 2014, 00:53

Re: FREE MAC solution to keystoning, etc.

Post by Innov8r »

For us Mac users who also don't have the expensive PhotoShop, I just discovered a good way to deal with Keystone effect - and it won't cost anything (or very little). The Shareware GraphicConverter 7 has some new features, including de-skewing. GraphicConverter is Mac OS X software, free download from
http://www.lemkesoft.com/
Although you can using GC forever without paying, Paying for the software unlocks some additional features, notably not having to suffer through the opening nag dialog, and Automated Batch Processing, which is well worth the $39.95.

After Pulling the "Effect" menu to "Unskew (Set Proportions)" You set the 4 lines to the corners, or your crop area.
Click "Apply" button at top right.
That brings up the "Unskew" dialog box, which I left at "Auto-Fit". Checking the box to "Try to unskew complete image" will NOT crop, leaving it unchecked will crop at the red lines. OK.

GC also has a nice "white point" tool in the toolbar. Click it once, then click what is supposed to be white space.

hth

Dave
1deskew.gif
1deskew.gif (37.5 KiB) Viewed 17543 times
2deskew.gif
2deskew.gif (80.17 KiB) Viewed 17543 times
GC_Whitept.png
GC_Whitept.png (30.46 KiB) Viewed 17543 times
zamacam
Posts: 20
Joined: 04 Mar 2014, 00:53

Re: Photoshop solution to keystoning, etc.

Post by zamacam »

Hi all,

I'm currently finalizing my workflow (I'll post about it later and, by the way, many thanks to all, I saved a lot of time with this forum) and I'd like to inform that there is another software to deal with keystoning. It's name is DxO. It's well known by professional photographers (at least here, in France). It does a pretty decent job in this matter and its price is lower than Photoshop/Lightroom.

Maybe it can interest someone.

For more information, please see: http://www.dxo.com/intl/photo for general informations and http://www.dxo.com/intl/photo/dxo_optic ... orrections for informations about optical correction.
Post Reply