Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Fall 2006 Homework 1 Questions

Questions?

How do we write the absolute value function? is it abs() something like that? should it be a different color?

how do we turn in our homework? printed out? on a flash drive? email?
Through webwork. You'll need to register and create an account (it's free). This is where grades will be posted as well. Your TAs should go over how to turn stuff in and do a walk through in your next recitation. -poof #10

the assignment doesn't say it is necessary, but can we insert code that will display the picture before and after posterization?
It would be best to leave that out and only use it while you are writing the code for the assignment. -Albert d'Heurle

You can certainly TEST your program with showing before and after, but remove those lines before turning it in. Think about the TA testing 25 programs – she really doesn't want 50 pictures opening up when she's trying to test them in a big batch. Mark Guzdial

I'm having problem on writing the command for the first bullet point-can we use "if/else"? and the returned new green value in the picture turns out to be 0 and not 255.
Yes, you can use if/else Toni Walden

I have an error that says my code contains at least 1 syntax error, meaning it is not legal jython. the code is for p in getPixels(picture). i've tried writing it differently and rewriting it but i can't figure out what exactly is wrong with it. Help! Thanks- Katie Gallagher
It's difficult without seeing all of your code. Do you have semicolons after getPixels(picture)? If not, that's your error. See a TA at office hours or online for more specific help. Amanda Bennett

it seems like picture and pic are interchanged in the HW instructions. in the hint is says posterizeMe(picture) then it says the ta will be using pic = makePicture(file)
Does it matter? can we say... def posterizeMe(pic) ?
thanks!
You can use any word there. You can call it banana if you'd like. It is just a variable. But everytime you want to refer to the input, you need to use the same word. -poof #10

Can we test our program on old submitted photos for homework 1?
I believe if the code is written correctly, then a previously posterized picture run through our program, would remain the same, right? I hope this makes sense.
No. Posterize takes the average of the colors that surround the pixel. It would just posterize it even more. -poof #10

if(green<100):
      setRed(p, green) and setGreen(p, red)


Is this what's causing me problems? When my red is pure red, it doesn't change at all. Help!
First of all, i'd be careful using the word 'and' in my code (particularly when you aren't using it as part of the if statement). Second, if possible, I wouldn't use "green" and "red" as variable names in JES, simply because they're already defined. Third, should your picture change if red is pure red with this statement (what would the value of the green value be if only red were in your picture)? Keep thinking. You're getting there Amanda Bennett

is the picture supposed to turn out almost completely green?
Trace through your code and see if you made a mistake. You can also look on the homework gallery to see how other people's picture turned out. Amanda Bennett

I have an error that says my code contains at least 1 syntax error, meaning it is not legal jython. the code is for p in getPixels(picture). i've tried writing it differently and rewriting it but i can't figure out what exactly is wrong with it.

