We can read and display images in Python as follows. import numpy as np import s
ID: 3677988 • Letter: W
Question
We can read and display images in Python as follows. import numpy as np import scipy.misc as sm import matplotlib.pyplot as plt from matplotlib.pyplot import figure,imshow,gray, title u=sm.imread('barbara_512.png', 1) figure(); imshow(u); gray(); title('Barbara') ; plt.show() In image processing we can think of the image u as a function of two variables u(x, y) defined on some region ohm R^2. While implementing some algorithms, one has to maintain proper boundary conditions. For example, Neumann boundary condition implies that u. n = 0 on the boundary deltaohm, where n is the outward pointing unit normal to the boundary. One way to achieve this is to extend the boundary by some factor. For example. if u is a 512 Times 512 image, we obtain another image U with size 514 Times 514. The image U is obtained expanding the image u by 1 pixel unit on all four sides, and the expansion is done by repeating the boundary values. i.e. the image U has top two rows same as the first row of u, bottom two rows same as the bottom row of u, and so one. Write a python function shrink(U, n), which expands the image U by n pixels on all four sides.Explanation / Answer
#define function shrink(U,n)
import PIL<br>from PIL import Image
basewidth = n<br>img = Image.open(‘U.jpg’) // setting pixels to basewidth and oening image U
<br>wpercent = (basewidth / float(img.size[0]))<br>hsize =
int((float(img.size[1]) * float(wpercent)))<br>img =
img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
<br>img.save(‘resized_image.jpg’)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.