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 Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 1 Review Fall 2003: Scaling with input

(Back to Fall2003 Midterm Review 1)

Answers? Comments? Comments on answers?


Ok, I've been trying to figure out this problem and this is what I've been able to figure out so far.
A) The picture would be halved because, in this case, the factor is actually multiplied by the target x and y. Only every other pixel would appear. The first four lines printed would be as follows:
Copying from 45,25 to 100,100
Copying from 45,27 to 100,101
Copying from 45,29 to 100,102
Copying from 45,31 to 100,103
B) The picture would double in size and every pixel would appear twice in the canvas. The first four printed lines would be as follows:
Copying from 45,25 to 100,100
Copying from 45,25 to 100,101
Copying from 45,26 to 100,102
Copying from 45,26 to 100,103
C) Still working on part C; I'm not sure how to go about evaluating the 1.5. I'll post my work on that later.

C) The picture would enlarge by 50%. The first four lines would read as follows:
Copying fr0m 45,25 to 100,100
Copying from 45,26 to 100,101
Copying from 45,26 to 100,102
Copying from 45,27 to 100,103.
It seems like it would take other pixel twice. Not really sure.

Can someone that understands go through this process step by step?

Towards the end of the Midterm Exam Review, we got a great explanation of this problem, anyone care to share?!

we are forgetting that the source Y is multiplied by (1.0/factor). There is one floating point so, the first print statement will be:
copying from 45,25 to 100,100
but the next one will be
copying from 45,27.0 to 100,100
and so on remembering the sourceY floating decimal


Saying 1.0 doesn't make it only one floating point, does it? I think it just means that JES will deal in floating point numbers, rather then in only integers.

Can someone please go over part C?

If you use floating point numbers in your calculation, Python will compute with decimal points. But when you use them in coordinates, it will only use the integer portion. Mark Guzdial


Since python will compute with decimal points, then the print function will also show the decimal points

C) Enlarge the picture by 50%.
Copying from 45,25 to 100,100
Copying from 45,25.633 to 100, 101 (here the program however is using the same coordinate as before 45,25 and copying it to 100,101). In other words the program is actually doing Copying from 45,25 to 100,101)

Copying from 45,26.333 to 100,102
.
.
.


Hey people! On C: 1/1.5 does not equal .75! It equals approximately .6667!
Exactly. So for C, think of how you would count it straight: 25, 25 2/3, 26 1/3, 27. Then translate that...
  • Also, try to describe the pictures by using phrases like "enlarge/shrink by XX%" and "crop from x to y". It might help you order your thoughts better and be more understandable. Clarity definitely counts for a lot when we have to grade your explanations.
Lauren Biddle

It took the TA's a long time to figure this problem out in yesterday's review session. It's a long problem, is this going to be on the exam?


The function 1/factor is another way of presenting the ratio of (source pixels)/(target pixels). So a ratio of 1/1.5 is actually (in fraction form) a ratio of (2 source pixels)/(3 target pixels). So for every two source pixels, one is represented twice and the other is represented once, but both are represented. Similarly, in 1/0.5 (2/1), for every two source pixels, only one is represented. The general rule for increasing scales (say 11 times), is that each pixel is given equal preference (in division) and the remainder is distributed randomly (I think.) Come to think of it, this sounds more like a math theorem than a simple method. But it's too late for this to help now, so whatever.

I dont understand why in A, the picture is halved? I thought that A would double the size and B would reduce the size by half.

Somebody please answer my question, it will help the rest of you out,l who are aimlessly still trying to figure this problem out. Thank you and good luck on the exam, everyone. Remember to drink milk before the exam, acutally whole is great for you.

Okay. The function of incrementation is 1/factor because the target needs to be .5 the size of the source. So the source would actually be 2 times the target. In my statement above, this relationship applies to the number of pixels represented. Take a factor of 0.5. Logically, the source would have 2 times the number of pixels of the target, so you do 1/.5 as the increment and get sourcex = sourcex + 2. So every other source pixel would get into the target pixel.
Demo: increment(source) = {1,2,3,4,5,6} and increment(source + 2) = {1,3,5}.
The bottom line is, you have to get the reciprocal of the factor (1/factor) to get the ratio of (source size)/(target size).

Addon: 1/.5 = 2/1 which is the ratio you want for (source)/(target) in a shrinking case.
and 1/2 = 1/2 which is the ratio for (source)/(target) in an enlarging case.
and of course, 1/1.5 = 2/3, meaning that for every two pixels of source, there are three pixels of target.

Addon: After years of conditioning to skim, I can't drink whole milk.



ok. so for part A. the picture is enlarged by 1.5 times the original size?

please tell me right or wrong.
Ashley Hansen

For those of you who can't seem to get this nested for loop stuff, here is a real life example:
def race4Cars():
   for car in race(1,5):
     for tire in car(1,5):
       put tire on the car
       print tire
       if tire == 4:
         "This car is ready to race"
       if tire < 4:
         "This car needs more tires"
     start car
     prepare to race
   race cars

1 and 2 lines of code: There are 4 cars racing a race, for each car you must have some race cars, we have 4.

3 thru 9 lines of code: Each car needs to have tires before it can continue with the race. Run through the loops when tire = 1, is the car ready for the race? NO, it has to run all the way through the range, thus getting its 4 tires. The if statements help you see how many tires the car has as you work through the loop.

10 and 11 lines of code: Now that we have gotten through the inner loop and the car has four tires, we can start car 1 and prepare car 1 to race. Then we return and do the same thing with
car 2, car 3 and car 4. Once we have prepared all 4 cars, we race!

Brittany Selden

The picture in part A is shrunk to half its original size. 1/0.5=2, so with a step of two, every other pixel will be transferred, putting only half the pixels into the target.

Actually, 1/4 of the pixels. It's 1/2 in each direction. Mark Guzdial

This question is ridiculous.

so then it's 1/4 of the original size?

Whew! Lucky I got that 1/(factor)^2 thing down



Link to this Page