Images

Mon W1

Announcements

  • Welcome to IDS-101-13: Thinking Machines!
  • Week 4!
  • Shouvik, who is allegedly cool and fun, made us look at this on Friday: import numpy as np img_arr = np.array([ [1, 2, 3], [4, 5, 6] ])
  • At least I think that's what happened, I found it boring and fell asleep instantly.
  • In my dream, I imaged the impossible... what if numpy was good?

Images

  • I literally only ever used numpy for one thing ever. import numpy as np from PIL import Image as im
  • I used it with the famous "Python Image Library" to make digital art.
  • This is an actual assignment in one of my upper division classes: brot.py

Images

  • It is relatively easy to convert a np array into an image:
    • A numpy array is a basically a list of rows.
    • Each row is a list of "pixels" - the tiniest unit our screen can display.
    • The value in some pixel in some row gives how bright that pixel is.
  • Image a computer doing pointillism, perhaps.
    Pointillism is a technique of painting in which small, distinct dots of color are applied in patterns to form an image.
  • So we say: take 2 steps over and 1 steps down, and using a relatively dark color, perhaps. step_over = 2 step_down = 1 brightnes = 0 # relatively dark img_arr[step_over][step_down] = brightnes
  • By the way I have no idea if over/down is correct - check it by making things bright or dark.

Images

  • Once we have set any brightness in our array, we use the following code from the image library: im.fromarray(img_arr) # 'im.fromarray' from PIL # 'img_arr' we just made
  • I think by default this doesn't work because PIL has very specific tastes in arrays.
  • Recall: Shouvik told us arrays have different types.

Images

  • For whatever reason, we have to use "np.uint8" (look it up when you feel like it) img_arr = np.array([ [1, 2, 3], [4, 5, 6] ]).astype(np.uint8) # From an error message im.fromarray(img_arr)
  • This will make a very small image.

Images

  • To make something big enough to see... # let's make a 110 by 120 image of brightness 130 reg_arr = [[130 for i in range(110)] for i in range(120)] img_arr = np.array(reg_arr).astype(np.uint8) im.fromarray(img_arr)
  • This will make a very small image.
Group 1Group 2Group 3Group 4

Question #1

How are you enjoying CC so far?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Question #2

Do we like images more than, say, lists or pandas dataframes or numpy arrays?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Question #3

What makes something art?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Digital Art

  • Exercise C.1 Create something you find beautiful.
    • Consider the following:
      • You can determine maximum brightness by increasing it until something breaks.
      • Computer monitors don't display only brightness, but color, using 3 brightnesses.
      • Gradients, changes in color over space, occur by determining color based on the position in an image.
    • I claim: beauty is created by community - work together to design and build.
    # let's make a 110 by 120 image of increasing brightness. reg_arr = [[i for i in range(110)] for j in range(120)] img_arr = np.array(reg_arr, dtype=np.uint8) im.fromarray(img_arr)

Bonus

  • Exercise C.1 Create something you find beautiful.
    • My first thing: reg_arr = [[i for i in range(110)] for j in range(120)] img_arr = np.array(reg_arr).astype(np.uint8) im.fromarray(img_arr)

Bonus

  • Exercise C.1 Create something you find beautiful.
    • Something beautiful (to me): im.fromarray(np.array([[[i + j, i + -j,-i + j] for i in range(255)] for j in range(255)]).astype(np.uint8))
    • Cramming this all on one line is admittedly obnoxious, but I hope will make you thing for yourself while still learning something (let me know).

Question #4

What do you do when given a hard problem?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Homework

  • Homework 3 Electoral Votes
    • Using multiple line strings, the new .split() method, and what you know about indices, write code that takes the information from Archives.gov and creates a list of states and their number of electoral votes.
    • This is a special list that will help us latter.
      • You may need many lines of code or many cells.
      • Whatever you submit you should test using "run all" or "ctrl+F9" to make sure that when I run your code, or when you run the code in the future, that it does what you expect.
    • You may make a copy of this Notebook and share it with me and anyone with whom you collaborate.
      • Give Shouvik and I edit permissions.
      • Due Fri @ 12 Noon (so we're able to discuss it in class)
      • You may only give your peers view or comment permissions.
    • It is more important to try things that interest you than to complete the assignment.