ebook distortion

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
jumpjack
Posts: 69
Joined: 2010-12-10T05:29:16-07:00
Authentication code: 8675308

Re: ebook distortion

Post by jumpjack »

Ops, my mistake, actual situation is this:
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ebook distortion

Post by fmw42 »

If this is an ebook page (presumably digital), why are the pages bulging outside the e-book bounds? If the pages were not outside the bounds then a perspective on each side should do the trick. If there is some digital distortion to curl the pages then you have a tough problem and perhaps higher order polynomial may be the only solution.
jumpjack
Posts: 69
Joined: 2010-12-10T05:29:16-07:00
Authentication code: 8675308

Re: ebook distortion

Post by jumpjack »

It is NOT an ebook! It's a paper book, and I'm trying to digitize it to turn it into an ebook!
geep999
Posts: 17
Joined: 2010-12-10T07:33:21-07:00
Authentication code: 8675308

Re: ebook distortion

Post by geep999 »

Out of curiosity I tried to remove the distortion using Hugin as per the tutorial
http://hugin.sourceforge.net/tutorials/ ... e/en.shtml
Somewhat successful. It might have been better if I'd had the page edges to use for control points.
Probably useless for batch processing if you're trying to process a whole book.
Why not scan and OCR it?
I think Sirius Cybernetics Corporation might have a suitable product.
Cheers,
Peter
Image
Image
jumpjack
Posts: 69
Joined: 2010-12-10T05:29:16-07:00
Authentication code: 8675308

Re: ebook distortion

Post by jumpjack »

geep999 wrote:Out of curiosity I tried to remove the distortion using Hugin as per the tutorial
http://hugin.sourceforge.net/tutorials/ ... e/en.shtml
I'm sorry but you got a very poor result! Characters are even more distorted! (some ones are bigger than others)
Somewhat successful. It might have been better if I'd had the page edges to use for control points.
Probably useless for batch processing if you're trying to process a whole book.
All pages would have same distortion, so once I find the algorithm for first pages, it will be ok for all of them.
Why not scan and OCR it?
I don't unsrestand the question: this is what I am trying to do! I am "scanning" a book with a camera, and I'd like to distort the resulting images to get then processable by an OCR.
geep999
Posts: 17
Joined: 2010-12-10T07:33:21-07:00
Authentication code: 8675308

Re: ebook distortion

Post by geep999 »

All pages would have same distortion, so once I find the algorithm for first pages, it will be ok for all of them.
Gwenview (Linux viewer) displayed a thumbnail image of your book in which I saw it being held between two hands standing on a table. I was thinking that it would be difficult to make that accurately repeatable.
Why not scan and OCR it?
I don't unsrestand the question: this is what I am trying to do! I am "scanning" a book with a camera, and I'd like to distort the resulting images to get then processable by an OCR.
Sorry - I meant scan with a real scanner, not a camera. But if you've no scanner then you're stuck with the camera.
Even with a scanner you run into problems with distortion at the middle of the book.

Good luck,
Peter
jumpjack
Posts: 69
Joined: 2010-12-10T05:29:16-07:00
Authentication code: 8675308

Re: ebook distortion

Post by jumpjack »

geep999 wrote:
All pages would have same distortion, so once I find the algorithm for first pages, it will be ok for all of them.
Gwenview (Linux viewer) displayed a thumbnail image of your book in which I saw it being held between two hands standing on a table. I was thinking that it would be difficult to make that accurately repeatable.
Putting some markers on the table, I was able to shoot 10 pictures with identical shape of the pages.
geep999 wrote:
Why not scan and OCR it?
I don't unsrestand the question: this is what I am trying to do! I am "scanning" a book with a camera, and I'd like to distort the resulting images to get then processable by an OCR.
Sorry - I meant scan with a real scanner, not a camera. But if you've no scanner then you're stuck with the camera.
I also have a flatbed scanner, but don't want to use it, for two reasons:
- fully opening a book a couple of hundreds of times can damage it
- I'd like to make a"DIY bookscanner" affordable for every owner of just a cellphone. My one has 5 MP camera, but I think 3 or even 2 would be enough.

edit:
3rd reason: my phone can take automagically thousands of picture at 10 seconds delay. I think all nokia phones can do it.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: ebook distortion

Post by anthony »

Okay so it looks like you are stuck with a very freeform polynomial.

So get a book containg a large grid pattern. Locate all the gird pixels (morphology can help with that. and figure out where you want each of those points to end up in the final image. Store that in a file...

sx1 sy1 dx1 dy1
...

for source x,y to destination x,y

now add one more line at the top (the polynomial order) to fit to that data. make it at least 2 may be 3. And use it.
Do it with the grid photo image first
convert input_grid.png -distort polynomial '@grid_data.txt' result.png

Give us links to your grid image and data would also be good.

once you have it for the grid, you can repeat it for all your other pages.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jumpjack
Posts: 69
Joined: 2010-12-10T05:29:16-07:00
Authentication code: 8675308

Re: ebook distortion

Post by jumpjack »

anthony wrote: now add one more line at the top (the polynomial order) to fit to that data. make it at least 2 may be 3. And use it.
I don't understand this part.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: ebook distortion

Post by anthony »

The one number on the first to specify the 'order' for the polynomial

Eg:

3
10,10 0,0
10,5 0,10
and so on
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jumpjack
Posts: 69
Joined: 2010-12-10T05:29:16-07:00
Authentication code: 8675308

Re: ebook distortion

Post by jumpjack »

anthony wrote:The one number on the first to specify the 'order' for the polynomial

Eg:

3
10,10 0,0
10,5 0,10
and so on
I guess you mean "add a '3' as first line". I didn't get why you were talking about one line while meaning one number (as I'm specifying all parameters on a single line).
But I already did it, with weird results; that's why I was asking at the beginning if I have to specify points in a specific oder (clockwise, ccw, line by line... ?).
I thought just specifying points for the "contour" of the text area was enough. Specifying 3-4 points per each text line is not a good option, I think.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: ebook distortion

Post by anthony »

The order of control points is not important.

However do not just select points along the curve. It will fail.

You need to specify pixels all over the image. including all corners, edges, and middle.

Polynomial requires lots of points. The more the better, the more uniform the better.

perhaps you can give use the list of points?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jumpjack
Posts: 69
Joined: 2010-12-10T05:29:16-07:00
Authentication code: 8675308

Re: ebook distortion

Post by jumpjack »

anthony wrote: Polynomial requires lots of points. The more the better, the more uniform the better.
Like describing a surface rather than a line?
Thanks, I'll try.
Post Reply