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 2007 Homework 1 Questions

Questions?

Please remember the following:
  1. Don't post code that essentially solves the problem for other students.
  2. The coweb ignores indentation and does weird things with special characters like greater-than and less-than, so to have any code snippets you post in your questions show up correctly, make sure that you put code tags around your code like this:
<code>
    Your code goes here...
</code>



Are any TA's or someone who can look at my code and give me some advice on why it won't run? I'm getting no debug after if run it on the picture, and the picture looks the same when i repaint it. Please response of contact me so i can show you my entire code in privacy.

I have no clue as to how I make something greater than or equal to
Look up "greater-than-or-equals" in the index of the textbook. Colin Potts

I also dont understand how to swap the red and blue values
Do it in stages: Find out the red and blue values, giving those quantities names. Then set the new blue and red values accordingly. Colin Potts

I tried the program, and no bugs showed up but nothing happened either (the picture stayed the same). Then I rewrote it and I keep getting "spacing errors", even though I've been trying to change that for about half an hour. Any suggestions, maybe?
Check your indentation. Spacing errors often happen when you have a for, if or else that isn't followed by an indented block. Getting the indentation wrong may also have been the reason for the program not working the first time. You may, for example, have been changing the color of only the very last pixel in the picture (which is hard to notice) rather than all of them. Colin Potts

???When I writePictureTo it saves it but it has 0kb. i read on the help site that i have to change the directory to not read only but i dont understand how to do that. and when i change things to not read only they always go back after i hit ok and then look at the properties again. they change back to read only????? Jay Collins
When you use writePictureTo, the 'picture' argument needs to be the variable in the code you used to hold the picture (so likely 'pic', or somesuch), the 'path' argument needs to be a directory path, plus the filename you want to save it to. So for instance, you could have a path of "C:\PosterizedPic.jpg". Make sure to include the quotes. If I'm understanding your problem correctly, chances are good that you have one of those listed incorrectly. Chris Phillips
Thanks, Chris. And I will be covering writePictureTo in class on Friday. Colin Potts

How do I scale down a digital image? The Image Scaler link for Macs does not work for me. Is there another way to scale the image so I can use it in JES? Thanks!
The link was broken, and I have corrected it. Sorry about that – and also for missing this question earlier. Colin Potts

???I have writtenthe picture and it goes to the path i describe. I must just not understand your answer to my previous question. because when it writes it does not show any errors. it just puts the file there but it does not put the image in the file. my computer reads it as a picture and says that the files contains 0 kb or in other words no picture in the file???
This may be a stupid question, but when I do the writePictureTo thing it saves it to my computer, but it saves the image that isn't changed. How do I get it to save the image that I have already posterized so I can upload it onto the bonus page?

Here is my code and it writes a file to my desktop but the file is empty???
writePictureTo(picture,"C:\\Users\\JayBoyyyy\\Desktop\\jcollins6.jpg\\")
_ Jay Collins

Do not add the \\ at the end of the string then it should work. Your string should look like
"C:\\Users\\JayBoyyyy\\Desktop\\jcollins6.jpg"

Should JES recognize the abs function in the same manner it recognizes, say, the getRed function? And by that I mean, should JES both embolden and color purple the abs function when used in the program area? Scott Williams
No, it shouldn't. It'll work, though. Noah Witherspoon

How do we submit the homework? Email to the TA, or to cs1315? Noah Witherspoon
You submit it on T-square. Thanks! Brittany Duncan

I downloaded the mediasources pictures onto my desktop, but when I try and open a file using the command area on JES (I did: fn=pickAFile() )i can't open the Mediasources to pick a picture. It just acts like I am picking the whole mediasources file as my picture. What am I doing wrong?
Make sure that you have extracted them. The media sources come as a zip file, which requires you to extract its contents before you can access it. If you need help with extracting the files, have a look at http://eee.uci.edu/help/zip/how-to/#winunzip Chris Phillips

how do i save the new picture as to where i can attach it for extra credit?
Check the JES Dictionary - Picture Manipulation Commands page for the writePictureTo method. Noah Witherspoon
Homework Submission?
How can you put multiple conditionals in an 'if' statement? Robert Lee
You can combine expressions using the keywords and, or and not. I will be talking about this in class tomorrow. Colin Potts


Is there any way to re-submit stuff on T-square? I unintentionally omitted the collaboration statement(I didnt collaborate) and all the other required stuff.
did you save it as a draft or submit it? I don't think you can if you submitted it.
Just send a note to your collaboration statement to your TA, explaining that you forgot to add it to the submission itself. Colin Potts

Oh and by the way, are we supposed to save the homework as a draft that is eventually taken as a submission on the due date or are we supposed to submit it outright? (my own question)
I did everything the picture manipulation commands said to do, and the error keeps saying that the path cannot be opened and to check if i can write it to the directory, but I don't know what this means.
You should be saving your homework as a draft, and -not- clicking submit. Once you click submit, you can never submit again. You'll have to email your TA if you realize you forgot something. If you save as a draft, however, then you can update it as often as you like until the due date. At the due date, T-Square will automatically submit your saved draft for you, so you don't need to worry about it. Chris Phillips
I did everything the picture manipulation commands page said to do but an error still comes up saying it can not open the path and to check to see if it can be saved in the directory, but i do not know what this means
Could you post the "writePictureTo" line from your code, so that we can see what might be wrong? Remember to enclose it in code tags as explained at the top of this page Colin Potts
I can get the original image to save by doing writePictureTo, but I can't get it to save the posterized picture. How do I save the changed picture?
Did you post that code in the black area or as part of your program (in the white area)? That's why mine didn't work at one point, I posted it in the black area.
writePictureTo(picture, "C:\Users\Owner\MyDocuments\posterizedpic.jpg")

You're missing the "r", ie
 (picture, r"path.jpg")

Do these statements conflict? Is it basically saying if the value is between 80 and 90 set it to green? Or is there an error?

If the original red value of the pixel is greater than or equal to 90, set the new red value of the pixel to 255
If the original red value of the pixel is greater than 80 and less than or equal to 167, set the new red value of the pixel to the original green value

Nope, there's no error, JES will be able to figure it out if you put in those instructions exactly. And the program might change the values of the pixels more than once if more than one condition applies to them.
writePictureTo(picture, r"C:\DocumentsandSettings\Owner\MyDocuments\MyPictures\posterizedpic.jpg")


it still won't work; it is saying the same thing:
The error was: C:\DocumentsandSettings\Owner\MyDocuments\MyPictures\posterizedpic.jpg could not be opened. Check to see if you can write to the directory.
I wasn't able to do what you wanted.
The error java.io.IOException has occured
Please check line 22 of C:\Documents and Settings\Owner\My Documents\posterize
Well, there's your problem. C:\DocumentsandSettings and C:\Documents and Settings are different from each other. (Think spaces.) Computers are very, very stupid and they do what you say, not what you obviously mean. Colin Potts
I try to do this: "If the original red value of the pixel is greater than 80 and less than or equal to 167, set the new red value of the pixel to the original green value"
and it wont work.

My code looks like this:
if getRed(pixel)>80 and <=167:


even if something seems repetitive, it's still neccessary
 getRed(pixel)>80 and getRed(pixel)<=167: 
And you might want to check your parathesis too, you don't have enough.

Im fairly certain I wrote the code correctly but when I look at the end result there is too much red or not enough blue and green. I know it's not just the picture Im using because I tested it on the cat picture from here: http://coweb.cc.gatech.edu/cs1315/5505
and it appeared different from the original.

I dont get how to figure out what the original Red and Blue values are.
I'm pretty sure we went over those in class, but its also on this page -> http://coweb.cc.gatech.edu/cs1315/2759 and in the book in Chapter 3
I already turned in HW via T-square, but forgot to add the collaboration statement to it. Am I able to resubmit the HW as long as it's in before the deadline? James King
This question was already answered further up on this page

How do you set a color to its original value? I used the getBlue, getRed, and getGreen things but my colors keep coming out wrong.