for p in getPixels(picture):
That line of code is correct (assuming you've defined picture as your input). What does the code look like before this point? Check over all of your code to find the error. Amanda Bennett
Make sure it's indented correctly. -poof #10


uhm.I have no clue about the absolute value. where can I find how to do it?
>>> abs(65)
65
>>> abs(-65)
65
- Bobby Mathew|

oh my goodness! thank you so much, I've been working FOREVER! and couldnt figure it out!

oh...wait...
how shoudl I do that with color..I guess that was the major problem?
Absolute value works with numbers. What gives you a number when dealing with pixels? If you subtract 2 color values, you still have a value, correct? We just don't want that value to be negative, so you put it inside of the abs function. Amanda Bennett

Before making any changes to the picture, should I getPixels and then proceed??? or it is not necessary??
Perhaps I am misunderstanding your question, but it is impossible to change a picture without changing its pixels, and to change the pixels you need to get at them. Have a look at a few examples from the slides and book to remind yourself how this is done. It's basic to all the picture manipulations you will be doing, so you need to master these ideas. Colin Potts

# If the original blue value is less than or equal to 109, set the new red value to the absolute value (hint: function abs) of the original green value minus the original red value.


how do I do this then?
try taking it a piece at a time. Make sure you have the orignal color values saved as variables. Write the if statement, and then just do setRed like you normally would but instead of setting it to a number set it to the absolute value of original green-original red, hope that helps -Ally Chase

yes! I think that worked! thank you sooooo much! Should it have alot of red in it though? mine only looks like the bottom picture in the ones other people posted, it isn't green like the rest. Am I wrong?
There is no way for us to tell you if your code is creating the correct picture without physically looking at it. If you are unsure, I would suggest taking your homework to a TA and have them look over it. Just because you see a picture posted doesn't necessarily mean that it is correct. -poof #10

why am i getting a syntax error for this line? "if originalRed >=100:" the line before defines is "originalRed=getRed(p)"
"charlie blackmon"
There doesn't seem anything obvious wrong with either of these two lines so I can't help you right now. It's possible that your indentation is wrong, that you misspelled something (possible if you retyped the lines above correctly rather than cutting and pasting them from JES), or that there is an error on the previous line that is confusing JES into locating the error on the (correct) line below it. There's really no such thing as "an" error message. There are lots of types of error messages. The text of the message may tell you more than you realize. What does it say? Colin Potts. BTW, Charlie, you put your name in asterisks as though you had a who's who page, but you haven't created one for yourself yet.

After I run my program on a picture and open up the media tools to compare individual pixels (to make sure it is right), the numbers I get are slightly off. For example, I get (240,225,110) when I should be getting (241,255,109), or I get (3,68,60) when I should get (9,66,58). I know I did not type the numbers in wrong in my program. What is going on?
Strange. Your numbers are off by small amounts but the discrepancies aren't systematic. This suggests to me that you're probably looking at pixels adjacent to the ones that you set. Actual pixel indices go from 0, but the pixel numbers in getX and getY go from 1. You may think that you're looking at the pixel at (30,30) when you're really looking at the one at (31, 31). It's confusing if you use both methods to access pixels. (Disclaimer: I may be completely wrong about the pixel addressing scheme in MediaTools, and I try not to use it.) Try printing out the value of getPixel(pic, x+1, y+1) and see if that coincides with the value that MediaTools is giving you for (x, y). In any event, getPixel(pic, x, y) should return the correct value – the value that you set. If it doesn't, then there really is something wrong with your program. Colin Potts
I noticed the same thing using getPixel and MediaTools. getPixel(pic,30,30) returns the same info as (29,29) in MediaTools. -Tom Sulkowski

why was my extra credit picture taken down? my name was correct and everything rmohtadi3
Somebody may have accidentally overwritten the link to your file when they added their own. I've put the link back at the end of the page. BTW well done with the series completion puzzle last week. Colin Potts

I can't get my extra credit to work. I loaded my writePictureTo part on jes and it worked. when i am trying to call the function though it says An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer. what am i doing wrong?
I assume that the function generating the error message is writePictureTo() (although, I don't understand in that case what it is that is working in JES, but anyway....) Make sure that you are calling writePictureTo() with two arguments. The first is the picture; the second is a string that represents the path to the file you are writing the picture to. If you get these two in the wrong order you will get this error message. Colin Potts

I am having a problem with the absolute value function line and am hoping somebody can help me out. I currently have it as setRed (abs (g-r)) - can someone please let me know what I am doing wrong? Thanks!
setRed() takes two inputs. The first is a pixel and the second is a number. You are only supplying the number. -poof #10

i cannot find 'attatch' in extra crediit posting site.
If you are trying to post your picture for the extra credit, just go here. Make sure that your file is named according to your prismID or your TA won't be able to find it. Examples: gtg561q.jpg or cholder3.jpg -poof #10

my extra credit is still saying An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer. i am calling writePictureTo(picture, then file). why is it still not working?
Please supply the line of code that is giving you the error or come by my office hours from 5PM-6PM in the library and/or 6PM-7PM in Skiles 318 (the library closes at 6 on Friday's so I have to leave) -poof #10


posterizeMe() is not calling the picture
It should be posterizeMe(picture). The picture should be passed in as a parameter. - Bobby Mathew

this is still not working
Make sure the first line of your function is
def posterizeMe(picture)
. Then in your code, you shouldn't have anything like pickAFile() or makePicture() etc. When you run it, type the commands under the 'How the TA will grade part' and it should work. If its still not working, email a TA. - Bobby Mathew

do i submit this as hw1.py or do i need to put my name in the filename.
Everything you need to know about naming the file is on this page. -poof #10

I don't understand the "passing a parameter into a function" question. Does this just mean that we test to see if something is true before making changes to the picture?
No. Parameters are explained on pages 32-33 of the textbook. Colin Potts

agreed ^^^^ i m drawing big blanks on that question.
An example of parameter passing is show(pic). The function show() takes ONE parameter/input, a picture. You put the parameters inside the ()'s. iF there are multiple parameters you seperate them by commas. You should be using parameters all the time. getPixels(pic), getRed(px), and posterizeMe(pic), all take in parameters. If a function needs input or a parameter, that means that something else is supplying the data that it's going to work with. -poof #10

is it okay to use 3 for loops in this homework?
If you would like to then you can as long as your homework does all of the correct color value checks and the end result is correct. But it is a lot simpler than using 3 for loops. -poof #10

When I added return(pic) at the end of my function it wont run. Also, do we put # in front of our answers to the questions at the bottom? - Meghan Lukken
Make sure that return in not inside your for loop. When JES gets to the word 'return' it exits the function. -poof #10

I uploaded my picture to the hw1 page, but my picture is not showing up. My gtg is showing up in the list of uploaded files. Is this a problem??
Maybe, personally, I don't look at the pictures, I grab the HTML and searrch for gtg numbers. But if you really want it to show up, make sure it's in the correct format. Look at a few of the other linked pictures. If it still won't show up, I would just send your TA an email. And make sure they can see that you tried to post it BEFORE the homework is due. -poof #10


Uploaded Image: qzhang3.JPG