A következő címkéjű bejegyzések mutatása: resolution. Összes bejegyzés megjelenítése
A következő címkéjű bejegyzések mutatása: resolution. Összes bejegyzés megjelenítése

2020. június 3., szerda

Image resolution for OCR and how to check it

The resolution of the documents consisting of scanned pages determines how much information they store about the visual content, so how well or easily those pages are readable. This is usually measured in DPI (Dot Per Inch - how many pixels are covering a 2.54cm part of the page) so that it is independent of the page size. Horizontal and vertical DPI is usually the same, and for normal documents 300 DPI is optimal (higher is only needed for documents with small print). The minimum acceptable DPI for production OCR processing is 200 DPI (as advised by vendors of several OCR engines).
For the usual business documents of A4 and Letter standards the below table shows the amount of information contained and describing the visual content of the complete page at different usual DPIs (as well as horizontal and vertical size in inches, millimeters, pixels and DPI):


It can be seen that a 200 DPI image has less than half the information about the page (practically a 3.74 megapixel photo - worse than what any smartphone can take in 2020) compared to the optimal 300 DPI (approx. 8.5 megapixels). Anything below has even more scarce information about the page: 150 DPI only has one quarter, 100 DPI only has one tenth of the information.
Consequently a modern OCR solution using traditional engines (ABBYY, Nuance, Tesseract, RecoStart whichever company has them acquired at the moment) can be expected to perform adequately if feed with 200-300 DPI documents.
Up scaling scanned images just inserts rows and columns of smartly averaged pixels between the original pixels but this does not add the missing information: what was really there originally on the document. This is automatically performed by the engines anyways, but is not expected to make the results better, just enables processing low resolution documents (still usually producing substandard results).

Effect of JPEG: lossy compression 

JPEG uses lossy compression, this simply means, that even though you input the specific pixel information you have scanned (what color is each location in the page with a specific resolution), it does not store this information as given: it encodes 8x8 blocks converted into frequencies with a quality setting. If that is high, the JPEG closely resembles the image, so it is almost as good for OCR as the original and is larger. Lower quality adds noise and makes OCR results worse.
On comparison TIFF G4, PNG etc. formats store pixel as received, there is no degradation due to compression, this is called loss-less compressions and usually results in larger files.

How to figure out the resolution of your input files

For JPEG, PNG, TIFF etc. open them in e.g. IrfanView https://www.irfanview.com/ and fin.d the resolution in the bottom left in the status bar or press “I” for “I”mage properties. In case of TIFFs switch to the page you one to see the resolution for, they do not necessarily have the same resolution. Resolution may slightly differ from the numbers in the above table.

Finding the resolution of the images in PDFs

You can use the pdfimages command from popplers utils (free, opensource software).

Using WSL on Windows 10

Using msys2 on other Windows versions


Please note, PDFimages may calculate DPI wrong (for example if images are stored rotated) but the resolutions you can always compare to the table above.

How to install pdfimages

Using Windows Subsystem for Linux on Windows 10
  1. Enable Windows Subsystem for Linux
  2. Install e.g. Ubuntu from the Microsoft Store
  3. Start bash
  4. Install the poppler-util package (and its dependencies)
$ sudo apt install -y poppler-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
poppler-utils is already the newest version (0.62.0-2ubuntu2.10).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Using msys2

https://www.msys2.org/ is a free and open-source platform for multiple Windows versions (excluding Windows XP and below)
After installing msys2, install the package (the example below is for 64 bit installations):
c:\msys64\usr\bin\bash -lic “pacman -S mingw-w64-x86_64-poppler“

2012. november 15., csütörtök

HDTV screen calculation basics explained

This article is intended to give you the quick formulas to calculate all interesting measures from the diagonal size of your screen optionally walking you through the calculus with the lease possible pain. (hopefully :)
Let me know if you are interested in other calculations as well, and I will update this article when I find the time!

Quick formulas for 16:9 screens

Width:
w=0.8716 * d
Height:
h=0.4903 * d
Area:
a=0.4273 * d^2
Maximum distance from your eye to the screen to be able to see all the details displayed:
mh = 0.4358 * d / tan(hres / 120°)
mv = 0.2451 * d / tan(vres / 120°)
whichever is shorter.

Examples

Please note, that the viewable screen size is rarely equal to the size used in the marketing :) You shall use whatever specs your screen has. Both of my screens are w:h = 16:9.
  1. My new 50” (127cm) Panasonic Viera P50UT50E, native resolution: hres:vres = 1920:1080 pixels (full-HD, the usual resolution of blu-ray movies)
    d=49.9” (126.7cm) is viewable
    w=43.5" (110.5cm)
    h=24.5" (62.1cm)
    a=1064 square inch (6864.4cm2)
    mh=75.8" (192.6cm)

    mv=77.2" (196.2cm) -> visible horizontal and vertical resolution about the same
  2. My old 32” (81,3cm) JVC AV-32H40 CRT, native resolution: 720 * 576 pixels (PAL SDTV, the usual resolution of PAL DVDs)
    d=29.9” (75.9cm) is viewable
    w=26" (66.2cm)
    h=14.7" (37.2cm)

    a=382 square inch (2464.6cm2)mh=124" (314.9cm)
    mv=87.3" (221.7cm) -> visible vertical resolution is a lot better, makes you have to move closer
