### Class Announcements

We've posted information about the diagnostic and some practice material on this handout. Please make sure to have downloaded and installed BlueBook, our exam platform.

Q: Will the diagnostic start at 1:30 pm on Monday and end at 2:20 pm the same day?

A1:  Yep

Q: What does while True do? Is it an infinite loop?

A1:  Yep! You need ‘break’ to end it

Q: My TA told us about global variables and how to use it, and so I used it in the last assignment. I also checked this programing in LAIR hours. Will I get downgraded?

A1:  Shoot me an email

Q: In any function, should we only be returning one variable?

A1:  One or none

Q: why do you have to have parameter balance in the deposit function? wouldn't the code work with only amount?

A1:  Looks like you figured it out yourself!

Q: So we use “while true” if we want to keep repeating somehting but don’t have a specific condition we want to test?

A1:  Yes! Or you want to do some work inside the loop before you check the condition, in which case you break inside the loop

Q: What is the difference between a constant and variable? More specifically with regards to the interest problem, was the original input a constant or variable since it can change with each program run but within a single run, they are a constant number used.

A1:  A constant is just a kind of variable - stylistically, it’s defined outside of any function in ALL_CAPS and shouldn’t be changed. In your specific example, the value of any constant should be known *before* the program is run.

Q: Is it ok for sentinel values to break loops to be set globally?

A1:  Constants can be set globally, yeah

Q: what is the range of color intensity?

A1:  0-255

Q: 255 is for 8 bit, can python calculate for 16-bit?

A1:  Pretty much every device uses 8 bits (except some really fancy screens), so colors are represented in 8 bits.

A1:  All 3 intensities are 0

Q: is it the inverse of white?

A1:  Yep!

Q: the entire range of vary is from 0, to 255 for the three colors, right?

A1:  Yes, for each of the 3 colors

Q: If another ocmbination has the same ratio but different numbers, how does it change the pixel. Like will Red: 6/250 Green: 1 Blue 7/250 be the same as the first pixel we were shown?

A1:  Nope - the pixel will be darker if the numbers are less, even if the ratios are the same

Q: Will Assignment 3 serve as review for the diagnostic or is it solely on Imaging? Do you anticipate to upload it today?

A1:  It’ll be uploaded this weekend or Monday, but the material won’t be on the diagnostic

A1:  Nope, just once

Q: Do we have to re-install Pillow everytime we re-start the terminal/pycharm?

A1:  Nope, just once!

Q: “WARNING: You are using pip version 19.2.3, however version 20.0.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command.” Should I do as instructed by pycharm? will that break down anything?

A1:  You can, but you don’t need to worry about that message

Q: Got a warning that I have pip version 19.2.3 and not 20.0.2 is that ok?

A1:  Totally fine

Q: whats the difference between import simpleimage and from simpleimage import simpleimage?

Q: Does the file need to be in the same directory?

A1:  Yep

Q: For my_image.show() is that in the terminal or in the program?

A1:  In the program

Q: how do we define pixel to use in the loop?

Q: Do you need to previously define pixel?

Q: how does python determine what dimension to go across in the loop? How does it differ for RGB versus other kinds of images?

A1:  row by row, and it doesn’t matter what kind of image it is

Q: Do we have to import the image into python first, or specify a link like to the desktop etc. ? For the “xx.jpg” part

A1:  The image should be in the same folder as the python file

Q: can you just access the pixel data of the image and run a regular for loop on that collection?

A1:  What do you mean?

Q: could you write an if statement within the for loop that affects pixels with only certain RGB values?

A1:  Yes!

Q: so python just automatically knows pixel in “For pixel in image”? can we replace pixel with something else?

Q: In what order does it modify the pixels?

A1:  row by row

Q: It goes through the pixels vertically before horizontally?

A1:  row by row

Q: does the loop go through all (x,0) and then move through (x,1) or does it go down y first?

A1:  row by row

Q: is "pixel" already defined in python ?

Q: How do we choose which pixel?

A1:  You get the pixel from the for loop

Q: do functions that mess with image files pass by value?

A1:  Which functions are you talking about?

Q: When you change the pixel color, does it change the original file or a copy?

A1:  The original pixel

Q: for images we don’t use a main function?

A1:  You do

Q: Isn't this an infinite loop? When does "for each" stop?

A1:  After the last pixel

Q: coul //=. still be used as a shortcut here?

A1:  Yep

Q: Isn’t // integer division

