Answered You can hire a professional tutor to get the answer.

QUESTION

import numpy as np import matplotlib.pyplot as plt #load an image I = plt.imread('C:\Users\Tina\Desktop\image.jpg') #display the shape of the array...

import numpy as np

import matplotlib.pyplot as plt

#load an image

I = plt.imread('C:UsersTinaDesktopimage.jpg')

#display the shape of the array and data type

print("I.shape=",I.shape,"nI.dtype=",I.dtype)

#convert to float data type and scale to [0..1] if necessary

if (I.dtype == np.uint8):

  I = I.astype(float) / 256

#I.dtype should now be float

#if your image is color (shape HxWx3), convert to grayscale by averaging together R,G,B values

R = np.array(img[:, :, 0])

G = np.array(img[:, :, 1])

B = np.array(img[:, :, 2])

R = (R *.299)

G = (G *.587)

B = (B *.114)

np.mean

#display the image in the notebook using a grayscale colormap

plt.imshow(I,cmap=plt.cm.gray)

#force matplotlib to go ahead and display the plot now

plt.show()  

#select out a 100x100 pixel subregion of the image

w,h = I.size

A = I.crop((w-50, h-50, w+50, h+50))

#display the selected subregion

plt.imshow(A,cmap=plt.cm.gray)

plt.show()

I am not sure if I am doing this right.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question