とらりもんHOME  Index  Search  Changes  Login

Python training course - exercise 1

2018/05/24 Ishibashi

link to Python training course in hiki (only lab network.)

link to exercise 2

link to answer

Exercise 1

In exercise 1, we will use PIL, Matplotlib, numpy.

Through this exercise, you can be able to import a image from your PC to Python, export a image from Python to your PC, and also conduct simple image data processing.

A learner is expected to finish "Learn the Basics" & "Data Science Tutorials", before starting this exercise.

Exercise 1.1: import, make white-black and export a image.

  • Preparation: Download lena.png. you can use "wget" command in shell, or you can search URL.
wget http://optipng.sourceforge.net/pngtech/img/lena.png
  • Exercise 1.1.1: import "lena.png" to Python using PIL. (a tip: putting a image into a variable.)
  • Exercise 1.1.2: import "lena.png" to Python using matplotlib. (a tip: putting a image into a variable.)
  • Exercise 1.1.3: show 2 images (in ex 1 & 2) data type using "type()" function.
  • Exercise 1.1.4: make white-black image of "lena.png" and export to your PC using PIL.
  • Exercise 1.1.5: make white-black image of "lena.png" and export to your PC using matplotlib. (a tip: using numpy)

Exercise 1.2: resize image

  • Exercise 1.2.1: import "lena.png" and see the pixel numbers.
  • Exercise 1.2.2: resize "lena.png" into 200 pixel by 200 pixel image using PIL (resampling pixels.) → sample image of Ex 1.2.2
  • Exercise 1.2.3: resize "lena.png" into 200 pixel by 200 pixel image using PIL or matplotlib (cutting image.) → sample image of Ex 1.2.3
Last modified:2019/01/08 14:13:22
Keyword(s):
References: