110 likes | 552 Vues
JyThon : Image Processing. Natapon Pantuwong. Manipulate Pictures. Open image file with JyThon >>> file = pickAFile () >>> print file /user/ guzdial / mediasource /babara.jpg >>> picture = makePicture (file) >>> show(picture) >>> print picture
E N D
JyThon : Image Processing NataponPantuwong
Manipulate Pictures Open image file with JyThon >>> file = pickAFile() >>> print file /user/guzdial/mediasource/babara.jpg >>> picture = makePicture(file) >>> show(picture) >>> print picture Picture, filename/Users/guzdial/mediasources/babara.jpg height 294 width 222
Manipulate Picture >>> print getWidth(picture) >>> print getHeight(picture) >>> pixel = getPixel(picture,1,1) >>> print pixel Pixel, color = color r =168 g=131 b=105 >>> pixel = getPixels(picture) >>> print pixel[0] Pixel, color = color r =168 g=131 b=105
Manipulate Picture >>> print getX(pixel) >>> print getY(pixel) >>> print getRed(pixel) >>> setRed(pixel,255) >>> color = getColor(pixel) >>> print color color r=255,g =131, b=105 >>> newColor = makeColor(0,100,0) >>> setColor(pixel,newColor)
Manipulate Picture >>> print distance(color,newcolor) >>> makeLighter(color) >>> makedarker(color) >>> writePictureTo (picture, “/Users/guzdial/newpicture.jpg”)
Manipulate Picture >>> file = “Users/guzdial/mediasources/katie.jpg” >>> pict = makePicture(file) >>> show(pict) >>> setColor (getPixel(pict,10,100),yellow) >>> setColor (getPixel(pict,10,101),yellow) >>> setColor (getPixel(pict,10,102),yellow) >>> setColor (getPixel(pict,10,103),yellow) >>> setColor (getPixel(pict,10,104),yellow) >>> repaint(pict)
Using Loops in Pictures >>> for pixel in getPixels(picture) value = getRed(pixel) setRed(pixel,value) >>> for pixel in getPixels(picture) value = getRed(pixel) setRed(pixel,value*0.5)
Using Loops in Picture Your Turn!!! Make sun set picture from beach picture. Assume that when sun set, blue and green will be decreased 30%. Negative Image which invert black and white of gray level. Grayscale image which computed by average of red, green and blue of each pixel.
Looping Across the Pixels with range >>> for x in range(1,getWidth(picture)) for y in range(1,getHeight(picture)) pixel = getPixel(picture,x,y) Your Turn!!! Let lighten the picture. Mirror your image vertical or horizontal.
Copying and Transforming Image #Set up the source and target pictures barbf = getMediaPath(“babara.jpg”) barb = makePicture(barbf) canvasf = getMediaPath(“7inx95in.jpg”) canvas = makePicture(canvasf) targetX = 1 for sourceX in range(1,getWidth(barb)): targetY = 1 for sourceY in range(1,getHeight(barb)): color = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY),color) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas)
Copying and Transforming Pictures Your Turn!! Translation with (10,15) Rotate CW 90 degree. Scale up by 2 Scale down by 2 Blurring Sharpening Blue Screen