A1:  Yes, intensities should be ints

Q: and then put the .show? to display

A1:  Yes

Q: are RGB values always integers?

A1:  Yes

Q: What does return image do?

A1:  Check out the last few lectures

Q: Just wondering why the RGB values are on a scale betwen 0 and 255? 255 seems arbitrary is there a specific reason why it’s that number?

A1:  Good question! It’s the number of colors that can be represented in a single byte. stop by OH or Ed for more details!

Q: Is integer division used because RGB values can only be whole numbers?

A1:  Yes!

Q: So do we still use main() or we can just use red_channel as our “main” function?

A1:  Use main

Q: does returning an image after modifying it mean the original doesn;t exist anymmore or is the retuned mage a copy?

A1:  You’re returning the luggage tag of the image, so the image is the same one

Q: if r g and b were 0 would it be black?

A1:  Yep

Q: can you answer this question again: is "pixel" already defined in python ? (missed it when it was addressed live)

A1:  No, it’s just like the i in a for i in range loop

Q: Is there a reason red_channel is taking in the filename instead of a variable that’s already been assigned the filename through SimpleImage?

A1:  The red_channel function will make a SImpleImage from the filename

Q: Does returning the image show it or does thee have to be a show statement?

A1:  There has to be a show statement

Q: What order does the for each loop grab the pixels? Like from top-left going right across a row and then down to next row?

A1:  row by row

Q: so all photos must first be downloaded into python they cannot search your computer drive directly

A1:  They just need to be in the same folder as your Python file

Q: Can I put original_flower in when I call the function instead of the filename, since the file was assigned to it?

A1:  Can you clarify what you mean?

Q: does red channel do the pixel switch for the original flower or of the grey flower

A1:  It depends on which file you’re passing in

Q: is there a reason why mehran divided with // as opposed to /? do we need to do integer division for pixels or can we do float division too

A1:  RGB values should be ints

Q: so “red_channel” and “darker” are function already built in pyhton?

A1:  Nope

Q: If you had red, green and blue all equal 0, would you get black?

A1:  Yep

Q: Are the changes made to the pixels due to the functions permanent?

A1:  Yes

Q: is it necessary to return image when you could simply show image after manipulating it?

A1:  It depends on what you want to do with it afterwards

Q: if you wrote a brighter() function and multiplied the intensities (say by 2) and it resulted in an R,G, or B intensity value of greater than 255, does Python throw an error or just set it to 255?

A1:  It’ll set it to 255

Q: Is the decision to use green (instead of red or blue) for green screens arbitrary?

A1:  Yep! It’s mostly because neon green is slightly less common a color than red or blue

Q: why are we doing integer division each time instead of regular division? Is there a benefit of getting a whole number?

A1:  RGB values should be ints

Q: What does intensity threshhold mean?

A1:  It’s basically a measure of how green a pixel needs to be in order to be considered green

Q: do the images have to be the same size

Q: what if our images are diff sizes and have diff amounts of pixels?

Q: I'm guessing greenscreening requires your main_files and back_files must be the same size. Do you need to write a program to resize images, then? Also, are there equivalent programs that work with vectors instead of pixels?

A2:  Can you clarify what you mean by working with vectors?

Q: do you know why greenscreening is so much more widly used?

A1:  I think it’s just because bright green is a less common color than blue or red, so you don’t accidentally replace pixels you don’t want to!

Q: Is there a reason it’s usually a greenscreen and not a bluescreen or redscreen?

A1:  I think it’s just because bright green is a less common color than blue or red, so you don’t accidentally replace pixels you don’t want to!

Q: can you go over the image.set_pixel and the back.get_pixel a bit more in depth? I am confused where those variables come from are they built in or do we make them?

A1:  image and back are loaded in from filenames: we then call set and get pixel to take pixels from back and put them in image

Q: Rather than putting the filename in as my argument when I call the function, can I write in the variable I had assigned my image to as my argument?

A1:  Sure

Q: apologies if this is too basic but what is the utility of the return command again then?

A1:  Check out the last couple of lectures - it allows a function to give back an image to the function that calls it

Q: Do images have to be the same dimensions to be replaced with one another?

Q: I am a little confused on how image.set_pixel is working

A1:  It takes in a coordinate (x, y) and a pixel, and puts that pixel at that coordinate

Q: Then why did Mehran say // cuts it in half? Does it depend if if it divides perfectly

