08.06.2015 Views

Building Machine Learning Systems with Python - Richert, Coelho

Building Machine Learning Systems with Python - Richert, Coelho

Building Machine Learning Systems with Python - Richert, Coelho

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Computer Vision – Pattern Recognition<br />

This screenshot of a building is one of the images in the dataset. We will use this<br />

screenshot as an example.<br />

As you may be aware, image processing is a large field. Here we will only be looking<br />

at some very basic operations we can perform on our images. Some of the most basic<br />

operations can be performed using NumPy only, but otherwise we will use mahotas.<br />

Thresholding<br />

Thresholding is a very simple operation: we transform all pixel values above a<br />

certain threshold to 1 and all those below to 0 (or by using Booleans, transform it<br />

to True and False):<br />

binarized = (image > threshold_value)<br />

The value of the threshold width (threshold_value in the code) needs to be<br />

chosen. If the images are all very similar, we can pick one statically and use it for<br />

all images. Otherwise, we must compute a different threshold for each image based<br />

on its pixel values.<br />

Mahotas implements a few methods for choosing a threshold value. One is called<br />

Otsu, after its inventor. The first necessary step is to convert the image to grayscale<br />

<strong>with</strong> rgb2gray.<br />

[ 202 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!