Presentation is loading. Please wait.

Presentation is loading. Please wait.

Test 2 on Wed, 11/9 On image processing

Similar presentations


Presentation on theme: "Test 2 on Wed, 11/9 On image processing"— Presentation transcript:

1 Test 2 on Wed, 11/9 On image processing
Allowed to use JES to test your code, but discouraged Last day to withdraw with W: 11/15

2 Pixels and Pictures Pixels are picture elements
Each pixel has colors from (0,0,0) to (255,255,255) pixel = picture.getPixel(x,y) color = makeColor(r,g,b) pixel.setColor(color) A picture is a matrix of pixels Columns (x coordinate) from 0 to width-1 Rows (y coordinate) from 0 to height-1

3 Picture Functions ppp =makePicture(pickAFile())
ppp.getWidth(), ppp.getHeight() xxx=ppp.getPixel( , ) xxx.getColor(), .getRed(), .getGreen(), .getBlue() xxx.setColor(), .setRed(), .setGreen(), .setBlue() makeColor(), pickAColor()

4 Image Processing Draw a line
Paint pixels to red Picture negative (Paint pixels to complements) Get r,g,b of a pixel, repaint it with (255-r, 255-g, 255-b) Picture gray scale Get r,g,b of a pixel, bw = int((r+g+b)/3), repaint it with (bw,bw,bw) Sunset, posterize Pixels are organized in a grid

5 Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
get R,G,B values of the pixel compute the average set R,G,B values of the pixel to the average return def picBW(pic): get the width of pic, and name it get the height of pic, and name it for every y coordinate: for every pixel in the row at the given row y: call pixBW(pixxx)

6 Gray Scale picture def pixBW(pixel): # given a pixel, change to BW
r=pixel.getRed() # get R,G,B values of the pixel g = pixel.getGreen() b = pixel.getBlue() avg = int((r+g+b)/3) # compute the average bw= makeColor(avg, avg, avg) pixel.setColor(bw) # set R,G,B values to the average return def picBW(pic): wid = pic.getWidth() # get the width of pic, and name it hgt = pic.getHeight() #get the height of pic, and name it for y in range(hgt): # for every y coordinate: for x in range(wid): # for every pixel in the row pixBW(pic.getPixel(x,y)) # call pixBW(pixxx)

7 Additional Picture Functions
setMediaPath() – fix a path to media files getMediaPath(filename) file = makeEmptyPicture(100,100) – creates a blank picture of size 100x100 writePictureTo(file, getMediaPath()+“\newpic.jpg”) – save file with name “100x100.jpg” canvas=makePicture(getMediaPath(“newpic.jpg”))

8 Picture Copy copy.py with Two pictures
‘pictA’ to copy to ‘pictB’ (pictB has to larger than pictA) def picCopy(fromPic, toPic): # for every pixel in fromPic, copy its colors to the same pixel location in the toPic def main(): setMediaPath() picA = makePicture(getMediaPath(“ “) # get the width of picA # get the height of picA # create an empty picture, called picB, with the same dimension picCopy(picA, picB) repaint(pictB)

9 Picture Copy copy.py with Two pictures
‘pictA’ to copy to ‘pictB’ (pictB has to larger than pictA) def picCopy(fromPic, toPic): hgt = fromPic.getHeight() wid = fromPic.getWidth() for y in range(hgt): for x in range(wid): pixF = fromPic.getPixel(x,y) col = pixF.getColor() pixT = toPic.getPixel(x,y) pixT.setColor(col) return def main(): setMediaPath() picA = makePicture(getMediaPath(“ “) hgt = fromPic.getHeight() wid = fromPic.getWidth() # create a picture in same dimension picB = makeEmptyPicture(wid, hgt) picCopy(picA, picB) repaint(pictB)

10 Copy flower1 to lower left corner
sourceX sourceY flower1 targetX = sourceX targetY = sourceY + ? ? : getHeight(canvas) – getHeight(flower1)

11 Copy flower2 targetX = sourceX + getWidth(flower1)
sourceY flower2 flower1 targetX = sourceX + getWidth(flower1) targetY = sourceY + ? ? : getHeight(canvas) – getHeight(flower2)

12 Lab_1104 Modify picCopy() so that it has four arguments:
picCopy(fromPic, toPic, toX, toY) where toX and toY are coordinates in toPic from where pixels in fromPic have to be copied over Create a large empty picture, called ‘canvas’ Copy flower1.jpg to canvas, and flower2.jpg to canvas next to flower1.jpg updated copy.py to

13 Edge detection Pixel is different from its neighbors => an edge
Measure (criterion) of pixel differences ? One possibility – compare B/W value of a pixel with those at the left and below If differences are above threshold, then an edge (black), otherwise (white) For each pixel in picture1: get B/W values of the pixel, its left and below (how?) if differences of (pixel, left) and (pixel, below) > Threshold paint the pixel black otherwise, paint the pixel white


Download ppt "Test 2 on Wed, 11/9 On image processing"

Similar presentations


Ads by Google