Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > Workshop

Notices

Reply
 
Thread Tools Search this Thread
Old 05-11-2017, 05:30 AM   #1
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,583
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Question Best ImageMagick parameters for rescaling images with text

One of my ebooks contains many .png images of Arabic text that was saved with a relatively small font size (most likely 11 or 12pt), which makes it really hard to read. (For an example, see the attached file.)

I wondering if there are any ImageMagick* parameters that do the following:

1. Enlarge the picture by about 25-50%.
2. Smooth the resulting image.

Basically, I'm looking for any parameters that'll make the image slightly larger and more readable.

*It doesn't have to be ImageMagick; any suitable tool that supports batch processing is fine.
Attached Images
 
Doitsu is offline   Reply With Quote
Old 05-11-2017, 06:22 AM   #2
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,553
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
@Doitsu - if you have access to Windows have a look at ImBatch ==>> http://www.highmotionsoftware.com/products/imbatch

I have about half a dozen multi-step imbatch jobs that I use regularly on sets of many hundreds of images, they save me heaps of time.

BR
BetterRed is offline   Reply With Quote
Advert
Old 05-11-2017, 10:46 PM   #3
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
Is this just going to be for your own personal usage? Or is this for an actual book?

Was this a bunch of inline images instead of Arabic text? (I know I have run across similar problems with crappy conversions of Greek text.)

As you know, trying to UPSCALE things will result in some subpar images... but if you just needed something a little quick/dirty, I dabbled in this for a little and came up with this basic workflow.

Step 1

Original Image:

Name:  test2.png
Views: 759
Size:  762 Bytes

First you upscale the image:

Code:
convert test2.png -scale 1000% test2[Scaled1000].png
Click image for larger version

Name:	test2[Scaled1000].png
Views:	294
Size:	2.3 KB
ID:	156674

Note: You can insert any % there. 1000% makes it 10x larger.

Step 2

Then you can adjust the contrast slightly:

Code:
convert test2[Scaled1000].png -contrast-stretch 3% test2[ContrastTweak3].png
Click image for larger version

Name:	scale[ContrastTweak3].png
Views:	280
Size:	2.2 KB
ID:	156675

Note: You can insert any % there. I found that anywhere from 1-5% seemed decent. Going beyond that distorted the text too much.

Step 3

Then you can scale the image down:

Code:
convert test2[ContrastTweak3].png -scale 40% test2[ScaledDown40].png
Click image for larger version

Name:	test2[ScaledDown40].png
Views:	287
Size:	1.3 KB
ID:	156676

Note: You can use whatever % or size you want here. This results in a final image that is 4x larger.

Step 4

If you wanted to convert on an entire folder of PNGs, just go to the folder and run this:

Code:
convert *.png -scale 1000% -contrast-stretch 3% -scale 40% -set filename:fname %t_tn +adjoin %[filename:fname].png
Note: If you have a ton of images, probably better to run mogrify or come up with some sort of batch file. I read about the convert -set filename method here: https://www.imagemagick.org/Usage/ba...ogrify_convert

You could also probably introduce more steps in between (different resizing filters, etc. etc.), but I am not that familiar with that. Most of the time I am just using Imagemagick to clean up speckling in scans. :P

Last edited by Tex2002ans; 05-11-2017 at 11:16 PM.
Tex2002ans is offline   Reply With Quote
Old 05-12-2017, 12:44 AM   #4
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,583
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
@Tex2002ans: Thanks for your detailed instructions!
@BetterRed: Thanks for the ImBatch recommendation! I checked it out and I especially liked the built-in preview mode.
Doitsu is offline   Reply With Quote
Old 05-12-2017, 03:39 AM   #5
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,553
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
@Doitsu - I especially like the ability to see the effect when tasks are re-ordered. Resize then sharpen ain't the same as sharpen then resize.

FYI the images I process are from fixed cameras on 'wildlife' trails. Objective, eradication of feral animals - pigs, horses, goats, rabbits, foxes, hares, mice, rats etc. That's why there's hundreds of images - one scampering rat can trigger a dozen shots or more.

BR
BetterRed is offline   Reply With Quote
Advert
Old 05-23-2017, 08:45 AM   #6
willus
Fuzzball, the purple cat
willus ought to be getting tired of karma fortunes by now.willus ought to be getting tired of karma fortunes by now.willus ought to be getting tired of karma fortunes by now.willus ought to be getting tired of karma fortunes by now.willus ought to be getting tired of karma fortunes by now.willus ought to be getting tired of karma fortunes by now.willus ought to be getting tired of karma fortunes by now.willus ought to be getting tired of karma fortunes by now.willus ought to be getting tired of karma fortunes by now.willus ought to be getting tired of karma fortunes by now.willus ought to be getting tired of karma fortunes by now.
 
