Code Monkey home page Code Monkey logo

trimpictures's Introduction

Trim Pictures

This Python script automatically trims and deskews scanned photos.

When scanning images on a flatbed scanner I've tended to run into a few problems: it's hard to place a photo on the scanner bed such that it ends up being perfectly axis-aligned without chopping off part of the image; and it's hard to accurately trim the boundaries of the scan region to precisely match the edges of the photograph being scanned.

This is a small command-line tool that helps solve those problems while being robust to background smudges from dirt and dust on the scanner bed. The script works just fine whether the background to be deleted is dark or light. As a bonus, it can also convert images between common file formats.

Samples

Input Output
Input image with skew and dark border Output image aligned and border removed
Input image with light border and jagged edge Output image border removed

The trimming effect in the second image is easier to see if you highlight it or view it on a dark background. Of course this works just fine with more modern, colour photo prints as well.

By the way - if you know where the first photo was taken or what's going on in it, or any of the people in the second photo, please contact me!

Installation

As with most other Python software, first clone the repository, then create and activate a virtualenv:

$ python -m venv venv
$ source venv/bin/activate

Then just install the dependencies listed in requirements.txt:

$ pip install -r requirements.txt

Usage

With the virtualenv active,

$ python trim.py input.jpg output.jpg

It'll bring up a series of windows displaying the image and the contours extracted from it as it goes along; press any key to step through the sequence to the next image. To skip the intermediate visualizations and just write the output image file, add the --quiet flag.

To process a whole folder of images at once just use your shell's loop statment - e.g. in fish (which I highly recommend) I can process a batch of png images from an Originals folder and write the output files to jpg like so:

> for i in Originals/*.png
      python trim.py --quiet $i (basename $i .png).jpg
  end

An analogous construct exists for bash as well, of course.

trimpictures's People

Contributors

krithin avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

trimpictures's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.