Uploaded by PayPal dfy

Сode.org Unit 2 Chapter 1 Review 2

advertisement
Unit 2 Chapter 1 Review
Vocabulary

Heuristic: a problem solving approach (algorithm) to find a satisfactory solution where finding an
optimal or exact solution is impractical or impossible.

Lossless Compression: a data compression algorithm that allows the original data to be perfectly
reconstructed from the compressed data.

Image: A type of data used for graphics or pictures.

Metadata: Data that describes other data. For example, a digital image may include metadata that
describe the size of the image, number of colors, or resolution.

Pixel: Short for "picture element" it is the fundamental unit of a digital image, typically a tiny square
or dot which contains a single point of color of a larger image.

Hexadecimal Number System: A number system consisting of 16 distinct symbols — 0-9 and A-F —
which can occur in each place value.

Lossless: A compression scheme in which every bit of the original data can be recovered from the
compressed file.

Lossy: A compression scheme in which “useless” or less-than-totally-necessary information is thrown
out in order to reduce the size of the data. The eliminated data is unrecoverable.

Abstraction: Removing unnecessary details to focus on the essential characteristics. To break
problems up into separate parts which can then be solved separately and recombined to form a
complete solution. To focus on and use something based only on what it does and without concern
for how that functionality is accomplished.

1. Using the B&W file format from the pixelation widget
o
What are the largest dimensions (width and height) of an image we can make with the
pixelation widget?
255 x 255. Because there is only 1 byte each for width and height, the largest you can
set the width to is 1111 1111 = 255.
o
How many total bits would there be in the largest possible image we could make with the
pixelation widget?
Slightly tricky question. The answer is 65,041 bits. The largest image is 255x255 =
65,025, but we also need to add in the 16 bits for the metadata.
o
How many bits would it take to represent the smallest possible image (i.e. an image with
one pixel)?
17 bits. 16 bits for metadata, plus 1 bit for the single pixel.
pg. 1
Unit 2 Chapter 1 Review
2.
What would happen if we didn’t include width and height bits in our protocol? Assume your friend
just sent you 32 bits of pixel data (just the 0s and 1s for black and white pixels). Could you recover the
original image? If so, how?
Without the metadata we do not know immediately what the dimensions of the image are
supposed to be. With 32 bits, there are 6 possible pairs of dimensions for the image: 1x32, 2x16,
4x8 and their inverses. You could recover the original image by setting the metadata to each of
those possibilities and seeing if it looked like anything recognizable.
What are the largest dimensions (width and height) of an image we can make with the
pixelation widget?
A: 255 x 255
Explanation:
1. The max image size is 255 x 255 because the width and height can only be expressed with 8 bits
each, and the max value you can express with 8 bits is 255.
Q: How many total bits would there be in the the largest possible image we could make
with the pixelation widget?
A: 65,041 bits
Explanation:
1. The max image size is 255 * 255 = 65,025 (because width and height are only allocated 8-bits
each).
2. Since in this image there is one bit per pixel that means there are 255 * 255 = 65,025 bits of image
data
3. However, the image file also must contain the 16 bits of width and height metadata, which are 8 bits
each.
4. So the total is: width * height + metadata = 255 * 255 + 16 = 65,041 .
Q: How many bits would it take to represent the smallest possible image (i.e. an image
with one pixel)?
A: 17 bits
Explanation:
1. The image data is 1x1, and if we only encode 1 bit per pixel (B&W) then we only need 1 bit for that.
pg. 2
Unit 2 Chapter 1 Review
2. However, there are still 16 bits of metadata, 8 bits for height, 8 for width.
3. So the total (just as above) is: width * height + metadata = 1 * 1 + 16 = 17 .
Since this example is small enough you can prove it to yourself. Here is the data for a
1x1 image:
0000 0001
0000 0001
1
1. Why were images first broken down into pixels? What problem did this solve?
Images had to be broken down into pixels so that a computer could represent them digitally.
2.
How many different values can be represented by one Red component of a pixel?
256 (0 to 255)
3.
What are screen resolution and pixel density? How do they differ? Draw a diagram to support
your answer.
Screen resolution is the number of pixels on a screen as arranged vertically and horizontally, and
density is the number of pixels per a given area.
Screen Resolutions
Pixel Density - Same resolution, but phone has more density
pg. 3
Unit 2 Chapter 1 Review
4.
a.
RGB values
Why do RGB values range from 0 to 255?
RGB values are represented by 8 bits, where the min value is 0 and the max is 255.
b. Can they be any other range?
They can be any range someone desires, the range is arbitrary.
c.
What happens if you increase the range?
If you increase the range, the number of colors that can be represented increase.
d. Is it possible to represent all of the colors in the world? Why or why not?
It isn’t possible to represent all of the colors in the world, because the color spectrum is
continuous and computers work with discrete values.
5.
Describe a function that would take in any RGB value and double its intensity. What do you think
happens if the input is 200, 220, 209?
R x 2, G x 2, Y x 2
Possible answers:
 The numbers cycle around beyond 255 back to the 0 side (145, 165, 154).
 The numbers max out and become 255, 255, 255.
6.
Extra: Take out the calculator! How many different colors can be represented in the standard
RGB color model?
256 x 256 x 256 = 16,777,216 colors
1. Rewrite this string of numbers from raw format to readable format, and identify or label the
sections of bits.
000000100000001000000011010010101010
0000 0010
0000 0010
0000 0011
010 010
101 010
2.
How many more colors are available with 12 bits-per-pixel than 6 bits-per-pixel?
6 bits = 2^6 = 64 colors
12 bits = 2^12 = 4096 colors
4096-64 = 4,032
12 bits-per-pixel has 4,032 more colors!
3.
What happens if you have you an image that has 6 bits-per-pixel and you change it to 12?
Reasonable response: You will see a variety of different colors in the image, and the image will
look scrambled.
HOWEVER, if a student actually tries this with a large enough image, they will be surprised to find
that the image is recognizable but you see two of them. This happens any time you double the
pg. 4
Unit 2 Chapter 1 Review
number of bits per pixel. Here is an an example. The bee on the left was encoded with 12-bitsper-pixel. The image on the right shows what happens when you increase to 24 bits-per-pixel.
4.
A digital artist comes up to you and says, “Help! I need a 12-bit color that’s just a little bit greener
than #79B.” What would you suggest and why?
A color like #7AB would be a little bit greener because I increased the value of the green
value. Note: There are several ways to do this but expected responses to this question are:
#7AB #7BB #7CB #7DB #7EB #7FB
pg. 5
Unit 2 Chapter 1 Review
pg. 6
Unit 2 Chapter 1 Review
pg. 7
Unit 2 Chapter 1 Review
pg. 8
Unit 2 Chapter 1 Review
pg. 9
Unit 2 Chapter 1 Review
File
format
name
pg. 10
What type of
information or
data is it?
Compression?
How does it work?
uncompressed,
lossy, lossless
(just a few brief words about the theory behind the encoding or
compression)
Unit 2 Chapter 1 Review
BMP
(bitmap)
image data
uncompressed
bitmap image files are made up of metadata including the
dimensions, the print resolution, the number of colors in the
palette, and the number of bits per pixel. following the
metadata is a table of the actual pixel data.
JPEG
(or JPG)
When compressing a raw image file into a jpeg format, the
algorithm used to do the compression relies on the fact that
humans can perceive differences in brightness better than
differences in color. So, data that represents differences in
color can be thrown out or “lost” in the compression process
without significantly altering the perceived quality to the
human eye. It typically reduces the image size by about a
factor of 10.
WAV
A WAV file can contain compressed data, but the most
common format contains uncompressed data. It uses a
common way of encoding analog audio signals, and the audio
wave is sampled 44,100 times a minute, and each sample
takes 16-bits to store.
PNG
A PNG file contains an 8-byte signature at the beginning that
communicates, among other things, the fact that it is a PNG
file. After that, there are a series of 16-byte chunks of data
that communicate things like the image’s width, height, bit
depth, the actual image data itself, and the end of the image.
MP3
The MP3 file format typically compresses an original audio
file by a factor of about 10 times. Similar to the JPEG file
format, the MP3 compression algorithm relies on the limits of
human perception, and in particular, on the fact that there is
audio that is imperceptible to the human ear. For that range of
audio, the algorithm can throw out those samples without
significantly altering the quality.
image data
audio data
image data
lossy
uncompressed
lossless
audio data
lossy
image data
lossless
multiple files,
folders
lossless
GIF
ZIP
pg. 11
The GIF file format starts with a fixed-size header that
conveys that the file is in GIF format (and what version), and
is followed by the image data. The GIF format supports
representing pixels with a max 8-bits, so can only show up to
256 colors. This is why GIF is less preferable for comparing
photographs. GIF can also support multiple images in
sequence to make an animated GIF.
Most similar to what students did in the Text Compression
widget, a ZIP file includes a dictionary and a compressed file
Unit 2 Chapter 1 Review
When do you choose to use the heuristic approach to solving a problem?
When the problem can not be solved in a reasonable amount of time and an
approximate answer is acceptable
pg. 12
Download