ocrmypdf-image

$npx mdskill add partme-ai/full-stack-skills/ocrmypdf-image

Deskew, rotate, clean, despeckle, and remove borders from scanned PDFs to improve quality before OCR.

  • Fixes skewed pages, removes noise, and cleans up scanned documents for better readability.
  • Integrates with OCRmyPDF's image processing tools for document enhancement.
  • Uses command-line options like --deskew and --rotate-pages to apply specific corrections.
  • Outputs processed PDF files ready for further OCR or optimization steps.

SKILL.md

.github/skills/ocrmypdf-imageView on GitHub ↗
---
name: ocrmypdf-image
description: OCRmyPDF image processing skill — deskew, rotate, clean, despeckle, remove border from scanned documents. Use when the user needs to improve scanned PDF quality, fix skewed pages, remove noise, or clean up scanned documents before OCR.
---

# OCRmyPDF — Image Processing Guide

## Overview

[OCRmyPDF](https://github.com/ocrmypdf/OCRmyPDF) includes powerful image processing capabilities to improve scan quality before OCR. These tools help fix skewed pages, remove noise, clean borders, and enhance readability.

For core OCR functionality, see the **ocrmypdf** skill. For optimization and PDF/A options, see **ocrmypdf-optimize**. For batch/Docker/scripting, see **ocrmypdf-batch**.

## Deskew

Deskew corrects pages that are slightly rotated (e.g., from feed scanner skew).

```bash
# Auto deskew (recommended)
ocrmypdf --deskew input.pdf output.pdf

# Force deskew even if rotation is minimal
ocrmypdf --deskew --force-ocr input.pdf output.pdf
```

## Rotation

Rotate pages to correct upside-down or sideways scans:

```bash
# Auto-rotate based on text orientation
ocrmypdf --rotate-pages input.pdf output.pdf

# Force rotate all pages
ocrmypdf --rotate-pages --force-ocr input.pdf output.pdf
```

## Remove Borders / Cleaning

Remove unwanted borders, artifacts, and noise from scanned pages:

```bash
# Remove borders (dots, solid borders)
ocrmypdf --remove-bordering input.pdf output.pdf

# Combine with cleanup
ocrmypdf --remove-bordering --clean input.pdf output.pdf
```

## Despeckle

Remove speckles and isolated noise pixels:

```bash
# Remove speckles
ocrmypdf --despeckle input.pdf output.pdf

# Aggressive despeckle for very noisy scans
ocrmypdf --despeckle --clean input.pdf output.pdf
```

## Unpaper

[unpaper](https://github.com/Flameeyes/unpaper) provides advanced post-processing:

```bash
# Apply unpaper with default settings
ocrmypdf --unpaper input.pdf output.pdf

# Custom unpaper board options
ocrmypdf --unpaper-args "--board A4" input.pdf output.pdf
```

## Oversampling

Increase image resolution before OCR for better accuracy:

```bash
# Oversample to 300 DPI before OCR
ocrmypdf --oversample 300 input.pdf output.pdf

# Common for low-resolution scans
ocrmypdf --oversample 400 input.pdf output.pdf
```

## Combined Recipes

### Fix a skewed scan

```bash
ocrmypdf --deskew --remove-bordering --despeckle scanned.pdf fixed.pdf
```

### Clean up a very noisy scan

```bash
ocrmypdf --deskew --rotate-pages --despeckle --clean --oversample 300 noisy.pdf clean.pdf
```

### Remove all artifacts

```bash
ocrmypdf --remove-bordering --unpaper --despeckle dirty.pdf clean.pdf
```

## Quick Reference

| Task | Command |
|------|---------|
| Auto deskew | `--deskew` |
| Auto rotate | `--rotate-pages` |
| Remove borders | `--remove-bordering` |
| Remove speckles | `--despeckle` |
| Unpaper | `--unpaper` |
| Oversample DPI | `--oversample N` |

## Troubleshooting

- **Poor OCR after cleaning**: Try `--oversample 300` to increase input quality.
- **Artifacts remain**: Use `--unpaper` for aggressive cleanup.
- **Over-cleaned image**: Reduce cleaning options for preserve original quality.

More from partme-ai/full-stack-skills

SkillDescription
adobe-xd"Guides creation of UI/UX designs, interactive prototypes, reusable components, and design specs in Adobe XD. Use when the user asks about Adobe XD artboards, prototype links, repeat grids, component states, design tokens export, or developer handoff."
angular"Provides comprehensive guidance for Angular framework including components, modules, services, dependency injection, routing, forms, and TypeScript integration. Use when the user asks about Angular, needs to create Angular applications, implement Angular components, or work with Angular features."
ansible"Provides comprehensive guidance for Ansible automation including playbooks, roles, inventory, and module usage. Use when the user asks about Ansible, needs to automate IT tasks, create Ansible playbooks, or manage infrastructure with Ansible."
ant-design-mini"Builds mini-program UIs with Ant Design Mini components for Alipay and WeChat mini-programs. Covers Button, Form, List, Modal, Tabs, NavBar, and 60+ components with theme customization and CSS variable theming. Use when the user needs to create mini-program interfaces with Ant Design Mini, configure themes, or implement mini-program-specific UI patterns."
ant-design-mobile"Builds React mobile UIs with Ant Design Mobile (antd-mobile) components including Button, Form, List, Modal, Picker, Tabs, PullToRefresh, InfiniteScroll, and 50+ mobile-optimized components. Use when the user needs to create mobile-first React interfaces, implement mobile navigation, forms, or data display with Ant Design Mobile."
ant-design-react"Builds enterprise React UIs with Ant Design (antd) including 60+ components (Button, Form, Table, Select, Modal, Message), design tokens, TypeScript support, and ConfigProvider theming. Use when the user needs to create React applications with Ant Design, build forms with validation, display data tables, or customize the Ant Design theme."
ant-design-vueProvides comprehensive guidance for Ant Design Vue (AntDV) component library for Vue 3. Covers installation, usage, API reference, templates, and all component categories. Use when building enterprise-class UI with Vue 3 and Ant Design.
api-doc-generator"Generate API documentation by scanning Controller classes, extracting endpoint URLs, HTTP methods, parameters, and response structures, then producing standardized docs from templates. Use when the user explicitly mentions generating API documentation, creating API docs, scanning interfaces, or documenting REST APIs. Do not trigger for generic documentation requests without explicit API mention."
appium"Provides comprehensive guidance for Appium mobile testing including mobile app automation, element location, gestures, and cross-platform testing. Use when the user asks about Appium, needs to test mobile applications, automate mobile apps, or write Appium test scripts."
ascii-ansi-colorizer"Add an ANSI color layer to existing ASCII/plain-text output (gradient/rainbow/highlights) with alignment-safe rules and a required no-color fallback. Use when the user wants to colorize terminal output, add rainbow effects to CLI text, or style ASCII art with ANSI colors."