0% found this document useful (0 votes)
147 views6 pages

Chapter 03: IMAGE: Part 1: Key Term Quiz

The document provides code examples for performing various image processing tasks using the Python Imaging Library (PIL), including resizing images, rotating images, flipping images vertically or horizontally, cropping images, and pasting one image onto another. It includes multiple choice questions about key concepts in digital images and image file formats. The document is intended to teach basic image manipulation skills using Python and PIL.

Uploaded by

Hồng Nhung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views6 pages

Chapter 03: IMAGE: Part 1: Key Term Quiz

The document provides code examples for performing various image processing tasks using the Python Imaging Library (PIL), including resizing images, rotating images, flipping images vertically or horizontally, cropping images, and pasting one image onto another. It includes multiple choice questions about key concepts in digital images and image file formats. The document is intended to teach basic image manipulation skills using Python and PIL.

Uploaded by

Hồng Nhung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Faculty of information technology, Hanoi University Multimedia

Chapter 03: IMAGE


Part 1: Key Term Quiz
1. The working area of a computer display is sometimes called _______________.
2. The type of image used for photo-realistic images and for complex drawings requiring
fine detail is the _______________.
3. The type of image used for lines, boxes, circles, polygons, and other graphic shapes
that can be mathematically expressed in angles, coordinates, and distances is the
_______________.
4. The picture elements that make up a bitmap are called _______________.
5. _______________ allows you to smoothly blend two images so that one image seems
to melt into the next.
6. The process that computes the bounds of the shapes of colors within a bitmap image
and then derives the polygon object that describes that image is called _______________.
7. _______________ is when the computer uses intricate algorithms to apply the effects
you have specified on the objects you have created for a final 3-D image.
8. ________________ is the blocky, jagged look resulting from too little information in a
bitmapped image.
9. A collection of color values available for display is called a _______________.
10. _______________ is a process whereby the color value of each pixel is changed to
the closest matching color value in the target palette, using a mathematical algorithm.
Part 2. Multiple-Choice Quiz
1. What is the best way to start creating your project’s interface? 1
a. Start with pencil, eraser, and paper.
b. Outline your project and graphic ideas.
c. Storyboard using stick figures.
d. Use three-by-five index cards and shuffle them.
e. All of the above
2. Which image file type is best for photographs?
a. vector
b. encapsulated PostScript
c. bitmap
d. Shockwave
e. laser
3. A 24-bit image is capable of representing how many different colors?
a. 2
b. 16
c. 256
d. 65,536
e. 16,772,216
4. Vector-drawn objects are used for all of the following except:
a. lines
b. circles
c. polygons

Tutor: Nguyen Huy Anh


Faculty of information technology, Hanoi University Multimedia

d. photographs
e. boxes
5. “Unlimited use” of stock photography may actually impose a limitation on:
a. the number of units you can distribute without paying more.
b. the number of changes you can make to the image.
c. converting the image to another file format.
d. the filters you may use to alter the image.
e. the price you can charge for your product.
6. Name the area of memory where data such as text and images is temporarily stored
when you cut or copy within an application.
a. scrapbook
b. notepad
c. junkyard
d. filedump
e. clipboard
7. Perhaps the single most significant advance in computer image processing during the
late 1980s was the development of:
a. digital cameras
b. 3-D modeling programs
c. image-editing programs
d. scanners
e. electronic crayons 2
8. When an image created on a Macintosh is viewed on a PC:
a. it appears darker and richer because the values have changed
b. it appears lighter and less saturated because the values have changed
c. it appears darker and richer even though the values have not changed
d. it appears lighter and less saturated even though the values have not changed
e. it appears exactly the same
9. Graphic artists designing for print media use vector-drawn objects because:
a. they can contain more subtle variations in shading than bitmap graphics
b. printing inks respond better to them
c. they can be converted across platforms more easily
d. they can be scaled to print at any size
e. they can be viewed directly in Web browsers
10. The 3-D process of extending a plane surface some distance, either perpendicular to
the shape’s outline or along a defined path, is called:
a. lathing
b. rendering
c. modeling
d. extruding
e. skinning
11. A GIF image may contain:
a. 8 bits of color information per pixel

Tutor: Nguyen Huy Anh


Faculty of information technology, Hanoi University Multimedia

b. 16 bits of color information per pixel


c. 24 bits of color information per pixel
d. 32 bits of color information per pixel
e. 48 bits of color information per pixel
12. Which of these is the correct HTML hexadecimal representation of magenta (red +
blue)?
a. 00GGHH
b. #FF00FF
c. 255,0,255
d. %R100-%G0-%B100
e. <color = “magenta”>
13. Which of the following is not a color specification format?
a. RGB
b. HSB
c. GIF
d. CMYK
e. CIE
14. Which of the following is not a native Windows graphics file format?
a. BMP
b. RIFF
c. TIFF
d. PCX 3
e. PICT
15. TIFF stands for:
a. Transitional Image File Format
b. Total Inclusion File Format
c. Tagged Interchange File Format
d. Temporary Instruction File Format
e. Table Index File Format
Part 3. Creating an image from scratch