And the surprising information here is: stepping up from a 32" screen to an 50" one can earn you almost three (2,79) times as large of a screen area to watch! (Being full-HD it also has 2 megapixel native resolution compared to the 0.4 megapixel of the SDTV / DVD - that is quite an upgrade too :)

Stop here, if you don't care to know why. :)

Diagonal size and aspect ratio

The only information we need to know to start is the diagonal size (d) of your screen and the aspect ratio (width to height, w:h) of it:
  • nowadays usually 16:9
  • the old ones being 4:3
  • screens made for computers are often 16:10
  • and there are some 21:9 models out there. These are the ones best suited to watch movies see my upcoming post about how much better these are for movies and worse for TV shows! :)

Quick formulas for screens with other aspects

Please replace 16 and 9 with the aspect numbers for your screen:
Width:
w=16 * sqrt(d^2 / (16^2 + 9^2) )
Height:
h=9 * sqrt(d^2 / (16^2 + 9^2) )
Area:
a = 16*9 / (16^2 + 9^2) * d^2

Width and height from diagonal

We know how the diagonal of a square screen relates to its width and height:
w^2 + h^2 = d^2
Let’s define an unknown x knowing the relative ratio of the width and height of your screen:
Width:  
w=16 * x
and height:
h=9 * x
Use the aspect numbers of your own screen!

Now we substitute, so that we only have one unknown value to find out (we know d):
(16 * x)^2 + (h=9 * x)^2 = d^2
which is the same as:
256 * x^2 + 81 * x^2 = d^2
which is the same as:
337 * x^2 = d^2
which is the same as:
x^2 = d^2 / 337
which is the same as:
x = sqrt(d^2 / 337) (sqrt means "square root of")
This means that width and height both can be calculated from the diagonal.
Width:
w=16 * sqrt(d^2 / 337)
and height:
h=9 * sqrt(d^2 / 337)

Area from diagonal

We know how to calculate the area of the screen from its width and height:
a = w * h
We will substitute widht and height, know that we have the formulas for them:
a = 16 * sqrt(d^2 / 337) * 9 * sqrt(d^2 / 337)
Which is the same as:
a = 144 / 337 * d^2

Maximum viewing distance

According to the information I have found on Internet the smallest bit on a picture an average human eye can distinguish from another is one the size of a minute of arc: 1' (one degree of arc: 1° contains 60 minutes of arc: 60', the full circle is 360° which is 21600').
It is expressed this way, so that it does not matter how far that visible bit is. For example you may see the fly on the glass of your window in the same size as a building behind it in a distance, if they cover the same area of your visible field.
We refer to the maximum distance here as the where you cannot move any farther if you still want to see all the details that are displayed on your screen, supposing you actually use the full resolution of your screen. Some important points here:
  1. I suppose you are watching content on your screen, which does not have a smaller resolution than your screen. Watching a DVD film on a full HD screen will not really deliver you more details, since those are not recorded on the DVD.
  2. Some people might have better vision, some might have worse, this calculation is for the average.
  3. Some might argue, that even if you cannot see the difference between adjacent pixels, because they seem so small they still might look more "pleasing" to the eye. I do not care about such arguments. :)
  4. 3D TV-s indeed seem to need some further considerations. I will delve into that as soon as I find the time.
  5. We will not consider the minor difference in the visible size of a pixel in the center and on the edge of the screen. (the one on the edge is physically the same size, but is further from your eye, since the screen does not form a circle around your eye, thus it seems smaller)
 We can calculate this maximum distance from the data we already know: the width of the screen and the horizontal resolution or the height of the screen and the vertical resolution. The resolution is in turn the minimum number of minutes of arc we want to see, or else we just couldn't tell apart some separate pixels.
We will use the right-angled triangle between your eye, the center of the screen and either the top or the left edge of the screen.
  • There is a right angle in it at the center of the screen (there should be for optiam viewing experience anyhow :).
  • The lenght of the base of the triangle (between the center and the edge of the screen) is either half of the width or half of the height of the screen.
  • Its height is the distance between your eye and the screen, what we want to find out. :)
  • The angle at your eye is half the horizontal or vertical resolution (the other half covers the right or bottom half of the sceen).
 The tangent trigonometric function for an angle in a right triangle is:
tan(angle) = (lenght of the opposite side) / (lenght of the adjacent side)
but this is the same as:
(lenght of the adjacent side) = (lenght of the opposite side) / tan(angle)
so Maximum distance from your eye to the screen:
m = (half screen width) / tan(half horizontal resolution/60 degrees)
m = (half screen height) / tan(half vertical resolution/60 degrees)
whichever is shorter.

Rendszeres olvasók