UNPAPER(1)
unpaper(1) β your bestie's guide to making scans look less cursed π
β¨ NAME β¨
unpaper β unpaper. that's literally the name, bestie. the name ate and left no crumbs. π
π«Ά SYNOPSIS π«Ά
unpaper [options] (input patterns output patterns | input files output files)
πΈ OVERVIEW πΈ
okay so real talk: unpaper is a post-processing tool for scanned sheets of paper. it's especially for book pages that were scanned from previously created photocopies. the main purpose is to make scanned book pages better readable on screen after conversion to PDF. additionally, unpaper might be useful to enhance the quality of scanned pages before performing optical character recognition (OCR). π¦
it tries to clean scanned images by removing dark edges that appeared through scanning or copying on areas outside the actual page content (e.g. dark areas between the left-hand-side and the right-hand-side of a double-sided book-page scan). it also tries to detect misaligned centering and rotation of pages and will automatically straighten each page by rotating it to the correct angle. this process is called deskewing. note that the automatic processing will sometimes fail. it is always a good idea to manually control the results of unpaper and adjust the parameter settings according to the requirements of the input. each processing step can also be disabled individually for each sheet. β¨
input and output files can be in either .pbm, .pgm or .ppm format, thus generally in .pnm format, as also used by the Linux scanning tools scanimage and scanadf. conversion to PDF can e.g. be achieved with the Linux tools pgm2tiff, tiffcp and tiff2pdf.
π INPUT AND OUTPUT FILES π
input and output files need to be designed either by using patterns or an ordered list of input and output files; if patterns are used, such as %04d, then they are substituted for the input and output sheet number before opening the file for input or output. π
if you're not using patterns, then the program expects one or two input files depending on what is passed as --input-pages and one or two output files depending on what is passed as --output-pages, in order.
missing output file names are fatal and will stop processing; missing initial input file names are fatal, and so is any missing input file if a range of sheets is defined through --sheet or --end-sheet. no cap, that's a hard stop. π
unpaper accepts files in PNM format, which means they might be in .pbm, .pgm, .ppm or .pnm format, which is what is produced by Linux command line scanning tools such as scanimage and scanadf.
π OPTIONS π
okay bestie, options time. every flag, every default, every little value. no skipping, periodt. π
-l { single | double | none };--layout { single | double | none }β set default layout options for a sheet:singleβ one page per sheet.doubleβ two pages per sheet, landscape orientation (one page on the left half, one page on the right half).noneβ no auto-layout,mask-scan-pointsmay individually be specified.
using single or double automatically sets corresponding --mask-scan-points. the default is single.
-start sheet;--start-sheet start-sheetβ number of first sheet to process in multi-sheet mode. (default:1)-end sheet;--end-sheet sheetβ number of last sheet to process in multi-sheet mode.-1indicates processing until no more input file with the corresponding page number is available (default:-1)-# sheet-range;--sheet sheet-rangeβ optionally specifies which sheets to process in the range betweenstart-sheetandend-sheet.-x sheet-range;--exclude sheet-rangeβ excludes sheets from processing in the range betweenstart-sheetandend-sheet.--pre-rotate { -90 | 90 }β rotates the whole image clockwise (90) or anti-clockwise (-90) before any other processing.--post-rotate { -90 | 90 }β rotates the whole image clockwise (90) or anti-clockwise (-90) after any other processing.-M { v | h | v,h };--pre-mirror { v | h | v,h }β mirror the image, after possible pre-rotation. eitherv(for vertical mirroring),h(for horizontal mirroring) orv,h(for both) can be specified.--post-mirror { v | h | v,h }β mirror the image, after any other processing except possible post-rotation. eitherv(for vertical mirroring),h(for horizontal mirroring) orv,h(for both) can be specified.--pre-shift h, vβ shift the image before further processing. values forh(horizontal shift) andv(vertical shift) can either be positive or negative.--post-shift h, vβ shift the image after other processing. values forh(horizontal shift) andv(vertical shift) can either be positive or negative.--pre-wipe left, top, right, bottomβ manually wipe out an area before further processing. any pixel in a wiped area will be set to white. multiple areas to be wiped may be specified by multiple occurrences of this options.--post-wipe left, top, right, bottomβ manually wipe out an area after processing. any pixel in a wiped area will be set to white. multiple areas to be wiped may be specified by multiple occurrences of this options.--pre-border left, top, right, bottomβ clear the border-area of the sheet before further processing. any pixel in the border area will be set to white.--post-border left, top, right, bottomβ clear the border-area of the sheet after other processing. any pixel in the border area will be set to white.--pre-mask x1, y1, x2, y2β specify masks to apply before any other processing. any pixel outside a mask will be set to white, unless another mask includes this pixel.
only pixels inside a mask will remain. multiple masks may be specified. no deskewing will be applied to the masks specified by --pre-mask.
-s { width, height | size-name };--size { width, height | size-name }β change the sheet size before other processing is applied. content on the sheet gets zoomed to fit to the appropriate size, but the aspect ratio is preserved. instead, if the sheet's aspect ratio changes, the zoomed content gets centered on the sheet.
possible values for size-name are: a5, a4, a3, letter, legal. all size names can also be applied in rotated landscape orientation, use a4-landscape, letter-landscape etc.
--post-size { width, height | size-name }β change the sheet size preserving the content's aspect ratio after other processing steps are applied.--stretch { width, height | size-name }β change the sheet size before other processing is applied. content on the sheet gets stretched to the specified size, possibly changing the aspect ratio.--post-stretch { width, height | size-name }β change the sheet size after other processing is applied. content on the sheet gets stretched to the specified size, possibly changing the aspect ratio.-z factor;--zoom factorβ change the sheet size according to the given factor before other processing is done.--post-zoom factorβ change the sheet size according to the given factor after processing is done.-bn { v | h | v, h };--blackfilter-scan-direction { v | h | v, h }β directions in which to search for solidly black areas. eitherv(for vertical searching),h(for horizontal searching) orv,h(for both) can be specified. the blackfilter works by moving a virtual bar across each page. the darkness inside the virtual bar is determined and if it exceedsblackfilter-scan-thresholdblack pixels in the area are filled. during filling the blackness of each pixel is determined byblack-threshold. the bar is then moved byblackfilter-scan-stepin the scanning direction. once a page border is encountered the bar is moved down (horizontal scan) or right (vertical scan) by itsblackfilter-scan-size.-bs { size | h-size, v-size };--blackfilter-scan-size { size | h-size, v-size }β size of virtual bar in direction of scanning (meaning width for horizontal pass, height for vertical pass) used for black area detection. two values may be specified to individually set the size for the horizontal scanning-pass and the vertical pass. (default:20,20)-bd { depth | h-depth, v-depth };--blackfilter-scan-depth { depth | h-depth, v-depth }β depth of virtual bar in non-scanning direction (meaning height for horizontal pass, width for vertical pass) used for black area detection. two values may be specified to individually set the depth for the horizontal scanning-pass and the vertical pass. (default:500,500)-bp { step | h-step, v-step };--blackfilter-scan-step { step | h-step, v-step }β steps to move virtual bar for black area detection. two values may be specified to individually set the step for the horizontal scanning-pass and the vertical pass. (default:5,5)-bt threshold;--blackfilter-scan-threshold thresholdβ ratio of dark pixels above which a black area gets detected. (default:0.95).-bx left, top, right, bottom;--blackfilter-scan-exclude left, top, right, bottomβ area on which the blackfilter should not operate. this can be useful to prevent the blackfilter from working on inner page content. may be specified multiple times to set more than one area.-bi intensity;--blackfilter-intensity intensityβ intensity with which to delete black areas. this deletes pixels around the virtual scan bar. larger values will leave less noise-pixels around former black areas, but may delete page content. (default:20)-ni intensity;-noisefilter-intensity intensityβ intensity with which to delete individual pixels or tiny clusters of pixels. any cluster which only containsintensitydark pixels together will be deleted. (default:4)-ls { size | h-size, v-size };--blurfilter-size { size | h-size, v-size }β size of blurfilter area to search for "lonely" clusters of pixels. (default:100,100)-lp { step | h-step, v-step };--blurfilter-step { step | h-step, v-step }β size of "blurring" steps in each direction. (default:50,50)-li ratio;--blurfilter-intensity ratioβ relative intensity with which to delete tiny clusters of pixels. any blurred area which contains at most the ratio of dark pixels will be cleared. (default:0.01)
β¦and we're right back into it, bestie β the options tour keeps going π
-gs,--grayfilter-size{ size | h-size, v-size } β the size of the grayfilter mask it uses to hunt for "gray-only" spots of pixels. (default:50,50)-gp,--grayfilter-step{ step | h-step, v-step } β how big the steps are when it slides that grayfilter mask around in each direction. (default:20,20)-gt,--grayfilter-thresholdratio β the relative intensity of grayness that gets accepted, and this only kicks in when no black pixel shows up inside the mask before the mask gets cleared. (default:0.5)-p,--mask-scan-pointx, y β you set the starting point for mask-detection by hand. You can stack multiple--mask-scan-pointoptions to detect multiple masks, no cap. π―-m,--maskx1, y1, x2, y2 β manually add a mask, on top of whatever masks get auto-detected around the--mask-scan-pointcoordinates (unless--no-mask-scanis specified, ofc).
Literally any pixel outside a mask gets set to white, unless another mask covers that pixel. So masks stack, they don't fight. π«Ά
-mn,--mask-scan-direction{ v | h | v,h } β the directions it searches for mask borders in, starting from the--mask-scan-pointcoordinates. You pickv(vertical mirroring),h(horizontal mirroring), orv,h(both, why not). (default:h, becausevmay cut text-paragraphs on single-page sheets β noted, bestie π)-ms,--mask-scan-size{ size | h-size, v-size } β width of the virtual bar used for mask detection. Two values let you set horizontal and vertical size separately. (default:50,50)-md,--mask-scan-depth{ depth | h-depth, v-depth } β height of that virtual bar for mask detection. (default:-1,-1, which uses the total width or height of the sheet)-mp,--mask-scan-step{ step | h-step, v-step } β the steps used to move the virtual bar around while detecting masks. (default:5,5)-mt,--mask-scan-threshold{ threshold | h-threshold, v-threshold } β the ratio of dark pixels below which an edge gets detected, measured relative to maximum blackness while counting from the start coordinate heading towards one edge. (default:0.1)-mm,--mask-scan-minimumw, h β the minimum allowed size of an auto-detected mask. Masks detected below this size get ignored and set to the size given bymask-scan-maximum. (default:100,100)-mM,--mask-scan-maximumw, h β the maximum allowed size of an auto-detected mask. Masks detected above this get shrunk down to the maximum value, each direction individually. (default: sheet size, or the page size derived from--layout)-mc,--mask-colorcolor β the color value used to wipe out pixels not covered by any mask. Handy for testing so you can actually visualize what the masking is doing. (Note that an RGB-value is expected:R*65536 + G*256 + B.) π-dn,--deskew-scan-direction{ left | top | right | bottom },... β which edges to scan for rotation. Each edge of a mask can be used to detect that mask's rotation. If you give multiple edges, the average value gets used β unless the statistical deviation exceeds--deskew-scan-deviation. Useleftto scan from the left edge,topfrom the top edge,rightfrom the right edge,bottomfrom the bottom. Multiple directions go comma-separated. (default:left,right)-ds,--deskew-scan-sizepixels β size of the virtual line used for rotation detection. (default:1500)-dd,--deskew-scan-depthratio β how many dark pixels to accumulate before scanning stops, relative to the scan-bar size. (default:0.5)-dr,--deskew-scan-rangedegrees β the range it searches for rotation in, from-degreesto+degrees. (default:5.0)-dp,--deskew-scan-stepdegrees β the steps between single rotation-angle detections. Lower numbers = better results but slower processing, the classic tradeoff π (default:0.1)-dv,--deskew-scan-deviationdeviation β the maximum statistical deviation allowed among results from the detected edges. If it's exceeded, no rotation happens. (default:1.0)-W,--wipeleft, top, right, bottom β manually wipe out an area. Every pixel in a wiped area gets set to white. Multiple--wipeareas are allowed. This is applied after deskewing and before automatic border-scan. π§Ή-mw,--middle-wipe{ size | left, right } β if--layoutis set todouble, this lets you specify the size of a middle area to wipe out between the two pages on the sheet. Genuinely useful when the blackfilter fails to remove some black areas β like stuff resulting from photo-copying right in the middle between two pages. (iykyk)-B,--borderleft, top, right, bottom β manually add a border. Any pixel in the border area gets set to white. Applied after deskewing and before automatic border-scan.-Bn,--border-scan-direction{ v | h | v,h } β directions to search for the outer border in. You can specifyv(vertical mirroring),h(horizontal mirroring), orv,h(both). (default:v)-Bs,--border-scan-size{ size | h-size, v-size } β width of the virtual bar used for border detection. Two values let you set horizontal and vertical size individually. (default:5,5)-Bp,--border-scan-step{ step | h-step, v-step } β steps used to move the virtual bar for border detection. (default:5,5)-Bt,--border-scan-thresholdthreshold β the absolute number of dark pixels covered by the border-scan mask above which a border gets detected. (default:5)-Ba,--border-align{ left | top | right | bottom } β the direction to shift the detected border-area in. Use--border-marginto specify the horizontal and vertical distances to keep from the sheet-edge. (default:none)-Bm,--border-marginvertical, horizontal β the distance to keep from the sheet edge when aligning a border area. Measurement suffices likecmandinare allowed. π-w,--white-thresholdthreshold β brightness ratio above which a pixel counts as white. (default:0.9)-b,--black-thresholdthreshold β brightness ratio below which a pixel counts as black (non-gray). This one is used by the gray-filter and the blackfilter. It's also used when converting a grayscale image to black-and-white mode. (default:0.33)-ip,--input-pages{ 1 | 2 } β if you set it to2, it reads two input images instead of one and internally combines them into a doubled-layout sheet before any further processing. Before that internal combining happens,--pre-rotationis optionally applied individually to both input images as the very first processing steps.-op,--output-pages{ 1 | 2 } β if you set it to2, it writes two output images instead of one, as a result of splitting a doubled-layout sheet after processing. After the sheet gets split,--post-rotationis optionally applied individually to both output images as the very last processing step. β¨-S,--sheet-size{ width, height | size-name } β forces a fixed sheet size. Normally the sheet size comes from the input image size (ifinput-pages=1), or from the double size of the first page in a two-page input set (ifinput-pages=2). If the input image is smaller than the size you specify here, it shows up centered and surrounded with a white border on the sheet. If the input image is bigger, it gets centered and the edges get cropped. This option can also help you get regular sized output images when your input image sizes differ. Standard size-names likea4-landscape,letter, etc. may be used (see--size). (default: as in input file)--sheet-background{ black | white } β sets a color that fills the sheet before any image is loaded and placed onto it. Great when the sheet size and the image size differ. π¨--no-blackfiltersheet-range β disables black area scan. Individual sheet indices can be specified.--no-noisefiltersheet-range β disables the noisefilter. Individual sheet indices can be specified.--no-blurfiltersheet-range β disables the blurfilter. Individual sheet indices can be specified.--no-grayfiltersheet-range β disables the grayfilter. Individual sheet indices can be specified.--no-mask-scansheet-range β disables mask-detection. Masks you set explicitly with--maskstill have effect, so those don't get thrown out. Individual sheet indices can be specified.--no-mask-centersheet-range β disables auto-centering of each mask. Auto-centering is performed by default if the--layoutoption has been set. Individual sheet indices can be specified.--no-deskewsheet-range β disables deskewing. Individual sheet indices can be specified.--no-wipesheet-range β disables explicit wipe-areas. Meaning: the effect of the--wipeparameter can be turned off individually per sheet.--no-bordersheet-range β disables explicitly set borders. Meaning: the effect of the--borderparameter can be turned off individually per sheet.--no-border-scansheet-range β disables border-scanning from the edges of the sheet. Individual sheet indices can be specified.--no-border-alignsheet-range β disables aligning of the area detected by border-scanning (see--border-align). Individual sheet indices can be specified.-n,--no-processingsheet-range β do not perform any processing on a sheet except pre/post rotating and mirroring, and file-depth conversions on saving. This option has the same effect as setting all the--no-xxxoptions together, fr fr. Individual sheet indices can be specified. π--interpolate { nearest \| linear \| cubic }β sets the interpolation function used for deskewing and stretching, bestie.cubicgives the best image quality, whilenearestis the fastest. (default:cubic) β¨--no-multi-pagesβ turns off multi-page processing even if the input filename contains a%(which usually means βhey, placeholder for the page counter starts hereβ). π«Ά--dpi dpiβ dots per inch used when converting measured size values, like e.g.21cm,27.9cm. Mind that this parameter should occur before specifying any size value with a measurement suffix. (default:300) π-t { pbm \| pgm \| ppm }; --type { pbm \| pgm> \| ppm }β the output file type (and bit depth). If you donβt specify it, the one with the same, or closest, pixel format as the original input files gets used. πpbmβ Portable Bit Map, monochrome raw image.pgmβ Portable Grayscale Map, 8-bit per pixel grayscale raw image.ppmβ Portable Pixel Map, 24-bit per pixel RGB raw image.
-T;--test-onlyβ do not write any output. May be useful in combination with--verboseto get information about the input. π-si nr;--start-input nrβ set the first page number to substitute for%din input filenames. Every time the input file sequence is repeated, this number gets increased by1. (default:(startsheet-1)*inputpages+1) πΈ-so nr;--start-output nrβ set the first page number to substitute for%din output filenames. Every time the output file sequence is repeated, this number gets increased by1. (default:(startsheet-1)*outputpages+1) π--insert-blank nr [,nr...]β use blank input instead of an input file from the input file sequence at the specified index-positions. The input file sequence will be interrupted temporarily and will continue with the next input file afterwards. This can be useful to insert blank content into a sequence of input images. π¦--replace-blank nr [,nr...]β like--insert-blank, but the input images at the specified index positions get replaced with blank content and thus will be ignored. π--overwriteβ allow overwriting existing files. Otherwise the program terminates with an error if an output file to be written already exists. π-q;--quietβ quiet mode, no output at all. π€«-v;--verboseβ verbose output, more info messages. π£οΈ-vvβ even more verbose output, show parameter settings before processing. π-V;--versionβ output version and build information. π
π AUTHOR π
The unpaper authors. π«Ά
π COPYRIGHT π
2020, The unpaper Authors πΈ
okay bestie, thatβs the whole UNPAPER(1) page β source/version UNPAPER(1), dated May 05, 2022 β go forth and unpaper slay π
β¨π
π¦ where this page comes from
- opensuse-leap 16.0: unpaper 7.0.0-bp160.1.13 Β· GPL-2.0-or-later
- opensuse-leap 16.0: unpaper 7.0.0-bp160.1.13 Β· GPL-2.0-or-later
- opensuse-leap 16.0: unpaper 7.0.0-bp160.1.13 Β· GPL-2.0-or-later
- opensuse-leap 16.0: unpaper 7.0.0-bp160.1.13 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms