1 Ethics of Computing MONT 113G, Spring 2012 Session 11 Graphics on the Web Limits of Computer...

22
1 Ethics of Computing MONT 113G, Spring 2012 Session 11 Graphics on the Web Limits of Computer Science

Transcript of 1 Ethics of Computing MONT 113G, Spring 2012 Session 11 Graphics on the Web Limits of Computer...

1

Ethics of Computing MONT 113G, Spring 2012

Session 11Graphics on the Web

Limits of Computer Science

2

What is a Graphics file?

moon.gif

GIF89a¶ˇÃˇˇôˇˇfˇˇ3ˇˇÊøß5뢑Zµ´T¨Yß6;≥ YØh7^„ŸMöù;r-€êπÑ+˜`À≥t€Ω´w!PÅ|≈Bå[8∞cƒw€ée‹±/‚ƒç?Ã6≥C ߬=<∞f™ú¡z.kyÊ^“°O”uJÿÙ^≥d%äîÕr‰êäC~Àÿvo¥©U

moon.gif ?

3

Storage of Graphic Images

• Graphics are stored as 1's and 0's on the disk.

• The numbers form a code that the browser interprets to display the graphic on the monitor.

• Computer displays are composed of many dots, known as picture elements (pixels).

• The numeric code in an image file specifies the color of each pixel in the image.

4

Resolution

•The number of pixels on the screen determines the resolution of the image.

•More pixels per inch implies better resolution and better image quality.

•Older PC's had resolutions of 800 pixels x 600 pixels. Older Macs had resolutions of 640 pixels x 480 pixels.

•Newer PC's and Macs have much higher resolutions (e.g. 1152 x 768).

5

Resolution affects Image Size•The more pixels there are per inch (ppi) the smaller each pixel is.

•Image sizes are specified in terms of pixels. So the same image will appear smaller on a monitor with a higher resolution.

Increasing resolution decreases the image size.

6

Bit Depth

•The number of colors each pixel can assume contributes to image quality.

•The bit depth of an image is the number of bits used to specify color for that image. The bit depth determines how many colors can be shown.

•Black and white monitors have 2 colors. Only one bit is needed to specify color (bit depth = 1).

•A bit depth of n allows representation of 2n colors.

7

Changing Bit Depth

Some images don't need a large bit depth:

Bit depth 8

Bit depth 4 Bit depth 1

Smaller bit depths help to keep the file size (in kb or mb) small.This makes it faster to download the image file.

8

Bit Depth and Image Quality

For more complex images, higher bit depth leads to better resolution:

Bit depth = 32 (16.7 million colors)

9

Indexed ColorWith indexed color, the computer stores a table of colors (256colors for bit depth of 8). Each pixel is given a value between 0 and 255, which corresponds to one of the colors in the table.

10

RGB (Red, Green, Blue) Color

In the RGB color system, each pixel is given a specified amount of red, green and blue (between 0 and 255).

The color value is written in Hexadecimal, using 2 digits for each color:

#FF0000 Red#00FF00 Green#0000FF Blue#FFFFFF ?#000000 ?

#880066 Purple

11

Image File Compression

Images on the web are stored as separate files that must be downloaded from the server to the client to be viewed.

If the image file size is large, it will take a long time to download. Therefore, it is important to try to keep the file size as small as possible without losing much image quality.

Ways to reduce file size:1. Reduce the size of the image (in pixels)2. Reduce the resolution of the image.3. Reduce the bit depth of the image4. Use image file compression (GIF or JPEG)

12

GIF files

•The Graphics Interchange Format (GIF) is excellent for compressing images with large areas of uniform color.

•It is "lossless", meaning that the original image can be regenerated with no loss of information.

•GIF supports transparency in images.

•GIF supports animations (animated GIF's)

•This format is limited to 256 colors.

13

JPEG compression

•The JPEG (Joint Photographic Experts Group) compression method works well for complex images, such as photographs.

•JPEG supports millions of colors (up to a bit depth of 24).

•JPEG is "lossy", meaning that the original image cannot be regenerated exactly from the original. Some information is lost in the conversion to JPEG.

14

Church-Markov-Turing Hypothesis

The Church-Markov-Turing Thesis:Any non-trivial computer language is apparently capable of computing no more and no fewer functions than all other non-trivial programming languages. So, all languages are equally powerful.

Python is at least as powerful as any other programming language.

Therefore we might think that we can solve any problem with a Python program.

In practice we cannot, because...

15

Limitations of Computer Science

In practice, we cannot solve every problem with a program because...

1) The execution time of a program may be too long.

2) The problem may be non-computable.

3) We may not know how to solve the problem.E.g. Computer Vision

Artificial IntelligenceModeling complex systems such as weatheretc.

16

Execution Time

The execution time of a program can be a limitation in what we can compute.

Examples:

Taxes: How long would it take to sort taxpayers by Social Security number?

Electricity: What is the most efficient routing of power lines through a region or neighborhood?

Tractable problems can be solved in a reasonable amount of time.

Intractable problems require huge amounts of time to solve.

17

A Tractable Problem

Suppose we have a list of patients and an associated list of patient weights.

We want to write a program that prints out the names of patients with weight above a given value.

The names are stored in a list of strings.The weights are stored in a parallel list of real numbers.

Amy Ted Ann Tom

name

1 2 3 4 5 . . . n

115 145 132 224

weight

1 2 3 4 5 . . . n

. . .

. . .

18

The solution and its running time

The program examines each patient in turn.The running time is proportional to the number of patients in the list (n).

n (# patients) time (seconds) 2500 1.275 5000 2.550 7500 3.82510000 5.100

time

n

5.1

10000

Python solution:for i in range(n):

if weight[i] > targetWeight:print name[i]

19

Linear Running time

The graph of the running time of the previous problem is a line.

t = 5.1 x 10-4 n

We say the the running time is linear.

Problems that have linear running times can be solved in a reasonable amount of time. These problems are tractable.

20

Another example

Suppose we want to sort the patients by their weight. I.e. we would like to rearrange the list so that the weights go from lowest to highest.

Many sorting algorithms run as a function of n2. For example:t = 3.2 x 10-3 n2

Others run as a function of n log2 n. For example:t = 2.1 x 10-3 n log2 n

Logarithms: If 2x = n, then log2 n = x23= 8, log2 8 = 3

21

Graphing the running time for a sorting function

# people (n) t (seconds) 2500 59.261 5000 129.021 7500 202.745 10000 279.042

time

n

n

n2

n log n

Sorting a list takes more time than searching a list, but it still can be done in a reasonable amount of time.

22

Polynomial and Polylogarithmic running times

In general, tractable problems are problems that have running times that are a polynomial function of n (the size of the input) or a polylogarithmic function of n.

Examples:

t = 4n3 + 5n2 -3

t = n2(log2(n))3

t = 17 n6 - log2 n + 6n