willus's Avatar
 
Posts: 1,272
Karma: 11087488
Join Date: Jun 2011
Location: California
Device: iPad
Quote:
Originally Posted by Tex2002ans View Post
...
Code:
convert *.png -scale 1000% -contrast-stretch 3% -scale 40% -set filename:fname %t_tn +adjoin %[filename:fname].png
...
Thank you for this detailed answer. After reading about how the contrast-stretch option works in ImageMagick, I've learned something new. I may change the way k2pdfopt does contrast adjustment now. I'll have to try a few test cases.
willus is offline   Reply With Quote
Old 05-23-2017, 10:41 AM   #7
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by willus View Post
Thank you for this detailed answer. After reading about how the contrast-stretch option works in ImageMagick, I've learned something new. I may change the way k2pdfopt does contrast adjustment now. I'll have to try a few test cases.
I will have to research this topic/methods a lot more as well.

That method was just something I came up with in a few hours as a ROUGH resizing (better than nothing, but definitely not something I would use in an ebook for sale). There has to be much better Imagemagick solutions that exist out there.

Most of the time when I run across Doitsu's problem in all the books I work on is microscopic images of Greek text... but instead of me doubling/tripling the size, I just turn it into the actual Unicode characters instead. :P

* * * * *

I remember when I was trying to come up with a despeckling solution to clean up PDF scans. I spent days reading everything on Google, I somehow stumbled upon a REALLY obscure Imagemagick post that had the (close-to-perfect) solution.

If you did a search for it in Google, it was one of those where you get "6 hits" and/or it was buried on "page 1000" of a normal search (like "Imagemagick despeckling" or "cleaning speckles in PDF scans").

If I remember correctly, they did it by shrinking, then expanding pixels, then creative a diff image. Then step through and remove any group of non-fully-black pixels that was smaller than X x Y. This would get rid of little 1x1, 1x2, 2x1, 2x2, 3x2, [...] specs of dust all over the page.

Then it would reverse the expansion and use the diff image to try to return it to its original form.

It did a pretty fantastic job compared to ANYTHING I ever found before/since... BUT the downfall was sometimes the fine details would disappear... like the very tip of a comma, or the tip of a serif font, or little umlaut above a character in a footnote, or a badly scanned period would just poof.

Or complicated edges/lines would go poof (like a dashed line in a graph, or a very thin line separating the bottom of the text from the footnote section).

Definitely helped me in many cases though, and helped cut down on the size of some speckled PDFs/Images DRAMATICALLY.

And you had to weigh what would be worse... a whole PDF full of little speckles? Or the tiny end of a comma or an accent disappearing. :P

* * * * *

Then you get the REALLY obscure/ingenious stuff... like using ImageMagick to add line numbers to a PDF:

https://tex.stackexchange.com/questi...mbers-to-a-pdf

I mean look at that top answer... genius.

Coming up with super genius ways to compare the average color of a line, to tell if it was actual text or "blank space".

Last edited by Tex2002ans; 05-23-2017 at 10:54 AM.
Tex2002ans is offline   Reply With Quote
Old 05-24-2017, 01:22 AM   #8
dgatwood
Curmudgeon
dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.
 
dgatwood's Avatar
 
Posts: 629
Karma: 1623086
Join Date: Jan 2012
Device: iPad, iPhone, Nook Simple Touch
Given that these are presumably generated with a standard Arabic font, it might be possible to do some really smart OCR and turn it into actual text.
dgatwood is offline   Reply With Quote
Old 05-24-2017, 04:53 AM   #9
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,583
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by dgatwood View Post
Given that these are presumably generated with a standard Arabic font [...]
They were generated with a standard Arabic font, however, the font contains several (optional) ligatures that mimic traditional Arabic handwriting, which makes Arabic OCR of these particular images rather difficult.

For an example, have a look at the attached screenshot. It shows the same word in two different fonts (with and without ligatures).

To give you an idea of the difficulties, here's the same word split into the 5 letters that the OCR program would have to detect:

ﺟ ﺮ ـﻳ ـﻣ ﺔ
Attached Images
 
Doitsu is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Text covers instead of images imsoawesome Kobo Reader 1 02-04-2013 05:40 PM
Wrapping text around images lof Conversion 10 11-22-2012 05:09 AM
TEXT WRAP AROUND IMAGES RKEP71 Sigil 1 06-20-2011 08:26 PM
Text and images on k2 not as dark as k1 Matches Malone Amazon Kindle 25 02-27-2009 06:41 PM


All times are GMT -4. The time now is 04:48 PM.


MobileRead.com is a privately owned, operated and funded community.