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 2 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>



When i try to upload my picture to the gallery i get an error message, "IMAGE function cannot find upload" is there any tricks to adding the montage to the gallery. thanks

copyPicture is giving an error. I tested the montage function and it will show me a blank canvas. JES says there is an invalid input parameter error in the line:

destPixel = getPixel(bg, destX+x, destY+y)

bg should be referencing the blank canvas I made, which is showing up when I put in "show(canvas)".

JES doesn't let you access the components of a Color object, does it?

When I do the makeEmptyPicture command and put in the appropriate x and y values, nothing happens. The computer accepts the command but doesn't return an empty picture. How do I fix this?

On the extra credit, what doe sit mean "thematically related?"
It means if all the pictures have a similar theme (but are not the exact same picture). Thanks! Brittany Duncan

My program takes a really long time to run. Like, over a minute. Is that OK? Thats the speed on my crummy laptop but I kinda feel bad if all the TA's have to sit through minute-long programs Jon Paprocki
That's fine. It's doing a lot of work. The TAs will appreciate your consideration, but they are used to this. Colin Potts
However, please make sure that you aren't using huge pictures. If all your pictures can be put on a canvas that fits on the screen then they should be fine. Pictures around 300x300 pixels or so should be perfect, but a little bigger would be fine. Thanks! Brittany Duncan

OK and how do I set a function to be interpreted as a picture? The assignment says the TA's will type show(montage()) but when I do that I get that the input is not a picture, which is obvious. Can't I just put show(picture) in montage() and the TA types montage()? Jon Paprocki
You can, but you won't recieve full credit. If the last line of your code is "return picture" and you type show(montage()), that should work. If you don't understand why then please see a TA after recitation or at office hours. Thanks! Brittany Duncan
Change of plan: I was going to do local manipulations of pictures in class on Friday. I will delay that now until Monday. This Friday instead, I will cover functions in more detail and the "return" keyword. Colin Potts

Alright it works fine now :) Jon Paprocki

If we are supposed to use at least two functions, which one should be named montage? Jabari Worthy
The main function should be called montage, as that is the only function the TA will call. Thanks! Brittany Duncan

The assignment says to post your pictures. Do we need to post each individual transformation if only the original is needed? Jordan Jones
Ok, so you have to turn in all the pictures you use for the assignment to T-square, along with your code. You will only post one picture to coweb, which will be the final image created (ie all 5 together) Toni Walden

What is "Your function should take in NO INPUT PARAMETERS" means?
The passing of parameters to a function is explained on p.32 of the textbook and I will go over it again on Friday. Functions that take no input parameters resemble pickAFile() (which takes no parameters) as opposed to, say, getPixel() (which takes three). Colin Potts

I still don't understand how do get a picture without using the pick A File command.
Use getMediaPath() and setMediaPath(). Thanks! Brittany Duncan

How can you have more than one function in your program? I tried to have a copy function in the montage program but it didn't work. The canvas stayed white.
Did you ever call the copy function? Thanks! Brittany Duncan

I don't understand what you mean above by "call the copy function."
Calling a function is what you do when you use it as opposed to defining it. Think of "calling" as executing, running, or doing. Colin Potts

i'm trying to find the slides from class, and i feel stupid since i used them for the last hw and i cant find them now...any clues as to where i can find them? Sorry about the brain fart
They're linked from the syllabus page on the home page. Colin Potts
Even better! They are now linked from menu on every page. Colin Potts

Hey I accidentally added the montage picture twice. My prism ID is bgravitt3, but if you could delete the picture Sicko Collage? Thanks so much!
Done.

I am having trouble with the copy function. How can I define copyPicture or do I need to do something differently?

