CS1315: Prologue to Media Calculation.


114 views
Uploaded on:
Description
CS1315: Prologue to Media Calculation Changing pictures by record number Moving pixels crosswise over pictures We've seen utilizing list variables to track the pixel position we're working with in a photo. We can duplicate between pictures, on the off chance that we monitor: The source file variables
Transcripts
Slide 1

CS1315: Introduction to Media Computation Transforming pictures by list number

Slide 2

Moving pixels crosswise over pictures We’ve seen utilizing file variables to track the pixel position we’re working with in a photo. We can duplicate between pictures, on the off chance that we stay informed regarding: The source list variables Where we’re getting the pixels from The objective record variables Where we’re putting the pixels at (Not generally replicating the pixels: Replicating their shading.)

Slide 3

What would you be able to do then? What would you be able to do when duplicating starting with one picture then onto the next? Compositions: Copy a few pictures onto one Cropping: You don’t need to take the entire picture Scaling: Make a photo littler, or bigger when duplicating it

Slide 4

Some Utility Functions If you know the record\'s name, hunting down it with pickAFile() feels dreary You can set and get a media envelope ( way ) for recalling a spot where your media will be originating from (or going to) setMediaPath() gives you a chance to pick a record in your media organizer getMediaPath(basefilename) gives you a chance to create a complete filename out of just the last part

Slide 5

Example >>> setMediaPath() New media organizer: C:\Documents and Settings\Mark Guzdial\My Documents\mediasources\ >>> getMediaPath("barbara.jpg") \'C:\\Documents and Settings\\Mark Guzdial\\My Documents\\mediasources\\barbara.jpg\' >>> barb=makePicture(getMediaPath("barbara.jpg"))

Slide 6

Blank documents in mediasources getMediaPath(“7inX95in.jpg”) gives you a JPEG canvas which prints out as 7x9.5 inches Letter-sized page with 1 inch edges getMediaPath(“640x480.jpg”) gives a JPEG canvas at a typical size: 640 pixels crosswise over by 480 pixels high

Slide 7

Copying pixels as a rule, what we need to do is to stay informed regarding a sourceX and sourceY, and a targetX and targetY. We augmentation (add to them) in sets sourceX and targetX get increased together sourceY and targetY get increased together The dubious parts are: Setting qualities inside the assemblage of circles Incrementing at the base of circles

Slide 8

Copying Barb to a canvas def copyBarb(): # Set up the source and target pictures barbf=getMediaPath("barbara.jpg") point = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the genuine replicating targetX = 1 for sourceX in range(1,getWidth(barb)): targetY = 1 for sourceY in range(1,getHeight(barb)): shading = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), shading) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas

Slide 9

Comments Python disregards from “#” through whatever is left of the line If you begin a line with “#”, the entire line is overlooked Why do we need lines to be disregarded? To have the capacity to leave notes to ourselves or another person about how the project functions

Slide 10

Walking through the replicating capacity First, get the source (spike) and target (canvas) records and pictures as names we can utilize later. def copyBarb(): # Set up the source and target pictures barbf=getMediaPath("barbara.jpg") spike = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the genuine duplicating targetX = 1 for sourceX in range(1,getWidth(barb)): targetY = 1 for sourceY in range(1,getHeight(barb)): shading = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), shading) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas

Slide 11

The real duplicate def copyBarb(): # Set up the source and target pictures barbf=getMediaPath("barbara.jpg") thorn = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the real replicating targetX = 1 for sourceX in range(1,getWidth(barb)): targetY = 1 for sourceY in range(1,getHeight(barb)): shading = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), shading) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas We get the pixel\'s shade at sourceX and sourceY We set (duplicate) the shading to the pixel in the objective picture at targetX and targetY

Slide 12

Setting up the duplicate circle def copyBarb(): # Set up the source and target pictures barbf=getMediaPath("barbara.jpg") point = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the real duplicating targetX = 1 for sourceX in range(1,getWidth(barb)): targetY = 1 for sourceY in range(1,getHeight(barb)): shading = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), shading) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas targetX gets set to 1 toward the starting sourceX will go over the source\'s width picture INSIDE the circle, we set targetY to 1 Inside on the grounds that we need it to begin at 1 every time we do another X sourceY will go from 1 to tallness of source

Slide 13

Ending the circle def copyBarb(): # Set up the source and target pictures barbf=getMediaPath("barbara.jpg") spike = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the real duplicating targetX = 1 for sourceX in range(1,getWidth(barb)): targetY = 1 for sourceY in range(1,getHeight(barb)): shading = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), shading) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas Just before we end the sourceY circle, we augment targetY It’s now set up for whenever through the circle It’s set accurately for the following estimation of sourceY Just before we end the sourceX circle, we increase the targetX Note deliberately the space to make sense of which runs with which circle

Slide 14

What’s this naming something to itself? targetX = targetX + 1 This isn’t truly naming something as itself targetX + 1 is assessed It will bring about the number after targetX = then sets the estimation of targetX The outcome is that targetX gets augmented by 1

Slide 15

Ending the duplicate capacity def copyBarb(): # Set up the source and target pictures barbf=getMediaPath("barbara.jpg") point = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the genuine replicating targetX = 1 for sourceX in range(1,getWidth(barb)): targetY = 1 for sourceY in range(1,getHeight(barb)): shading = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), shading) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas At the very end, we demonstrate the source and target And return the altered target.

Slide 16

Works whichever way def copyBarb2(): # Set up the source and target pictures barbf=getMediaPath("barbara.jpg") thorn = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the genuine duplicating sourceX = 1 for targetX in range(1,getWidth(barb)): sourceY = 1 for targetY in range(1,getHeight(barb)): shading = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), shading) sourceY = sourceY + 1 sourceX = sourceX + 1 show(barb) show(canvas) return canvas the length of we addition sourceX and targetX together, and sourceY and targetY together, it doesn’t matter which is in the for circle and which is increased by means of expression

Slide 17

Transformation = Small changes in replicating Making generally little changes in this fundamental duplicating project can make an assortment of changes. Change the targetX and targetY, and you duplicate wherever you need Cropping: Change the sourceX and sourceY extent, and you duplicate just piece of the system. Pivoting: Swap targetX and targetY, and you wind up duplicating sideways Scaling: Change the addition on sourceX and sourceY, and you either develop or shrink the picture.

Slide 18

Copying into the canvas\' center def copyBarbMidway(): # Set up the source and target pictures barbf=getMediaPath("barbara.jpg") point = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf) # Now, do the genuine replicating targetX = 100 for sourceX in range(1,getWidth(barb)): targetY = 100 for sourceY in range(1,getHeight(barb)): shading = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), shading) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas

Slide 19

Copying: How it lives up to expectations Here’s the beginning setup:

Slide 20

Copying: How it meets expectations 2 After increasing the sourceY and targetY once (whether in the for or by means of expression):

Slide 21

Copying: How it lives up to expectations 3 After yet another addition of sourceY and targetY: When we complete that segment, we augment sourceX and targetX, and begin on the following segment.

Slide 22

Copying: How it takes a gander toward the end Eventually, we duplicate each pixel

Slide 23

Making a collection Could we do something to the photos we duplicate in? Without a doubt! Could either apply one of those capacities before duplicating, or do something to the pixels amid the duplicate. Would we be able to duplicate more than one picture! Obviously! Make a composition!

Slide 24

#Third picture, flower1 discredited negative(flower1) targetX=200 for sourceX in range(1,getWidth(flower1)): targetY=getHei

Recommended
View more...