0

So I'm going to give a little background on the project I'm working on. First of all I'm trying to use python's image processing libraries to determine how the area of a certain element changes with respect to time. Basically I have a black ramp that a powder will creep up as a function of time. I plan to quantify this by converting to monochrome/grey scale then computing the average pixel change for the region of interest.

Now to my actual question, what is the best way to basically crop an image based on this boundary? I want to remove as much unnecessary data from system. The images are going to change slightly from one test run to another so automating it is necessary.

Posting a good reference for these sorts of projects would actually be preferred. Thanks!

Zack
  • 19
  • 5
  • 2
    Use the [OpenCV](http://opencv.org/) module for anything related to computer vision. – pzp Jul 27 '15 at 16:14

1 Answers1

1

You can use crop() function from the PIL library but you would need to determine the dimension parameters. Here's a link with simple logic for cropping the center of an image...

Crop an image in the centre using PIL

If you're lucky then you can just go with a simple routine to cut out white space...

Use Python / PIL or similar to shrink whitespace

But since you're dealing with photographs you will likely have artifacts that inhibit an all white space crop. You'll need to add some tolerance so that a single pixel doesn't throw off the crop dimensions. You can loop through a list of tuples containing your image's RGB values using the snippet from here...

Getting list of pixel values from PIL

Then you would need to write the logic that determines what's an artifact and what is not.

Community
  • 1
  • 1
abaldwin99
  • 903
  • 1
  • 8
  • 26
  • Appreciate the post. Gives me a good place to get started. I'm going to be converting to gray scale then I think I will crop based on a pixel threshold value. – Zack Jul 27 '15 at 16:46
  • You can use `convert('L')` in PIL to convert to gray scale. Again if you need more control over the gray scale conversion there's good posts out there waiting for you... http://stackoverflow.com/questions/18777873/convert-rgb-to-black-or-white – abaldwin99 Jul 27 '15 at 16:56
  • Also take a look at the simpleCV project. I don't have personal experience with it but it might be of use to you. – abaldwin99 Jul 27 '15 at 17:02
  • Actually that looks perfect. I'll check it out a bit more – Zack Jul 27 '15 at 17:24