This lab assignment will have you write at least two functions in jython that will create a new image that will show a portion from another image. This technique is called cropping.
In the ACCC Labs that have JES, it can be found by:
Cropping of an image is to take a certain part of image and discard the rest of the image. Once the user has picked an image, we shall create an empty image which will store the resulting cropped image. Then we shall copy the pixels from the part of the original to the new image. "Copying the pixels" is nothing but copying the colors of pixels from original image to the new image. Here is a program to do this:
def cropImage(): #Allow the user to pick up an image file file = pickAFile() #print the file name user chose print file #now convert the image in JES format pic = makePicture(file) # decide the size of new image newWidth = 100 newHeight = 150 #now create a new image in JES format new_pic = makeEmptyPicture(newWidth, newHeight) # now decide starting with which part of image # we should crop the image start_x = 50 start_y = 100 # so we will crop the image starting from pixel # at row 100 column 50 and size of the image would be # 100 columns and 150 rows. for x in range(1, newWidth+1): for y in range(1, newHeight+1): # get pixel from original image orig_pixel = getPixel(pic, x+start_x, y+start_y); # get pixel from new image new_pixel = getPixel(new_pic, x, y); # get the color from original pixel c = getColor(orig_pixel) # set the color of new pixel to c setColor(new_pixel, c) # Now display the new image show(new_pic) # save the new image writePictureTo(new_pic, pickAFile()) |
Create a file using JES that will:
Each call will send the image selected by the user but must crop a different section of the image and crop a different sized section image. You are to crop an interesting item from the original image and not just some random location. You will also be required to submit your image with your JES program file. The BlendIn.jpg image offers a few interesting spots that could be cropped. You may use this image or any other image of your choosing. You may wish to use the JES pictureTool to help find the x and y coordinates of different interesting sections of an image.