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

Summer 2006 Homework 2 Questions

Post Questions here:


are we manipulating all four pictures (grayscale for one, and whatever we choose for the other three)? Or are we only manipulating three pictures (grayscale for one, and whatever we choose for the other two) and leaving the fourth picture as the original.

Also, are we supposed to include out codes used to manipulate these pictures in our assignment, or do that seperately and just writePictureTo() in order to save out manipulated pictures?

Thanks.

Total of 4 pictures, only 3 manipulations - The original should be there (preferably the first one). One of the other 3 should be grayscale. All code required to make the collage should be included in the file. - Bobby Mathew

how do you effectively write in the makeEmptyPicture(x,y) into your code to make the canvas size you want?
If you wanted a blank canvas of size 300x200, you would do makeEmptyPicture(300,200). - Bobby Mathew

i understand that, where in the code would this be written...

nevermind...thanks.
Just to make sure, you would create the empty canvas in the beginning (before any loop) and then copy the pixels in the appropriate positions on the canvas. - Bobby Mathew


I individually manipulated each picture. How do I paste the pictures onto the empty canvas?
Use the copy function done in class (in the book also) to copy the pixels of that picture onto the empty canvas. -Bobby Mathew

how do you copy all four pictures?

once again nevermind....

does order matter if i have 2 different "def blahblahblah():"??

You're required to have more than one function, so that means you'll have multiple 'def' statements in the same program. Obviously the function names should be different. - Bobby Mathew


when i do writePictureTo() i only save the original picture and not my montage...whats wrong?
If you use writePictureTo, you have to copy the canvas and not the original picture. So, it would be something like writePictureTo(canvas, "C:\\..............") - Bobby Mathew

how do you copy anything in general? i don't have the book onhand, and its not in any of our notes/anything that has been said in lecture.
You just have to get the pixels from the source and target and copy each pixel from the source to the target. You should have 2 for loops which keep track of the width and height respectively and then just get the pixels from the target and the source and then set the pixels from the source to the target. If that doesn't make sense, email one of the TA's. -Bobby Mathew

how do you get two or more functions to correspond to one code...as in i presumed im finished and have a montage but not two def statements in my code, how can that be changed to fall under the requirements and run properly still?
In the command line, you just call one function and that would be your collage function. So, within the collage function, you should make a call to the second function in the same program and that should make it run properly.
def function1():
  .............
  .............
  function2()

def function2():
  .............
  .............

-Bobby Mathew

i used the code to "copy a picture from one object to another" as stated in the book. i have looked it over multiple times and there is not a single thing wrong with it. i get no error messages, and it executes correctly. however, the picture and canvas are still seperated. what am i doing wrong?
Its hard to figure out what it might be. Make sure you're copying the pixels from the picture to the canvas. Emailing the code to your TA might help a little more. - Bobby Mathew

2 problems. I don't understand how to mirror the entire canvas, and where to put the command for that.What we have seen in the book refers to getting a mirrorpoint=getHeight(source)/2, but that splits each picture in half instead of mirroring the entire canvas. Anything else I have tried ends up with an "out of bounds" error. Second, I have a similar problem in writePictureTo, but in my case, even though after running montage I have all four altered images, what ends up saved is just the grayscale which was the last to be defined in my function. I'm so confused!!!!

Ok, nevermind on the mirrorpoint. I figured that out. I still can't get the writePictureTo to work. I run montage and all four pictures are now altered and mirrored and then I writePictureTo(canvas,"gt.....jpg")I don't know if there is something wrong with how I am saving or in the way I am trying to open it back up. do you use pickAFile...makePicture...show? I am only getting one altered and not mirrored image back.

At the end of the main function, do show(canvas). If it shows the correct thing, then run it again but have the writePictureTo command to save it. It should be writePictureTo(canvas, "C:\..........."). If you don't get the right picture, then look through the function which is not doing what its supposed to and then correct it. The picture you get as output should be the exact thing saved when you do writePictureTo - Bobby Mathew

Ok, when I took out show and return, and then replaced with writePictureTo, it worked. Can you explain why and what I was doing wrong? For my final submission, should I include show and return in the main function(I know to take out the write picture part)?Also, what picture are we supposed to upload using webwork, the completed montage, or the single image we used to create the collage?

Your main function should end returning a picture. Please do not put show in your final submission. I don't know why it didn't work, but it probably has to do with the way you were calling the function at the bottom. You must include all the images that are required to run your function when you turn it in. -Blake O'Hare

this may be a stupid question... but what does this mean? It shows up after i try to type in "montage()" at the bottom...

Picture, filename C:\Documents and Settings\Stephanie Butler\My Documents\My Pictures\Picture\cat8.jpg height 475 width 640
Picture, filename height 480 width 640
I wasn't able to do what you wanted.
The error java.lang.ArrayIndexOutOfBoundsException has occured
Please check line 13 of C:\Documents and Settings\Stephanie Butler\My Documents\hw2.py

It probably means that your canvas is not big enough for the 8 pictures. Make sure your canvas is big enough for the 4 images and the mirrored 4 images. - Bobby Mathew

OK, so I'm all done with my code, and I'm trying to run this stupid thing, and when it finishes running, it highlights the line where I define what pbottom is in my mirroring code, and gives me this:
>>> montage()
Picture, filename C:\Documents and Settings\Owner\Desktop\persian.jpg height 170 width 200
Picture, filename height 380 width 850
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 check line 77 of C:\Documents and Settings\Owner\My Documents\Computer Science\hw2.py

Check your mirroring function and the place where you're calling it in your montage function. Chances are you made a syntax error while calling the function or didn't input the right parameters or you're using a variable like pbottom which you haven't mentioned anywhere else in your code. - Bobby Mathew

by the way, here's my code for the mirroring function. in my montage function, all i have is on the second to last line before return(canvas), i have mirrorIt(canvas)
def mirrorIt(pic):
  mirrorpoint = int(getHeight(pic)/2)
  for yOffset in range(1, mirrorpoint):
    for xOffset in range(1, getWidth(pic)):
      pbottom = getPixel(pic, x, yOffset + mirrorpoint)
      ptop = getPixel(pix, x, mirrorpoint - yOffset)
      newcolor = getColor(ptop)
      setColor(pbottom, newcolor)

Ok, ignore my last reply. Your second 'for' loop should be 'for x in range(.......). Don't use xOffset because you're not using that anywhere. - Bobby Mathew

where are the slides that she went over in class that explained how to transfer pixels from one source to another?
I don't know, i can't find it. Its in the book. - Bobby Mathew

I don't know if it is too late to ask a question about HW2 but here goes... when I finish all my code and type:"show(montage())" Then I get the responce that the input it "not a picture" an the error of trying to pass an argument to a function.




Link to this Page