build details

Show: section status errors & todos local changes recent changes last change in-page changes feedback controls

Exercise: Instagram filters

Modified 2019-09-22 by Andrea Censi

Skills learned

Modified 2019-09-22 by Andrea Censi

  • Image pixel representation;
  • Image manipulation;
  • The idea that we can manipulate operations as objects, and refer to them (higher-order computation);
  • The idea that we can compose operations, and sometimes the operations do commute, while sometimes they do not.

Instructions

Modified 2019-09-22 by Andrea Censi

Create dt-instagram as specified below.

Specification for dt-instagram

Modified 2019-09-22 by Andrea Censi

Write a program dt-instagram that applies a list of filters to an image.

The syntax to invoke the program is:

$ dt-instagram image in filters image out

where:

  • image in is the input image;
  • filters is a string, which is a colon-separated list of filters;
  • image out is the output image.

The list of filters is given in Subsection 4.3.1 - List of filters.

For example, the result of the command:

$ dt-instagram image.jpg flip-horizontal:grayscale out.jpg

is that out.jpg contains the input image, flipped and than converted to grayscale.

Because these two commute, this command gives the same output:

$ dt-instagram image.jpg grayscale:flip-horizontal out.jpg

List of filters

Modified 2019-09-22 by Andrea Censi

Here is the list of possible values for the filters, and their effect:

  • flip-vertical: flips the image vertically
  • flip-horizontal: flips the image horizontally
  • grayscale: Makes the image grayscale
  • sepia: make the image sepia

Useful new APIs

Modified 2019-09-22 by Andrea Censi

User defined filters

Modified 2019-09-22 by Andrea Censi

In OpenCV it is possible to define custom filters and apply them to an image. A linear filter (e.g., sepia) is defined by a linear 9-dimensional kernel. The sepia filter is defined as:

K_{sepia} = \begin{bmatrix} 0.272 & 0.534 & 0.131 \newline 0.349 & 0.686 & 0.168 \newline 0.393 & 0.769 & 0.189 \end{bmatrix}

A linear kernel describing a color filter defines a linear transformation in the color space. A transformation can be applied to an image in OpenCV by using the function transform().