Skip to content

Instantly share code, notes, and snippets.

@spajak
Created February 12, 2022 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spajak/e28ca9ea294578924f6c735c5b94ffc3 to your computer and use it in GitHub Desktop.
Save spajak/e28ca9ea294578924f6c735c5b94ffc3 to your computer and use it in GitHub Desktop.
Repair Scanned Images Using ImageMagick

Improve/Repair Scanned Images Using ImageMagick

This is the command:

magick "img-01.tiff" -strip -kuwahara "1.5" -modulate "100,90" -level "6,92%,0.75" -quality 80 "img-01.jpg"
  • -strip - remove any metadata
  • -kuwahara "1.5" - apply smoothing algorithm
  • -modulate "100,90" - reduce saturation a bit
  • -level "6,92%,0.75" - improve contrast and decrease gamma (whitens background and makes image darker)

This is the effect:

Mały Książę

Get full version of the image.

Convert every file in a directory using PowerShell:

Get-ChildItem *.tiff -File | ForEach-Object -Process {
    $i = $_.Name; $o = $_.BaseName + ".jpg";
    magick "$i" -strip -kuwahara "1.5" -modulate "100,90" -level "5,92%,0.74" -quality 80 "$o"
}

Imagemagick filters that smooth & reduce noise

  • -despeckle - Reduce the speckles within an image.
  • -enhance - Apply a digital filter to enhance a noisy image.
  • -statistic median geometry - Select the "middle" value from all the surrounding pixels.
  • -statistic nonpeak geometry - Reduce noise in an image.
  • -adaptive-blur radius[xsigma] - Adaptively blur pixels, with decreasing effect near edges.
  • -kuwahara radius[xsigma] - Edge preserving noise reduction filter.
  • -bilateral-blur width - A non-linear, edge-preserving, and noise-reducing smoothing filter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment