Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
|
Lista Forumurilor Pe Tematici
|
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login
POZE MRRRR'S FORUM (VIEW ONLY)
Nu sunteti logat.
|
Nou pe simpatie: cristina25 24 ani
 | Femeie 24 ani Cluj cauta Barbat 24 - 58 ani |
|
|
TRaP
Moderator
Inregistrat: acum 8 ani
Postari: 951
|
|
This is done with ImageMagick; download portable from:
Pick Q8 version for: - Standard Scans & Document OCR Preprocessing: Standard document scans (JPEGs, PNGs, PDFs) use 8-bit color or grayscale. Binarizing and thresholding text for OCR does not require 16-bit color depth. - High-Volume Automated Batch Scripting: Lower RAM footprint and faster execution make batch processing significantly more efficient.
Pick Q16 version for: - High-Dynamic-Range Photography / RAW Files: Preserves subtle highlights and deep shadows from 16-bit TIFFs, PNGs, or camera RAW files without losing fidelity. - Multi-Step Complex Color Manipulation: Prevents pixel clipping and color degradation across lengthy image modification pipelines.
Recommendation: Download the 8 bits-per-pixel (Q8) version unless you actively work with 16-bit professional photography or medical imaging formats. For general scanning, script automation, and OCR tasks, Q8 is lighter, faster, and uses far less memory.
Every image preprocessing step can be performed directly in ImageMagick using specific operators.
Gray Scale Image: -colorspace gray Drops color channels, reducing the image to single-channel luminosity and eliminating chromatic noise.
Skew Correction (Deskew): -deskew 40% or -deskew 80% Calculates the tilt angle of text baselines and rotates the canvas to level them.
Normalization: -normalize (or -auto-level) Stretches pixel intensity across the entire dynamic range ($0\text{--}100\%$), automatically darkening faint text and brightening off-white background paper.
Image Scaling (Upscaling): -resize 200% (or -density 300 -resample 300) Increases pixel resolution (e.g., doubling dimensions), using interpolation to smooth jagged edges on low-resolution scans.
Noise Removal (Despeckling): -statistic Median 3x3 (or -despeckle / -morphology Open Disk:1) Evaluates neighboring pixels to remove isolated "salt and pepper" specks and scanner artifacts without blurring character edges.
Thinning and Skeletonization: -morphology Thinning Skeleton (or -morphology Thinning:1 Skeleton) Erodes thick, smudged, or bleeding text strokes down to single-pixel-wide central lines. (Note: Useful for heavy ink bleed, but can degrade recognition in standard OCR engines like Tesseract if over-applied).
Thresholding and Binarization: -lat 10x10-5% (Adaptive) or -auto-threshold Otsu (Otsu) Converts grayscale pixels into pure black ($0$) and white ($1$). Local Adaptive Thresholding (-lat) calculates thresholds per local region, preventing dark spots or uneven lighting from creating black patches.
Combined full pipeline command:
magick input.jpg \ -colorspace gray \ -resize 200% \ -normalize \ -deskew 80% \ -statistic Median 3x3 \ -lat 10x10-5% \ output.png |
One-liner:
| magick input.jpg -colorspace gray -resize 200% -normalize -deskew 80% -statistic Median 3x3 -lat 10x10-5% output.png |
Or apply targeted fixes, for example:
1. Morphological Dilation (Fills Holes & Thickens Text) Expands black pixels inward to fill the hollow gaps inside the letters.
| magick input.png -morphology Dilate Octagon:1 output.png |
2. Blur + Level Thresholding (Smooths & Rebuilds Letters): Applies a small Gaussian blur to bridge white gaps between nearby black pixels, then stretches the contrast to re-solidify the characters.
| magick input.png -gaussian-blur 0x1 -level 30%,70% output.png |
One-liner:
| magick input.png -colorspace gray -resize 200% -gaussian-blur 0x1 -morphology Dilate Disk:1.5 -level 20%,80% -threshold 50% output_clean.png |
-resize 200%: Gives ImageMagick more pixel room to interpolate smoother edges. -gaussian-blur 0x1: Blurs the pixelated inner holes so they bleed together with the black outlines. -morphology Dilate Disk:1.5: Grows the dark regions outward, closing hollow gaps inside letters like e, a, and o. -threshold 50%: Locks the reconstructed shapes back into crisp, solid black characters that OCR engines can easily read.
or for example: 1. Morphological Erosion (Thickens Black Text) To expand dark text pixels into the hollow interior gaps without washing out the page:
| magick input.png -morphology Erode Disk:1 output.png |
2. Contrast Inversion Method (Safer Control) Invert the image so the text is pure white on a black background, apply dilation/blurring, and then invert it back:
| magick input.png -negate -morphology Dilate Disk:1 -negate output.png |
One-liner:
| magick input.png -colorspace gray -level 40%,90% -negate -morphology Dilate Disk:1.2 -negate output_clean.png |
-level 40%,90%: Pulls faint light-gray pixels down toward black before applying any morphology. -negate ... -morphology Dilate ... -negate: Converts the text to white, expands the white text to seal the hollow holes, and flips the colors back to standard black-on-white.
Source: Gemini
It ultimately depends on your scan and the needed fixes.
|
|
| pus acum 4 zile |
|
|
TRaP
Moderator
Inregistrat: acum 8 ani
Postari: 951
|
|
For operating directly on PDF file without having to first convert to image. This does not require any admin permissions.
1. Download GhostScript Portable:
2. Right click the downloaded file ▶ Properties ▶ Unblock ▶ OK
3. Double click the file and extract to a desired folder
4. Locate the gswin64c.exe file and copy its complete path, without quotes. e.g. D:\Program Files\Portable Ghostscript\CommonFiles\Ghostscript\bin\gswin64c.exe
5. In your Image Magick folder, locate the delegates.xml file and open it with Notepad
6. Search for the line(s) that contain the text delegate decode="pdf" and replace the @PSDelegate@ text on those line with the path from 4. e.g.
<delegate decode="pdf" encode="eps" mode="bi" command=""@PSDelegate@" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=eps2write" "-sPDFPassword=%a" "-sOutputFile=%o" "-f%i""/> <delegate decode="pdf" encode="ps" mode="bi" command=""@PSDelegate@" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=ps2write" "-sPDFPassword=%a" "-sOutputFile=%o" "-f%i""/> |
becomes
<delegate decode="pdf" encode="eps" mode="bi" command=""D:\Program Files\Portable Ghostscript\CommonFiles\Ghostscript\bin\gswin64c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=eps2write" "-sPDFPassword=%a" "-sOutputFile=%o" "-f%i""/> <delegate decode="pdf" encode="ps" mode="bi" command=""D:\Program Files\Portable Ghostscript\CommonFiles\Ghostscript\bin\gswin64c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=ps2write" "-sPDFPassword=%a" "-sOutputFile=%o" "-f%i""/> |
7. Save and close the delegates.xml file
8. In Image Magick folder open a cmd window and use a command such as the one below to apply fixes directly to PDF: e.g.
| magick -density 300 input.pdf -colorspace gray -level 40%,90% -negate -morphology Dilate Disk:1.2 -negate -deskew 50% output_clean.pdf |
|
|
| pus acum 3 zile |
|