Question: Write a function extract(pixels, rmin, rmax, cmin, cmax) that takes the 2-D list pixels containing pixels for an image, and that creates and returns a

Write a function extract(pixels, rmin, rmax, cmin, cmax) that takes the 2-D list pixels containing pixels for an image, and that creates and returns a new 2-D list that represents the portion of the original image that is specified by the other four parameters. The extracted portion of the image should consist of the pixels that fall in the intersection of

the rows of pixels that begin with row rmin and go up to but not including row rmax

the columns of pixels that begin with column cmin and go up to but not includingcolumn cmax.

For example, if you do the following:

>>> pixels = load_pixels('spam.png') >>> extracted = extract(pixels, 90, 150, 75, 275) >>> save_pixels(extracted, 'extract_spam.png') extract_spam.png saved. 

you should obtain the following image:

To verify your image:

>>> compare_images('extract_spam.png', 'extract_expected.png') extract_spam.png and extract_expected.png are identical. 

Notes/hints:

Here again, your function will need to create and return a new 2-D list of pixels, and you can use the blank_image() function for that purpose. Compute the dimensions of the new image from the inputs to the function.

Dont forget that the rmax and cmax parameters are exclusive, which means that the extracted image should not include pixels from row rmax or column cmax of the original image. This is similar to what happens when you slice a string or list, and it should make it easier to compute the dimensions of the image.

One way to solve this problem is to use nested loops to iterate over the rows and columns of the newly created 2-D listthe one that represents the extracted image. You can then perform the necessary computations on your loop variables r and c to determine the cooordinates of the pixel from the original image that you should use for the pixel at position (r, c) in the new image. Use concrete cases to determine the appropriate computations.

SPAM SPAM

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!