Looks like this:
    Red = getBlue(pixel)
    Green = getGreen(pixel)
    Blue = getRed(pixel)


Is this what you have at the beginning of your code to find the original values? If so it looks like you've mixed up two of them (red and blue).

I swapped the red and blue around and it is still messed up. Even more so now. Heres a side by side of the TAexample cat and mine:
http://server6.theimagehosting.com/image.php?img=cat.456.JPG

That's looking like something that is going to take some code examination to rectify, since nothing immediately comes to mind that could cause that, short of some rather interesting code weirdness. Come by someone's office hours with a copy of your code, or email your TA and ask if you can submit it to them through email to receive comments on it.

Should spacing between the "abs" and the parantheses cause the colors to change?

setRed (pixel,abs (Blue - Red))

I wouldn't think so...is it working right the way it is?
The spacing does not matter. Colin Potts

never mind that I figured out whats up. More importantly, can you answer the question above this one?
Are you really getting that banding on the image? I.e. the color shifts change abruptly part way down the image? (That's the way your image looks in my browser.) If so, send me your code by email and I can comment on it. Colin Potts
When I changed the spacings between the greater than or other mathmatical signs, the colors changed.. should I leave the spacings out or not?
You can put any number of spaces between things but not inside them. The symbol >= is one logical operator that means "greater than or equal to", so if you put a space between the two symbols that is like putting a space in the middle of a variable name. I'm surprised that the program even ran. Spaces between names and symbols do not matter – so a>=b and a >= b are the same. Colin Potts

    if 80<Red<=167:

is this legal in python like in math?
  i.e.   a < x < b

Yes. it is shorthand for
if (80 < Red) and (Red <= 167)

(The parentheses aren't necessary, but make it clearer to me.) You can experiment using the command area to answer questions like these yourself. But to do that in this case, you would need to know that you only type in the part after the word "if" and that for a true condition, Python prints the value 1 and for a false condition, it prints the value 0 Colin Potts.

I'm still not understanding how to swap the red and blue values.
OK. This is almost doing it for you, but here goes. Say you want to swap the values of a and b (let's say that they are numbers). You would do this:
   temp = a
   a = b
   b = temp

Try this with numbers in the command area. Try it without using temp, to see why you need it.
Colin Potts

What does it mean when the error says "local name referenced but not bound to a value"?
It means that you are using it as if you had already given it a value, but you haven't. Colin Potts
Ok, so sometimes my code will posterize a picture, but sometimes it gives me that "not bound to a value" thing like I'm missing something small. For example, in the MediaSources pictures, it will posterize the beach picture but not the bigben picture.
Try sticking in two '\\'s at the end of the path, before the 'bigben.jpg'. See if that does it. With the code I have for this, I got an error, as it seemingly tried to interpret '\b' as being an escaped character, rather then part of the path. Chris Phillips
Nope, it still shows the error. It says there is something wrong with my setRed(pixel, redness). On other pictures, it will say something is wrong with the setBlue or setGreen. And then, sometimes it works.
I don't believe that the SAME program will give an error for one picture and not for another. (There are many situations where this can occur, but these situations will not arise with the template you should be using.) What is almost certainly what is happening is that you are tinkering with your program to see what happens so that the different behaviors you are observing and that are puzzling you are really coming from (slightly) DIFFERENT programs. This is very confusing for you, and since it means that you are unable to state precisely what is going on, nobody else can help you either. I can't tell what the problem is with your program right now, but if, say, the very LAST error message you got was that "redness" is not being bound to a value, work out why redness doesn't have a value. There should be a line above the point of the error that starts "redness = ....", and the error message suggests to me that that line is missing. So ask yourself what the value of redness should be and give it that value. Colin Potts

where are we supposed to write the collaboration statement? At the top of our program in JES?
Yes. Put it in a comment. Colin Potts
I'm a athlete here and we are provided with tutors for this class. I did the work and he checked it..is that excused for collaboration and if so what should I write for my collaboration statement?
If they actually helped you in some way (rather then just glanced over it and nodded), go ahead and throw in "I worked on this homework with the aid of a CoC/athletic department assigned tutor, Soandso". I suspect that'd still fall under the same clause as "Colin and the TAs", in people you can leave out of your collaboration statement, but barring something by Colin or Brittany (and with the deadline coming up), it's probably best to just err on the side of caution, and provide full disclosure. Chris Phillips
I'm having difficulty with the last two questions. Can I find I help with them in the book?
For the keywords, look at some examples of code from the book (pick some from anywhere) and ask what keywords appear on the line immediately preceding an indented block. The keywords are the ones that would be highlighted in blue if you type the example into JES. We have encountered four of these words so far. For passing parameters, see the last two paragraphs of p. 32. Colin Potts
I have my program written out, but it only works the second time I run it. The first time I run PosterizeMe(pic) and show(pic) it will come up with the picture in all blue, then if I run it again the same way, without changing anything in the program, it will come up like it should. What am I doing wrong?
Are you sure about this? I ran my version of the program twice to see what would happen. I get a very blue picture after running posterizeMe a second time. Interestingly, the third time, it looks a bit like it should, and then the fourth time is is v. blue again. Obviously, if you posterize a posterized picture, weird things are going to happen. I think you're accidentally doing the posterizing twice before looking at your results and then when you do it again, it looks nearly right. Colin Potts
It may be possible that you need to do a repaint(pic) before showing it. -Buck Scharfnorth
I don't at all understand what to do with the first of the additional questions for the homework. Do we use the program to find exact numbers or do we just state something general? If we do have to put explicit numbers, what if the code gives us more than one number for any of the RGB values? And can you have more than one 255 value for a pixel?
Yes you do need to find the exact values, but you do not necessarily need to use the program to find it. I find it simplest to solve by tracing your code and deriving your answer mathematically. You cannot have more than 1 value for any single R,G, or B value. The value will between 0 and 255, and because the red, green, and blue are not related, you can have any of the 16 million possible colors (256^3) with 256 possible values for each red, green, and blue. -Buck Scharfnorth
How do I look at the picture that I am manipulating while I am using JES?

Can someone please explain the show ( ) or openPictureTool (). What exactly do I write and what are the steps.
There are no steps. Assuming that you have a picture called pic, just say show(pic) or openPictureTool(pic) in the command area. Experiment with the picture tool by clicking on the picture. Colin Potts

I'm trying to save my Picture (posterized) on a Mac (I usually use a PC). What is the path on a mac, if its on the desktop?) (i.e for a PC it's writePictureTo(picture, "rC:\Users\Owner\MyDocuments\posterizedpic.jpg")
what would it be for a Mac?
On mine it is "/Users/potts/Desktop/" (Note the capitalization.) The second folder in the path could be anything, but its name should appear in the left panel of the finder next to a home icon. Colin Potts
Even better: Go to the Macintosh HD icon in the finder and navigate from there.
im trying to save my perfectly posterized picture and i can't. This is what I get.

writePictureTo(picture, r"/Users/gtg777y/Desktop/jpg")write
Invalid syntax
Your code contains at least one syntax error, meaning it is not legal jython.
Well, if you read the line of code carefully, this looks like a case of sloppy cutting-and-pasting! Colin Potts
Then I tried: >>> writePictureTo(picture, r"/Users/gtg139y/Desktop/jpg")
The error was:picture
Name not found globally.
A local or global name could not be found. You need to define the function or variable before you try to use it in any way.

Please Help, I really need the extra credit (after that quiz)What am I doing wrong (oh, and I'm using a Mac by the way)
(oh and I'm using random gtg#'s with you right now, but not when i'm actually doing it)
There are two problems. The second one, which you haven't hit yet is that you should really give your file a sensible name – something like "gtg139y.jpg" (a name followed by the dot-jpg extension.) The first error, which is giving you the error message is that you are trying to save a picture object called picture that doesn't exist. You must have called your picture something other than "picture". That is what "The error was:picture" is telling you. Colin Potts
When I saved my files in T-sqaured. Then tried opening it-it came up as a MPEG file and isn't showing up properly. Should I just send the file to my TA just in case??
Just send him or her a note explaining what has happened and that you can supply the file by email if necessary. It probably won't be. Colin Potts
Do you mind if I used an animated gif made entirely of posterized images?
As in the extra credit.
If your program generated and saved them, sure. Why not? Colin Potts
yeah, this saving the picture (for extra credit) is not working. . .is there an alternate way to send it or save it?
No. Saving files is quite basic and necessary. You won't be able to do the movie homework (#3) at all if you don't get this. If the Coweb were not responding so that you couldn't upload a file that you had successfully saved, that would be a different story. But you have to have a file to upload. Colin Potts
I am having major problems with running my program, i wrote it yesterday and was going to run it and debug it today.
Big mistake - but you know that now, and it's a valuable lesson. Run and debug as you go. Colin Potts
I have been trying to run the program after i load it since 12 noon. On my laptop i tried 3 different times, and waited an hour each time before having to shut down the program bc it would just still have an hourglass... with no other programs running. Then thought it might be the computers and have been trying on my roomates for 2 hours and it still after an hour will just act like its still trying to implement the program
when i try to save the new picture, it just saves the original one. i dont know what to do
Well, that's a reasonable hypothesis. If it runs slow, try it on a faster computer. But as you found out, it is probably the program itself. My guess is that you are doing LOTS and LOTS of computation for every pixel. Do you have one for loop? There should just be one loop. The block inside the loop should consist only of if statements and their blocks – no more for loops. (You can email me your code now for a quick sanity check.) Colin Potts
when i try to save the new picture, it just saves the original one. i dont know what to do
There is no try; there is only do ;) Seriously. It's doing what you tell it to do, so let's work out how come you're telling it to save the original file, not the changed one. (1) The posterizing does actually work? I assume it does. (2) You're calling posterizeMe(pic) from the command area? (3) You're doing writePictureTo(pic, "blahblah.jpg") also from the command area? (Are the same names [pic in my example] being used for both posterizeMe and writePictureTo? Colin Potts
i got it! i didnt do the posterizeMe(picture)
i got it! i didnt do the posterizeMe(picture)
i got it! i didnt do the posterizeMe(picture)

can someone please explain how i am supposed to store the original color values.
If you say something like r=getRed(pixel) r will be the original red value of the pixel. Even if you later change the red value using setRed, r won't change. Colin Potts

How does the TA know which picture you used? Or does it matter?
They don't. Your program should work for ANY picture. That's why functions have parameters. Colin Potts
do we need parenthesis for the conditions? For example,
if(getRed(p)>=90):
No. The parentheses make it clearer for many people, but they aren't necessary. Colin Potts
I'm confused....I thought T-Square was supposed to auto-submit our homework and it's 7:20 and it hasn't?!?
I think that the autosubmissions don't happen until midnight after the 5-hour grace period expires. T-Square flags them as late, but don't worry about it. Colin Potts
thanks
I dont understand the swapping of the red and blue values still? I saw your example above and I do not understand what your saying when you write
temp = a
a = b
b = a
When swapping values, you need to be able to do it in a way that won't overwrite needed variables. For instance -
a = 5
b = 3
a = b
b = a

What's wrong with this? Well, you start out with a being 5, and b being 3. In the first step, a = b, 
you're making it so a now stores the value 3. The 5 is lost. So in the second statement, when you say 
b = a, you're just reassigning b the value of 3, because that's what a now holds, the 5 is gone.

This (can) apply in the homework, depending on how you do it, because your comparisons are all the 
-original- values, of the original pixel. You don't want your assignment statements to interfere with 
those, because you could accidentally change the original value, which'll mean you've lost your 
original value, in the same way we lost the 5 up above. And if you lose the original value, then 
your later comparison statements may not evaluate properly. If you're still not understanding, 
swing by someone's office hours soon, so you can be brought up to speed before the next homework. 
Chris Phillips
You've still got office hours on Monday, right Dr. Potts?



Links to this Page