とらりもんHOME  Index  Search  Changes  Login

とらりもん - Python training course - exercise 1 Diff

  • Added parts are displayed like this.
  • Deleted parts are displayed like this.

2018/05/24 Ishibashi

[[link to Python training course|http://pen.agbi.tsukuba.ac.jp/~ryuiki_plus/hiki/?Python+training]] course|http://pen.envr.tsukuba.ac.jp/~ryuiki_plus/hiki/?Python+training]] in hiki (only lab network.)

[[link to exercise 2|http://pen.agbi.tsukuba.ac.jp/~torarimon/?Python+training+course+-+exercise+2]]2|http://pen.envr.tsukuba.ac.jp/~torarimon/?Python+training+course+-+exercise+2]]

[[link to answer|http://pen.agbi.tsukuba.ac.jp/~torarimon/?exercise+1+answer]]answer|http://pen.envr.tsukuba.ac.jp/~torarimon/?exercise+1+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"|https://www.learnpython.org/]], 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|http://saint-log.com/src/image/exercise_1_2_2.html]]
* 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|http://saint-log.com/src/image/exercise_1_2_3.html]]