For this project, the goal was to control entire images within a canvas, moving them around and providing different pieces of information about them such as which filter to use and whether or not the background should be there. Using various functions to manipulate image placement and other factors, we were able to make collages.
Task 1 consisted of making a function for getting information for each index in the collage image list and testing it for feedback. This meant that first, a list of images was made, and within the lists in that, we had a list of parameters for the image: filename, x offset, y offset, filter, alpha blend, background visibility (added later), and the pixmap file itself. Initially, each such index was given a value representing its index so that later, we could simply change the value of the parameters without having to change every instance of the parameter itself. I tested the function using the provided "testbuildcollage.py", which inputs a set of parameters and prints the values so we know that build collage is storing the correct data.
For Tasks 2-3, we had to create a function in our filter file that would place a picture into the bigger pixmap without including a background. Within said function, the width and height of the image was first obtained using for loops. Next, the alpha blend option (which blends two images together for an overlapping effect) was anticipated using variable assignment; (r1,g1,b1) was a given pixel in the image, (r2,g2,b2) was one ?the distance away of the x offset and y offset, and new rgb values were assigned to rnew, gnew, and bnew. To check if no background is wanted, however, the function uses an if-else statement, e.g. if the value provided for the index IDXbkg is True, place the image using placepixmapNoBkg, and if it is False, place it using placePixmap.This is illustrated in the code snippet below:
In Task 4, the first real image was actually assembled. This just meant making a new file with a function that would carry out all the steps to making a picture, then saving it. After, it could be viewed through show.py. Basically, the list is assembled within the function, then its information is passed along to the readImages and buildCollage functions. The images below show the function and the resulting image.
Task 5 was essentially the same, except this time, user input was required. The only difference was the images and their locations and the first item in the collage image list having the input filename be assigned to it. The program would require the name of a .ppm-format image, retrieved from the sys.argv list. The resulting image is shown below.
I also did extensions 2 and 5. For extension 2, I needed to make some kind of way for the program to tell if the background color was blue or green so it could remove it using the placePixmapNoBkg function. This required, first, a new index to be added to the lists, and also, the buildCollage function to be altered; if no background was requested and the green background variable was given (set if the swapRedBlue filter was not applied), then green would be taken out, and the same was done for blue, except it would mean that the red-blue switch filter was applied. In the placePixmapNoBkg function, I also simply swapped around the values of red and blue to change which color was to be specified as the background. The result is shown below:
For extension 5, I made it so however many images given in the command line would be assembled to make a collage according to a preset list with the coordinates, filters, and everything except for the image file. The code is displayed below; I mostly used if statements to achieve my goal.
Overall, this project taught me a lot about making and manipulating lists and tracing user input in the command line. I also learned how to place images within other images.
Worked with: Prof. Maxwell