A1:  Yep - //2 is close enough to cutting in half that we just can say that

Q: can you clarify if background is the screen and the front image is the one you’re drawing pixels from?

A1:  front is the one with the green screen

Q: Is get.pixel pre-defined?

A1:  Yep

Q: is it “x” and “y” because of pycharm recognize the coordinates of the image?

A1:  No, those are just good variable names

Q: If I have an image with only black and white pixels, is there a way for me to find the pixels that touch both black and white pixels? If the image had a bunch of white circles on a black background for example, this would ideally find the border pixels of the white circles.

A1:  Yes! Once you have a coordinate, you can calculate the coordinates of the neighbouring pixels and do whatever you want with them

Q: Why do you need both x and y for loops? Why can’t you just have one loop?

A1:  You need one loop for x coordinates and one loop for y coordinates

Q: Are nested loops the only way to select all pixels?

A1:  If you want their coordinates, yes

Q: does the for y have to come before the for x or are they interchangable

A1:  This is the conventional order, but it generally doesn’t matter

Q: What’s the pixel referring to/What’s it’s function in (x,y,pixel)?

A1:  It’s a pixel object we got from the left half of the image

Q: wait if it was a for x in range (width), why did the next set of coordinates become (0,1) instead of (1,0)?

Q: When x=50, will the two images overlap?

Q: how would you then save the image you get to your computer?

A1:  You can save it once it pops up on your computer

Q: Why do you add +1?

Q: how to export the images created?

A1:  You can save it once it pops up on your computer

Q: can you make the same mirrored image but without the original?

A1:  Yes! Try and think about how :)

Q: Why do you put the def main(): below the functions in the main?? Shouldn’t they be in front?

A1:  Either is fine

Q: it doesn’t change the flow?

A1:  Nope - Python makes a list of all the functions before starting to run main

Q: is pixel a variable? do I have to define what pixel is in my code?

A1:  It is a variable! no you dont have to define it.

Q: with the burrito mirror example, so when the blank image is added besides the original image, the original image is still referred to as "image" and the blank image added beside it is still referred to as "blank" in the code?

Q: What are the logistics for the diagnostic? Where are we taking it? How? Is there somewhere on the website that has this info?

Q: how does python know what pixel is?

A2:  how does python know what pixel is?

Q: Why do you use (x+1)?

Q: Sorry could you clarify pixel in (x,y,pixel) live again?

Q: How do you recommend us to study for the diagnostic?

A1:  Strategies are discussed in the handout!

Q: in the example, in the for x in range loops, why did it become (0,1) instead of (1,0)?

Q: I was really confused with the reflection of the burrito. What was the mirror.image you used in the bottom part of the code?

Q: re: prev question on Vectors for Brahm, defining an image with a scalable set of vectors as opposed to using pixels.

A1:  I’m not 100% certain I’m catching your drift - I have office hours in 5 minutes so we can chat about it there

Q: I sent an email but it might be easier for you all to answer now, but is it still possible to sign up for CS 100?

A1:  ok we will check when we get the email

Q: when mehran changed the red sauce in the burrito to leaves, did it matter which pixels from the leaves were put into the burrito? is it possible to put only pixels from a specific area of one image into a specific area of another image?

A1:  that is possible! He used “pixels are red” as his condition. But you could certainly use other conditions!

Q: Like I thought mirror was a variable

Q: If we are only returning one variable at a time, and not using global variables, it seems that the main function risks getting rather large. Is it acceptable for the main function to be larger in order to avoid using other techniques for passing variables?

A1:  its ok while you are getting started — but we strongly recommend you get used to parameters, returns, and start using them to write elegant code

Q: Can python handle videos as collections of images?

A1:  oh yea! That is the advanced version

Q: How does y know to move down rows once one y row is finished?

A1:  thats how range works. It gives you values one at a time, increasing by one each time

Q: If we want to change a specific part of an image, instead of a specific color; for example just the “T” on the STOP sign how do we “see” the full range of the pixels so we know what pixels the part of the image we want to change are?

Q: By “set pixel value” you mean the RGB information?

A1:  yes!

Q: Could you have done mirror = SimpleImage.blank mirror.width = width*2 mirror.height = height?

A1:  i dont believe this works, but you should try it and let us know if it does work!

Q: Where are we returning mirror to?

A1:  who ever called mirror_image! In this case the main function

Q: Is RGB and x y coordinates the only way to define specific pixels? I’m just thinking how you can lasso something using code