19 Manipulating Images Flashcards

1
Q
  1. What is an RGBA value? What is min, what is max?
A

RGBA value:
Group of numbers that specify the amount of reg, green blue and alpha (transparency). Can be specified individually for every pixel
Min = 0
Max = 225

Red (255, 0, 0, 255)
Green (0, 128, 0, 255)
Blue (0, 0, 255, 255)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. How can you get the RGBA value of ‘CornflowerBlue’ from the Pillow module?
A

> > > from PIL import ImageColor
ImageColor.getcolor(‘CornflowerBlue’, ‘RGBA’)
(100, 149, 237, 255)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What is a box tuple?

Explain with crop example

A

> > > from PIL import Image
catIm = Image.open(‘zophie.png’)
croppedIm = catIm.crop((335, 345, 565, 560))

For the Box tuple two coordinates are defined: The top left corner, which is the first two digits, and the bottom right corner, which is the last two digits.
The outermost top left corner of the page is (0,0), whereas the first digit is the width = x and the second digit is the height = y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What function returns an Image object for, say, an image file named zophie.png?
A

> > > from PIL import Image

|&raquo_space;> catIm = Image.open(‘zophie.png’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. How can you find out the width and height of an Image object’s image?

What trick can you apply to it?

A

> > > from PIL import Image
im = Image.open(‘img.png’)
im.size
(816, 1088)

Tuple Enpacking
&raquo_space;> width, height = catIm.size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. What method would you call to get Image object for a 100×100 image?
A

> > > from PIL import Image
im = Image.new(‘RGBA’, (100, 200), ‘color’)

if color isn´t given, the default will be (0,0,0,0), which is black

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. How do you resize an Image object and save it afterwards as an image file?
A

> > > from PIL import Image
catIm = Image.open(‘zophie.png’)
width, height = catIm.size
quartersizedIm = catIm.resize((int(width / 2), int(height / 2)))
quartersizedIm.save(‘quartersized.png’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. What module contains Pillow’s shape-drawing code?
A

> > > from PIL import Image, ImageDraw

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Image objects do not have drawing methods. What kind of object does? How do you get this kind of object?
A

Draw objects!

> > > im = Image.new(‘RGBA’, (200, 200), ‘white’)
draw = ImageDraw.Draw(im)
draw.line([(0, 0), (199, 0), (199, 199), (0, 199), (0, 0)], fill=’black’)
for i in range(100, 200, 10):
draw.line([(i, 0), (200, i - 100)], fill=’green’)
im.save(‘drawing.png’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Summary of useful methods
A

> > > from PIL import Image
im = Image.open(‘…’) = *

*.crop(), copy(), paste(), resize(), rotate(), transpose()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly