Category Archives: Programming Language

TensorFlow and deep learning, without a PhD

Excellent introductory video from Google’s Martin Gorner covering the handwritten 0-9 digits recognition problem using the MNIST data set.  Code is Python using the Tensorflow library.

He begins with a single layer network, progresses into a multi-layer network and ends with a convolutional neural network, showing how improvements in techniques correspond to better test accuracy.

Covers softmax, sigmoid, ReLU, matrix transformation, convolutional networks, over-fitting, test and training accuracy.

Well worth a watch for beginners and has better explanations than some full courses online.

Note: they figure out the microphone feedback situation around minute 15 or 16.


Flip Image OpenCV Python

OpenCV provides the flip() function which allows for flipping an image or video frame horizontally, vertically, or both.



OpenCV documentation:

Open Multiple Images with OpenCV in Python

Building on our previous example of opening a single image, this guide will explain how to open multiple images. The easiest way to load multiple images is to put all the images into a single folder and loop through the directory opening each one.

This guide doesn’t introduce any new OpenCV functions you shouldn’t already be familiar with from the previous example, but we will include new packages os and os.path to make a list of images to process.

The code

A note on OpenCV image support from the OpenCV docs (

Note OpenCV offers support for the image formats Windows bitmap (bmp), portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With help of plugins (you need to specify to use them if you build yourself the library, nevertheless in the packages we ship present by default) you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000 (jp2 – codenamed in the CMake as Jasper), TIFF files (tiff, tif) and portable network graphics (png). Furthermore, OpenEXR is also a possibility.

Boilerplate code


Open an Image with OpenCV in Python

The following code will get you started to load and display an image with OpenCV and Python.

OpenCV functions used:

The code


Boilerplate code


Where to next?

Install OpenCV 3.x with Python 2.7 on Ubuntu

Updated: 10/11/2016

How to Install OpenCV 3.x and Python 2.7+ on Ubuntu

Step 1:

Open a terminal window and update the apt package manager lists and upgrade any currently installed packages:

Step 2:

Install developer tools:

Step 3:

Install packages to open image formats including JPEG, PNG, TIFF, and others:

Step 4:

Install the GIMP toolkit (GTK+) which OpenCV uses to build GUIs:

Step 5:

Install packages to open video formats:

Step 6:

Install libraries that optimize various routines in OpenCV:

Step 7:

Install pip, a package manager for Python: is the official pip website

Step 8:

Install Python 2.7 development tools:

Step 9:

Install numpy because OpenCV stores images as NumPy arrays

This post follows, updates and adds to the instructions from Py Image Search here:

MLBD Machine Learning is Fun! Part 3: Deep Learning and Convolutional Neural Networks

Here we follow along with the 3rd part of Adam Geitgey’s excellent introductory series Machine Learning is Fun! “Deep Learning and Convolutional Neural Networks”

For the original article, click here.

The example presented is an object recognition classifier to determine whether or not something is a bird.  To complete this tutorial you will need:

  • TFLearn
  • TensorFlow
  • Python 2.7
  • Birds and not birds data set


Original test script

Capitalized Case JavaScript code


Code adapted from ‘Convert string to title case with javascript‘ users Greg DeanBill the Lizard  licensed under cc by-sa 3.0

CC: “Python for Informatics” Open Textbook Remixed in 11 Days

Image: dr-chuckCC BY


Chuck Severance, clinical professor at the University of Michigan’s School of Information, recently published a new textbook in 11 days because he was able to remix an existing textbook. The book, Python for Informatics: Exploring Information, is currently being used in his winter semester Networked Computing course. The textbook is based on the openly licensed book Think Python: How to Think like a Computer Scientist by Allen B. Downey. Students are able to take advantage of the University Library’s Espresso Book Machine to print on-demand copies for approximately $10. Python for Informatics is available under a CC BY-SA license.

Severance explains, “the book is a cool example of a situation where I’ve finally got to the ‘remixing’ bit of the Open promise.” The first 10 chapters are done and eight more are planned for completion by April 2010. Read more of Chuck’s thoughts about remixing an open book.

Creating this open textbook was a part of a larger effort by Chuck to support his course with openly licensed  content, and current versions of lecture slides and videos are published via the PythonLearn website.  In a past iteration of the course, Chuck went through the dScribe process developed by Open.Michigan to create an OER version of SI 502, available under a CC BY license.

Helpful Image Commands Matlab/Octave

% Load and display an image

img = imread(‘filename.jpg’)


% Image size


% Image class (data type):


% At a given location (row, col):

disp(img(50, 100));

% For an entire row:

disp(img(50, :));

plot(img(50, :));


% A slice of an image

img(101:103, 201:203))


% Crop an image

cropped = img(110:310, 10:160)


Color images

Note: Matlab indexes begin at 1 not 0

% Get the red layer (RGB)

img_red = img(:, :, 1);

% Get the green layer (RGB)

img_green = img(:, :, 2);

% Get the blue layer (RGB)

img_blue = img(:, :, 3);


Image arithmetic

% Add two images

summed = img_1 + img_2

% Average of two images

average = img_1 / 2 + img_2 / 2

% Multiply by a scalar

0.5 * img

% Blend two images

result = 0.75 * img_1 + 0.25 * img_2

% Image difference

diff = img_1 – img_2

diff = img_2 – img_1

% Absolute image difference

imabsdiff(img_1, img_2)