1 From PIL import Image # first two lines import the necessary modules from PIL
2 import ImageDraw
3 txt = "Not really a fancy text!"
4 size = (150, 50)
5 color = (0, 100, 0)
6 img = Image.new('RGB', size, color) # creating image using Image.new
7 imgDrawer = ImageDraw.Draw(img) # The function ImageDraw.Draw takes an image
object as an argument to create a Draw instance. This Draw instance enables drawing
various things in the given image.
8 imgDrawer.text((5, 20), txt) # we call the text method of the Draw instance and supply
position (a tuple) and the text (stored in the string txt) as arguments.
9 img.show()

Tutor: Nguyen Huy Anh


Faculty of information technology, Hanoi University Multimedia

Part 4. Resizing
Download the image from internet.
Write the following code. Replace the inPath and outPath strings with the appropriate
image path on your machine.

1 import Image
2 inPath = "C:\\images\\ImageResizeExample.jpg"
3 img = Image.open(inPath)
4 width , height = (160, 160)
5 size = (width, height)
6 foo = img.resize(size)
7 foo.show()
8 outPath = "C:\\images\\foo.jpg"
9 foo.save(outPath)

#Line 6 in the code snippet does the resizing job and finally we save the new image on
line 9. You can see how the resized image looks by calling foo.show().

Let’s specify the filter argument.

1 From PIL import Image


2 inPath = "C:\\images\\ImageResizeExample.jpg" 4
3 img = Image.open(inPath)
4 width , height = (160, 160)
5 size = (width, height)
6 filterDict = {'NEAREST':Image.NEAREST,
7 'BILINEAR':Image.BILINEAR,
8 'BICUBIC':Image.BICUBIC,
9 'ANTIALIAS':Image.ANTIALIAS }
10
11 for k in filterDict.keys():
12 outPath= "C:\\images\\" + k + ".jpg"
13 filterOpt = filterDict[k]
14 foo = img.resize(size, filterOpt)
15 foo.save(outPath)

Tutor: Nguyen Huy Anh


Faculty of information technology, Hanoi University Multimedia

Part 5 Rotating
Use your image and write down following code:

1 import Image
2 inPath = "C:\\images\\Rotate.png"
3 img = Image.open(inPath)
4 deg = 45
5 filterOpt = Image.BICUBIC
6 outPath = "C:\\images\\Rotate_out.png"
7 foo = img.rotate(deg, filterOpt)
8 foo.save(outPath)

Part 6 Flipping
Use your image and write down following code:

1 import Image
2 inPath = "C:\\images\\Flip.png"
3 img = Image.open(inPath)
4 outPath= "C:\\images\\Flip_out.png"
5 foo = img.transpose(Image.FLIP_LEFT_RIGHT)
6 foo.save(outPath)
5
# To flip the image vertically, replace line 5 in the code with the following:
foo = img.transpose(Image.FLIP_TOP_BOTTOM)

The same effect can be achieved using the ImageOps module. To flip the image
horizontally, use ImageOps.mirror, and to flip the image vertically, use ImageOps.flip.

import ImageOps
# Flip image horizontally
foo1 = ImageOps.mirror(img)
# Flip image vertically
foo2 = ImageOps.flip(img)

Part 7 Cropping

Use your image and write down following code:

import Image
img = Image.open("C:\\images\\Crop.png")
left = 0
upper = 0
right = 180

Tutor: Nguyen Huy Anh


Faculty of information technology, Hanoi University Multimedia

lower = 215
bbox = (left, upper, right, lower)
img = img.crop(bbox)
img.show()

Part 8 Pasting
Use your image and write down following code:

1 import Image
2 img = Image.open("C:\\images\\Crop.png")
3 # Define the elements of a 4-tuple that represents
4 # a bounding box ( region to be cropped)
5 left = 0
6 upper = 25
7 right = 180
8 lower = 210
9 bbox = (left, upper, right, lower)
10 # Crop the smiley face from the image
11 smiley = img.crop(bbox_1)
12 # Flip the image horizontally
13 smiley = smiley.transpose(Image.FLIP_TOP_BOTTOM)
14 # Define the box as a 2-tuple. 6
15 bbox_2 = (0, 210)
16 # Finally paste the 'smiley' on to the image.
17 img.paste(smiley, bbox_2)
18 img.save("C:\\images\\Pasted.png")
19 img.show()

After finish, submit all your work to FIT.


Thanks!

Tutor: Nguyen Huy Anh

You might also like