There is an example copyPicture() function in the collage construction kit, which you can basically
use verbatim (just make sure you understand what it's doing). If you mean how do you use that function,
in your montage function, you would use something like

copyPicture(pic1, canvas, startX, startY)


Where startX and startY give the upper left corner of where you want the pic to be 
(so, variously,  1,1  1,midY  midX,1  midX,midY, and one more for the central location,
which since it wasn't mentioned in the sample code, I'll leave out. 
Chris Phillips


I keep getting the error message:
show(picture): Input is not a picture
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.

What should I be looking for in order to fix this? Megan O'Keeffe

The variable 'picture' is, well, not a picture. Why that is, is dependent on your code. For this assignment, you no longer are using pickAFile(), but you'll still need makePicture("whatever.jpg"), where whatever.jpg is the name of an image located in the directory you're selecting with setMediaPath(). Make sure that whatever manipulations you are doing, you are still using an object (possibly one you've passed through multiple variable names) that was made into a picture at some point. Chris Phillips

Is our code supposed to be huge?

Define 'huge'. You'll definitely be writing much more code then you did on the last assignment (posterizeMe() was a single function to change a picture in a single way. You'll have approximately four times as much just for the picture manipulations, plus some code to create each picture, assign where it'll go on the canvas, and a function to copy it to the canvas). But I can't really give you an exact "You should have X lines of code", because there are a lot of different ways to code this assignment. Chris Phillips




okay.. so i'm getting "I wasn't able to do what you wanted.
The error java.lang.ArrayIndexOutOfBoundsException has occured
Please check line 60 of /Users/graysonbyrd/Documents/CS1315/hw2.py"
and I realize that it's probably because my canvas isn't big enough, but it is?! Grayson Byrd
If this is on line 60, I am guessing it is when you are copying one of your transformed images onto the canvas after doing all the transformations. An out of bounds exception is often a sign of an off-by-one-error. Your canvas may be big enough, but if this is the top-right copy, you may be starting to write it at an x that is one too large so that the picture "falls off" the right edge of the canvas. If it is the bottom-left copy that is causing the problem, it is probably your y value that is causing the problem. Colin Potts

There is no file at /toucanoriginal.jpg
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.

I keep geting this over and over even though my file does exist...correct type of inappropriate value argument? huh?
My money is on the computer being right, not you :) The file really doesn't exist - at least, not where you are telling it to look. Don't forget to use setMediaPath and getMediaPath Colin Potts

This whole setMediaPath() thing isn't working for me for some reason. I might be just totally wrong here, but the book is telling me to type it into the command area... so I type >>> setMediaPath() and press enter. It lets me get to MediaSources and then it won't let me pick anything. How do I make it work?
You have to pick a folder, not a file. Go to the folder above MediaSources, not into MediaSources itself. From the parent folder, select MediaSources by clicking once, and then click the Choose button. This will select MediaSources as your media path. Colin Potts

Im getting this error:

getPixel(picture,x,y): x (= 513) is less than 1 or bigger than the width (= 512)
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 29 of C:\Documents and Settings\Sami Bashir\Desktop\hw2\hw2

the problem code looks like this:
  for destX in range(x, getWidth(pic)+x):
    for destY in range(y, getHeight(pic)+y):
      fromPixel = getPixel(pic, destX, destY)
      destPixel = getPixel(canvas, destX, destY)

This is the off-by-one error that I explained at length in class on Wednesday. What was your question? Colin Potts

I altered my code back to the orignal and I got this message instead:

getPixel(picture,x,y): x (= 0) is less than 1 or bigger than the width (= 512)
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 29 of C:\Documents and Settings\Sami Bashir\Desktop\hw2\hw2

the code looks like this:

for destX in range(x, getWidth(pic)+x+1):
    for destY in range(y, getHeight(pic)+y+1):
      fromPixel = getPixel(pic, destX-x, destY-y)
      destPixel = getPixel(canvas, destX+1, destY+1)

So. Think. You have tried this two ways. The first way you showed caused x to become too large. (You can't set a pixel that is off the right-hand side of the picture.) The second way - when you altered your code "back to the orignal" - meant that you started out trying to set the pixels in column 0 (which is off the left-hand side of the picture.) The problem is that you are changing TWO things: one in the range arguments and one in the arguments of getPixels. Why don't you try changing one thing at a time? Colin Potts

I TRIED altering one bit of code at a time and I still came up with the same errors.
That's OK. When you are done shouting, let us know if you still want help. Colin Potts


I didnt intend for the capitalized letters to be taken as shouting. I meant for them to draw attention amidst all of the new questions. I would still like help though.
OK, and I forgot to insert a smiley. I think that you are making a mistake that would be easier to avoid if you looped instead through x's and y's that represented source locations instead of destination locations. That way, your fromPixel should always be the pixel at sourceX, sourceY with no addition and subtraction necessary. Where the destPixel is will depend on which of the copies you are making (top left....bottom right). I'll sketch a code skeleton later. Colin Potts

Any chance at a bit more extra credit for interesting transformations?
But surely, art is its own reward? Colin Potts
Indeed. I'll do 'em anyway.



Ive read the other homework questions but im still confused about the setMedia path, i know you said to choose a folder and not a file but i thought i was?( im just doing an example from the book, trying to get the same results.)
>>> setMediaPath( )
New media folder: C:\MediaSources\
>>> getMediaPath("barbara.jpg")
'C:\\MediaSources\\barbara.jpg'
>>> barb=makePicture(getMediaPath("barbara.jpg"))
>>> paperfile=getMediaPath("7x95in.jpg")
Note: There is no file at C:\MediaSources\7x95in.jpg
ps thanks
You're not confused; you're doing everything right. You're just misspelling the path of the paperfile. Colin Potts

If we decide to use a posterize function, is there a specific way we have to do it, or can we create our own function that still posterizes a picture? In other words, is there more than 1 way to posterize a picture?
Sure. The example I showed in class mapped every pixel to one of eight colors: RGBCMYKW. Homework 1 mapped the colors differently. A bitmap is just a posterization in which every pixel either goes to white or to black. You can change the rules for the color mappings and the thresholds however you like. Colin Potts

There is no file at /toucanoriginal.jpg
The error was:
Inappropriate argument value (of correct type).
I've used the setMediaPath and getMediaPath functions but I continue to get the exact same error message
def makeCollage():
  canvas=makeEmptyPicture(2000, 2000)
  pic= makePicture(getMediaPath("toucanoriginal.jpg"))

There must be something wrong with how you are setting the media path. When you run setMediaPath() in the command area, JES should respond with something like the following:
>>> setMediaPath()
New media folder: /Users/potts/Documents/ed/1315/Materials/mediasources/

Also, I get the following error when I try to access this file (of course, because I don't have it):
makePicture(filename): There is no file at /Users/potts/Documents/ed/1315/Materials/mediasources/toucanoriginal.jpg

Notice that in my case the full media path is given before the file name. In your case, it is just "/". Colin Potts
/users/sylviedodell/Pictures/mediasources
to set the media path don't you just type setMediaPath() and go to the correct place when prompted?

it seems like my collage has little empty pixels (white) on the bottom,,, i am very confused becuase no matter how many pixels i add or subtract, there is still white space under the bottom pictures.... I did:
targetY=getHeight(canvas)-getHeight(pic3)
for sourceY in range(1, getHeight(pic3)):
px=getPixel(pic3, sourceX, sourceY)
cx=getPixel(canvas, targetX, targetY)
setColor(cx,getColor(px))
targetY=targetY + 1
targetX=targetX + 1
cant understand the problem...can you please tell me what's the problem?
Please put code tags around your code (see top of this page) so that it shows up laid out correctly. If the problem is with the indentation of your loops, no one could tell from what you posted. Colin Potts

I'm trying to open the .pdf of yesterday's lecture and it won't work. Can you repost? Thanks!
It works for me. Sometimes the CoWeb stalls and you have to hit the reload button and try again. Colin Potts

I am having issues with saving my picture so I can post it on coweb. I tried: writePictureTo(pic, r"C:\Documents and Settings\Serah Frey\Desktop\Python Pics\gtg618w.jpg") and it said name not found globally (i.e. "pic" but I tried "picture" and "myPic" which are all I can think of that my picture could be named in my program. Am I supposed to do anything besides run the program before I do writePictureTo or is there something else I am missing?
Well, it's your program. You should know what the picture is called! ;) Are you saying something like pic=makeCollage() before trying to write it? That's how you give it a name so you should then be able to show(pic) and writePictureTo(pic, ....) Remember that the homework requires that your function return a picture, not show it. Colin Potts

In one of the above questions, someone answered that "There is an example copyPicture() function in the collage construction kit." Is this person talking about the textbook?
No. It's just a mouse click away in the slides and code page. Colin Potts

Whenever I run my program I keep getting a blank canvas. Any idea why that might be?

when i copy a picture to the canvas, the targetX=1 and targetY= 1 if i want the picture to be in the upper left hand corner right? and if i want it to be say th eupper right hand corner, targetX=width +1 and targetY=1? si, no?
That's sounds right (given that width=getWidth(picture) ). Colin Potts

no wait scratch that. if i want the pic to be in the upper left hand corner, targetX=1,targetY=height +1.
No, you were right first time. y-coordinates start at the top and go down the screen. Colin Potts

'C:\\Users\\Tom\\Pictures\\2007-09-01 Summer 2007\\church.jpg' is that an accepatable media path? it isn't a picture from MediaSource. my program should still be able to funcation as long as i set the media path there, correct?
The media path is a folder, not a file. But if you mean 'C:\\Users\\Tom\\Pictures\\2007-09-01 Summer 2007\\. Yes, that is fine. When you submit your work, the TA will put your file church.jpg in a folder and set the media path to that folder. Your pictures don't have to be from MediaSources. Colin Potts

I know we talked about this in class, but what does this mean? "An error occurred attempting to pass an argument to a function."
Passing an argument to a function means sending a variable into a function. When you call, say, posterizeMe(pic), it is sending the defined variable called 'pic' into the posterizeMe() function. Make sure the variable is defined (i.e., you actually have declared 'pic', and have put a picture into it), and make sure that the function is expecting a variable (make sure the function reads def posterizeMe(pic) rather then def posterizeMe(). The first expects a variable to be passed in, the second does not). If one of those isn't written properly, you'll get that error. Chris Phillips

when I setMediaPath and then later in the program, i ask it to makePicture(getMediaPath(soccer)) but it tells me i have the innappropriate argument type and I don't understand why. Is there something I'm missing or completely misunderstanding? thanks!

'soccer' is not the correct name of the file. It might be 'soccer.jpg', but not simply 'soccer'. Make sure to enclose it in double quotes, as well. So you'd have makePicture(getMediaPath("soccer.jpg")) for instance. Chris Phillips





Is it supposed to look like "return picture" or "return(picture)"?
Doesn't matter. return is not a function but a keyword, so the parentheses are not necessary but don't do any harm. Colin Potts



Okay, I've set the media path, but I keep getting this error message:

Note: There is no file at .\eye2.jpg
makePicture(filename): There is no file at .\.\eye2.jpg
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.

Sorry if you have answered this before : /
We have. Chris's answer above is excellent. If this is still holding you up, you can make your function work temporarily by cheating. Use pickAFile() while you work on the rest of the code. You can then look at your media path problem tomorrow with me or a TA. Colin Potts

Do we need to include in the final code the functions to transform the original pictures (examples: negative, scale, lighten...)?
I have been trying . but I can't
Yes, you need to include all the code. You can copy some of this from the examples posted at the slides and code page (literally copying and pasting) or from the textbook. Colin Potts

how can you make canvas to picture???
"Canvas" is just the word we have been using to describe a background picture that you want to copy another picture onto. Usually it just consists of all white pixels, but it doesn't have to. So, no conversion is necessary: a canvas is already a picture. Colin Potts

When I try to save my picture I keep getting the error:

The error was: C:\Documents and Settings\my name\Desktop\Python Pics\C:Documents and Settings\my name\Desktop\Python Pics\montage.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
See the announcements page entry for September 11. Colin Potts
Oh, no, wait. (My previous response may still be helpful for other who are still getting this error.) In your case the problem is simply that you are mistyping your path name. Read the error message carefully. Colin Potts

When we use "return" in our program, does it go in the "for" loop (the "for pixel in allPixels" loop) or does it go in the primary indention for everything following def function:?
If you put the return after the for loop, the function will exit after processing all the pixels. If you put it inside the for loop, the function will exit after processing only one pixel. Colin Potts

when I do my copy function that it says to do on the boring collage construction page it gives me an error?

def copy(sourceImage, targetImage, X, Y):
for destX in range(getWidth(sourceImage)):
for destY in range(getHeight(sourceImage)):
fromPixel = getPixel(sourceImage, destX+1, destY+1)
destPixel = getPixel(targetImage, destX+x, destY+y)
setColor(destPixel, getColor(fromPixel))>


montage()
getWidth(picture): Input is not a picture
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 51 of /Users/iamthewalrus1223/Desktop/CS Notes/montage

What does that mean?
Please surround your code with code tags as instructed at the top of the page and re-post. Colin Potts

Do we put the setMediaPath() command in our code (as the first line), or should we just leave it out of the code because the TAs will be typing it into the command area before they run the code? Should we just have getMediaPath() inside our actual code, and not put setMediaPath() in the code at all?
call setMediaPath() in the command area to test your function. Call getMediaPath() in your function itself. Colin Potts

I'm sorry if this has already been asked, but when i try to run my copies through a makePicture function, it tells me that The error was:isabs() argument must be a string object, not instance of 'Picture'
Inappropriate argument type.
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.
Please check line 23 of C:\Users\Katie\Documents\CS 1315\hw2.py
I thought that the point of make picture was to ask JES to recognize strings as pictures...?
Thanks!

Never mind the questionright above this, i figured it out! Thanks anyway!

I am having problems with writePictureTo. I read the above question about this, so I told the program-

>>> pic=montage()
>>> show(pic)
>>> writePictureTo(pic, "/Users/Christy/Documents/C 1315/hw2Sources/")
The error was: output == null!
I wasn't able to do what you wanted.
The error java.lang.IllegalArgumentException has occured

it was able to show the picture, but then i got that error message. I'm not sure whats wrong...
You need to tell JES the name of the file you're saving, not just the folder you're saving it into. JES won't make up a file name for you. If it should be "hw2.jpg", your write line should look like: writePictureTo(pic,"/Users/Christy/Documents/C 1315/hw2Sources/hw2.jpg") Colin Potts

when I defined the canvas name I called it just "canvas"
canvas=makeEmptyPicture(920,321)
at the end of the program I wrote show(canvas) and it works,
but when I want to save the collage and I write:

>>> writePictureTo(canvas,"C:\newpicture.jpg") it doesn't work.
and I can't save the Collage

where I get my prism ID???

It's the same as your GT email address. Look on the Find Out Who Your TA Is page for your name, and it'll list your ID, if you are otherwise unsure. Chris Phillips

>>> writePictureTo(canvas,"C:\newpicture.jpg")
The error was:canvas
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.
Make sure that you are using writePictureTo() as part of the function within which 'canvas' is defined. I.e., if you define canvas in montage(), make sure writePictureTo() is placed at the bottom of the montage() function, and indented once so that it's run as part of the montage() function. Chris Phillips

so for the extra credt, the pictures must be thematically related, and above, you said that this means all the pictures must be different but fall into a theme. but the instructions also say that the "unmodified picture" must be placed on top. does this mean that we should have all the unmodified pictures on top?
No. If you use more than one picture, one of them must be unmodified and appear in the center. Colin Potts

Please look at the following code:

q1 = posterize(makePicture(getMediaPath('double.gif')))

When I try to command getPixels(q1), I get an error. I think I understand the problem, which is that the result of posterize() does not return a picture, right? How can I convert it to a picture? By the way, getPixels(q1) and the line of code above are in the same function. Robert Lee
It has to return the a picture. Colin Potts

When I submit the assignment to T-square, do I need to personally zip the file containing my pictures and upload the zip, or does the site do the zipping for me (i.e., I simply upload each picture)?

That's a little tricky to answer. The short version is "You don't need to zip your files". The longer version is "When it talks about unzipping files, that is how T-square bundles everyone's submissions together, when a TA goes to grade, they download a zip file that contains all their student's submissions, and they then unzip them. So that part of the homework page isn't referring to something you have to do, but rather something we have to do. So just go ahead and submit each picture you used separately (or zip them, but make sure you can retrieve the zip and everything is intact)". Chris Phillips

Is it ok if I integrate the same posterizeme() function from last HW?
Yes. Colin Potts

I have the picture saved onto my computer, but I am having trouble uploading it to the website. It says "image function cannot find the upload" I'm not sure what I need to do to post it.

never mind that obscenly stupid previous question. i figured it out.

so we show the modifications of the picture in our program also?
Don't show. Just return. Colin Potts

Say I have posted pic1 to the top left of my canvas using targetX=1 and targetY=1. If I want to post pic2 next to pic1 should targetX= getWidth(pic1) or getWidth(pic1)+1? When I just use the width of pic1 it looks like the pictures are side by side, but it seems like pic2 should be overlapping pic1 by one column of pixels. However, when I use the width plus 1, it looks like I have a column of empty pixels between the two pictures.
The second one looks right. Don't worry about the apparent column of empty pixels. show() sometimes shows artifacts like this. Colin Potts

I'm trying to posterize only one of the four pictures which I named pic1 by doing this left=1
top=1
midx = width + 1
midy = height + 1
pic1 = pic
pic2 = pic
pic3 = pic
pic4 = pic

However when I ran the code it posterized all four pictures instead of just 1. How do I get the code to just posterize 1 pic?

The easiest way would be to do the following instead -

pic1 = makePicture(getMediaPath("thing.jpg"))
pic2 = makePicture(getMediaPath("thing.jpg"))
...

posterizeMe(pic1)


*Chris Phillips*



Which TA's have office hours available tomorrow? Also, what time and where?

TA Office Hours (scroll down)

when I do my copy function that it says to do on the boring collage construction page it gives me an error?

def copy(picture, canvas, X, Y):
  for destX in range(getWidth(picture)):
    for destY in range(getHeight(picture)):
      fromPixel = getPixel(picture, destX+1, destY+1)
      destPixel = getPixel(canvas, destX+x, destY+y)
      setColor(destPixel, getColor(fromPixel))



montage()
getWidth(picture): Input is not a picture
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 51 of /Users/iamthewalrus1223/Desktop/CS Notes/montage

What does that mean?
Why this error occurs has been the topic of many questions and answers on this and the previous homework page. You don't say which line of the above is line 51 of your program, but I assume it is the one starting "for destX...." in the above snippet. Somewhere else, in your main montage function you have a line that contains something like "copy(p, q, x, y)" where your p,q,x and y are different values. Whatever p is in that call in your code is not a picture - just like the error message says. And that is your error. BTW, there is a second error. I don't know whether your actual code contains this second error or whether you introduced it when copying and pasting to the coweb, but the X,Y parameters in your code and the x and y in line starting "destPixel = ..." are upper and lower case, respectively. They should be exactly the same. Colin Potts

Could we go over get/setMediaPath() and writePictureTO() again in class today?
I'll see if there is time Colin Potts
I went over setMediaPath()/getMediaPath() but forgot about/ran out of time for writePictureTo(). The example code I posted is what I created in class, but I have also added a call to writePictureTo() to show that too. Colin Potts

I want to repost the assignment on T-square, but I already submitted... is there any way I can put the previous file down and post new one that I want to post?

i just honesty do not feel well prepared for this homework. . . i come to all the lectures . . i take notes. . . .i go to recitation.
There is no way to do this assignment completely from what we see in class. I'm over here struggling. . . .

Next time, could we better and more exactly prepare for the homework. I'm just going to assume that they only become harder:-)
Hmmm. Thank you for bringing this up: There are probably a bunch of other students in this position that aren't saying anything. It sounds as though things haven't clicked for you yet, (They do. Really.) and maybe one or two misconceptions are having a big effect on your understanding and motivation. If we fixed those, things might seem much rosier. But no one can help you unless you sit down and go over things in detail. Maybe one on one tutoring might help? Do you go to TA or my office hours? I spent several hours this weekend online helping people via email or IM. Check the Help link on the main page for help with tutoring and the People page for information on TAs' (and my) office hours. Colin Potts
BTW, everything needed for this homework has been covered in class, and most of the components of the code you need has been posted to the coweb or can be copied from the book. We're not deliberately holding anything back to trick you or weed out students. If you can't do this, it's not because we are mean or you are dumb; it's just that something in your problem-solving approach to programming isn't clicking yet. Colin Potts

i keep getting spacing errors!!!

example:
def flippy(pic):
 #pic=makePicture(path)
 newPic=duplicatePicture(pic)
 middleX=(getWidth(pic)/2)
 for y in range(1, getHeight(pic)):


the error is in the first line (def. . .), how should i properly space it?
I put code tags around your code so that people could read it. Please do this in future. There is nothing wrong with the code here, but a spacing error is usually caused by a mistake earlier in the code: You have too many open or close parentheses, or the indentation of what precedes the code is wrong. If it's parentheses, JES color-codes the open and close brackets, so look at those. Colin Potts

so i had this issue and got this response:

I'm trying to posterize only one of the four pictures which I named pic1 by doing this left=1
top=1
midx = width + 1
midy = height + 1
pic1 = pic
pic2 = pic
pic3 = pic
pic4 = pic

However when I ran the code it posterized all four pictures instead of just 1. How do I get the code to just posterize 1 pic?

RESPONSE:
The easiest way would be to do the following instead -

pic1 = makePicture(getMediaPath("thing.jpg"))
pic2 = makePicture(getMediaPath("thing.jpg"))
...

posterizeMe(pic1)


so i changed it and now I'm getting this error when i try to run the fourcopies:

>>> tileFourCopies (pic)
Note: There is no file at /Users/Tommy/Car.jpg
makePicture(filename): There is no file at /Users/Tommy/Car.jpg
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 16 of /Users/Tommy/Desktop/montage.py

So what should I do/write so that I will be able to see the four pictures and just posterize 1 of the 4 pictures?
(please word it in a way so that i greatly understand it, thanks:-)

Make sure you're setting the media path to the directory the pictures are in. I.e., the error you are getting is saying it was not able to get a picture called "Car.jpg", located in /Users/Tommy/, and turn it into a picture. Make sure that you actually have a Car.jpg in /Users/Tommy/, or use setMediaPath() to direct elsewhere.
And, the code above would, if extended (i.e., setting pic3 and pic4 as well), work fine, it would create pictures called pic1, pic2, etc, and then send pic1 into the posterizeMe() function, to be posterized. I used it when doing this homework myself, and suggested its use (and saw it work) when advising people during office hours. If you're unable to get it to work, and unable to get your own coding approach to work, contact a TA more directly, so they can see your code. Chris Phillips


What does "media.Picture instance at 24575979" mean..? It keeps happening after montage() runs for about a minute, and then puts it to a halt.

Well, nevermind - I got it to work now... However, I'm still not sure what the whole "media.Picture instance" thing meant... What is it anyways?
You were probably calling a function just with its name, and not including () after it. You were thus getting the memory address location that the picture was stored in. Don't worry about it, it's outside the scope of this class. Chris Phillips

ok... a final question now that I have a working collage. Mine takes about 3 or 4 minutes to show up. When exactly do TA's stop a program and decide it doesn't work?
Depends. If the TA decides it doesn't work, and you get a bad grade because of that, email them specifically saying that it works, it just takes forever. They should go ahead and test it again, let it run longer, and regrade. Chris Phillips

I keep getting "getPixels(picture): Input is not a picture." but my input is just a copy of the original "makePicture" jpg. Do I need to tell the copy to "makePicture" again? Or what is wrong exactly? Grayson Byrd

Sure, try making a new picture using makePicture(). Fiddle. That's the joy of coding, trial and error. If you can't figure it out, get in touch with a TA through email or IM, send your code, and let them try and help. Hit up someone's office hours, maybe. Chris Phillips

I kept getting this error: getPixel(picture,x,y): x (= 641) is less than 1 or bigger than the width (= 640)
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 14 of C:\Documents and Settings\HP_Owner\Desktop\hw2

 fromPixel = getPixel(pic, destX+1, destY+1)
      destPixel = getPixel(bg, destX+x, destY+y)


That can be a lot of different things. Make sure that your canvas is twice the size of your picture(s), and make sure all your pictures (if you have multiple) are the same resolution. After that, it's probably some code shenanigans, and it may be something you'll want to hit someone's office hours to resolve. Chris Phillips

i know we have to submit ALL of our pictures, but do we submit each individual after-manipulated picture or the original ones if we used different pictures for a theme? (plus the final canvas, of course)

The original ones. The after manipulated picture(s) you don't submit; the only thing image you use at the end, is the collage, which you stick on the coweb.

I accidently submitted an old copy of my homework - is there any way to submit my newer slicker code?

Email it to your TA. Chris Phillips

SO for a really long time I kept getting the....
getWidth(picture): Input is not a picture
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 2 of C:\Documents and Settings\Katie Ruth\My Documents\CS 07\hw2.py
...so then I did makePicture(getMediaPath(blah)) on all my pics, but I am still getting the same error. What can I do?? Is there somewhere I can go where someone can look at it with me?

(fanfare) TA Office Hoooooours!
Though it's a bit too late for this one. You can maybe see if a TA is willing to meet with you outside of their office hours this evening, who can help you (you have until midnight, remember). Still, for what it's worth, make sure that you have lines that are comparable to:

pic1 = makePicture(getMediaPath("thing.jpg"))

AND that you have used setMediaPath(), and pointed it to where your images are located. (as a side note, if you want to email your code to me, I'll have a look over it and try and help you, though I can't promise it'll be too terribly timely. I'm going to be unable to respond to email from 6:00 - 9:30, so...) Chris Phillips

Okay, so scratch the previous question, I figured it out. However when I try to show(montage()) I get this error:
>>> show(montage())
show(picture): Input is not a picture
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.

Is 'picture' what your montage() function is returning? And, is 'picture' defined in montage()? You probably want to return 'canvas', or whatever the variable name is of the picture that now should hold the entire montage. Chris Phillips


I'm getting the same error [getWidth(picture): Input is not a picture] and I don't understand any of the responses to the questions regarding this error.
JES must be right: Whatever it is that you are calling "picture" is not really a picture and does not have a width, and you need to change your program so that it is and it does. At some point in the function above the line that is giving you the error, you should have a line that starts picture = ..... Whatever is on the right-hand side of the "=" should be or should make a picture (e.g. the functions makePicture(...) or makeEmptyPicture(...)). Alternatively, you could be passing "picture" in as a parameter, from another function either in the program or in the command area. If you are doing that, then make sure that what you are passing in is a picture and not, say, a file name. Colin Potts

the homework auto submits itself right??

I am trying to submit the hw to T-Square, its 7:05 right now and its saying its past due date. don't we have until midnight?

I know it's past time, but I'm having trouble with writePictureTo, as in, IT DOESN'T WORK! it loads and acts like it's going to work, but when I try to open the file on my computer, it shows up as a white box with a red X :S

why is this so hard, i've been working on this since saturday morning. . . .life isnt fair :-( :-(
do you drop the lowest homework grade?
No, we don't drop the lowest homework grade. We do pay 13 people to sit around and answer your questions though. :-) Thanks! Brittany Duncan

I'm having a similar issue. If I run writePictureTo, it will make a picture file in the right folder, but there is no picture. what is going on here?


okay, im sorry to ask this. . . but please be merciful and answer.

I struggled doing this on the last hmwk when it was extra, and i still can not do it now, but it counts so. . .

How do I save the picture (montage in this case) I have made? Could you please tell me the directions step by step? (no one has been able to explain it to me in lamens term)

THANKS soooo much!!!

Okay, now when I put in show(montage()), I just get a blank canvas, and I have all my pics with makePicture and getMediaPath and return. Any suggestions???
Sounds like you need to talk to a TA personally. Thanks! Brittany Duncan

Make sure you're setting the media path with setMediaPath(). Make sure you are using lines akin to -

pic1 = makePicture(getMediaPath("thing.jpg"))

to assign pictures. Make sure you are properly copying those pictures to your canvas (this is probably what you haven't done), and that at the end of your montage() function, you have

return canvas

replacing canvas with whatever the blank canvas variable name is. Address those, and you should see show(montage()) work. Whereupon, you would use writePictureTo(getMediaPath("yourGTID.jpg")) to write it to a file.

Beyond that, you need to see a TA personally, and get squared away.

okay so im going back over my hmwk and pictures (b/c i can often be anal like that), and i opened my prgram and loaded it, then put this into the black part:

show(montage())

and i get this error:

show(picture): Input is not a picture
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.

so what's going on? will the TA also get this error?
can someone explain this to me, and help me. thanks!

The TA will in fact get that error. I believe that the problem is that you are probably not "return"ing the picture. Because of this, show() is trying to show something that isn't in your computer's memory. Thanks! Brittany Duncan

when will my assignment submit itself???
11:55 PM. Thanks! Brittany Duncan

im having issues with the wrtiePictureTo function...... boo

oh,you're right brittany, i loaded the one with no return, sorry. . .
but then i loaded the program in whcih i did include return, and this is what i got

first i put in:
>>> show (montage(pic))

and i got:
show(picture): Input is not a picture
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.

then i put in:
>>> show (montage())

and got:
The error was:montage() takes at least 1 argument (0 given)
Inappropriate argument type.
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.

So what should i do? (please help someone)

You need to take whatever is in the parenthesis out. For instance, the line "def montage(picture):" is wrong, it should be "def montage():". Thanks! Brittany Duncan

I keep getting this error message in regards to the copyPicture function. I've checked with other people who've used the same function as me, but they don't have this problem. How do I fix this?

>>> show(montage())
getPixel(picture,x,y): y (= 451) is less than 1 or bigger than the height (= 450)
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 24 of C:\Documents and Settings\User\My Documents\hw2.py

Make sure that all your pictures are the same size. Make sure that your canvas is twice that size (both width and height). Make sure that your loops are correct. It is one of those things that is causing the error. Chris Phillips

I'm having trouble with my writePictureTo. JES doesn't say anything is wrong with the line, but it just won't save. Help?
...
return canvas
writePictureTo(canvas, "mokeeffe3.jpg")
Megan O'Keeffe

Stick in a getMediaPath ( writePictureTo(canvas, getMediaPath("mokeeffe3")) ), and do it before it returns canvas (as once a function returns something, it stops doing anything).

okay so when i put in show (montage(pic)) i get only my main picture, what should i do?

what could i be missing that would give me only the one picture?, i have return pic under all my def functions. . .

First, montage() isn't supposed to take any parameters. Second, make sure montage is returning whatever your composite image is. return canvas, say, if it was called canvas. Chris Phillips

when I put in show(montage()) i get this error everytime and I dont know what it means. can a TA please help me
Picture, filename C:\Users\ali\Documents\MediaSources-MainImages\stewieGriffin.jpg height 272 width 480
Picture, filename C:\Users\ali\Documents\MediaSources-MainImages\glenQuagmire.jpg height 425 width 312
Picture, filename C:\Users\ali\Documents\MediaSources-MainImages\chrisGriffin.jpg height 300 width 400
Picture, filename C:\Users\ali\Documents\MediaSources-MainImages\brianGriffin.jpg height 432 width 400
Picture, filename C:\Users\ali\Documents\MediaSources-MainImages\familyGuy.gif height 386 width 513
Picture, filename C:\Users\ali\Documents\MediaSources-MainImages\640X480.jpg height 480 width 640
getPixel(picture,x,y): x (= 641) is less than 1 or bigger than the width (= 640)
The error was:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
Please check line 48 of C:\Users\ali\Documents\hw2.py

Resize all your images so that they are the same size. You currently are trying to pull in a bunch of varying sizes, and that'll make your code wonky. Then, make sure that the blank image that you are overwriting, is twice the size of your images. I.e., if you have a pic1, pic2, pic3, etc, eachof resolution 400x300, then your canvas needs to be 800x600. Chris Phillips

okay so nw im only putting in show (montage())

and i still only get one picture

What are you returning? Your logic should be "make these 5 pictures of width x, height y, now make a blank canvas of width 2x, height 2y, now pass 4 of these 5 pictures into picture manipulation functions, now copy these 5 images to the canvas, then return the canvas". At the end, are you returning the canvas, or another image? Chris Phillips

how would you resize a picture?

Use an external app. Or, if you aren't familiar with any (come by office hours, I'll show you one) for the purposes of this homework, just use one image rather then 5 different ones of different resolutions. Chris Phillips

okay so im responding to:

First, montage() isn't supposed to take any parameters. Second, make sure montage is returning whatever your composite image is. return canvas, say, if it was called canvas. Chris Phillips

by not have any paramters, do you mean i should not have (pic) i should have ()?

and what do you mean by "make sure montage is returning whatever my composite image is"?

lets say my image is called "flower", are you saying that i should have return after every place that says flowers:
ex:
"flowers.jpg"

return "flowers.jpg"


i don't understand what you are saying, could you clarify some more- thanks chris:-) (or whoever responds, thanks)
No. I'm saying, in your code, you should have something like 

pic1 = makePicture(getMediaPath("flowers.jpg"))
pic2 = makePicture(getMediaPath("flowers.jpg"))

etc...

Then you should be making a canvas with something like

canvas = makeEmptyPicture(getWidth(pic1)*2, getHeight(pic1)*2)


(Your code may be different from that, but basically, you're making a blank image twice the resolution of the pics you've brought in).

Then you manipulate each picture.

Then you copy pic1, pic2, pic3, etc, onto the canvas.

So...at the end, you need to be returning canvas.

No idea if that's your problem, but it's the most likely cause of you getting one picture back out. 
If it isn't, go by someone's office hours tomorrow, or email me your code. *Chris Phillips*

REMEMBER, EVERYONE. GET IT DONE TOMORROW AND GET 80%. GO TO OFFICE HOURS.

Chris Phillips

Chris i love you! thank you for breaking it down, that was the exact problem- you're the best.
(that was absolutely a perfect breakdown for someone new to cs, THANKs again)

now i can sleep in peace, goodnight!!!




Link to this Page