Professional Documents
Culture Documents
Import As Import As Import As
Import As Import As Import As
Import As Import As Import As
In [31]: img=mpimage.imread('C:/Users/admin/Desktop/PVT/test_images/peppers_color.jpg')
In [32]: plt.figure(1)
plt.imshow(img)
In [20]: np.shape(img)
In [33]: img.dtype
Out[33]: dtype('uint8')
In [17]: img_R=img[:,:,0]
plt.imshow(img_R,cmap='gray')
In [24]: img[100,100,1]
Out[24]: 22
localhost:8888/nbconvert/html/Desktop/PVT/FDP-Day1.ipynb?download=false 1/5
7/27/2021 FDP-Day1
In [10]: np.shape(img_R)
In [18]: img_G=img[:,:,1]
plt.imshow(img_G,cmap='gray')
In [19]: img_B=img[:,:,2]
plt.imshow(img_B,cmap='gray')
In [25]: newimg=np.zeros(np.shape(img))
In [26]: np.shape(newimg)
In [28]: newimg[:,:,0]=img_R
plt.figure(2)
plt.imshow(newimg)
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats o
r [0..255] for integers).
localhost:8888/nbconvert/html/Desktop/PVT/FDP-Day1.ipynb?download=false 2/5
7/27/2021 FDP-Day1
In [34]: newimg.dtype
Out[34]: dtype('float64')
In [35]: newimg=newimg.astype('uint8')
In [36]: newimg.dtype
Out[36]: dtype('uint8')
In [37]: plt.figure(2)
plt.imshow(newimg)
In [38]: newimg[:,:,1]=img_G
plt.figure(3)
plt.imshow(newimg)
localhost:8888/nbconvert/html/Desktop/PVT/FDP-Day1.ipynb?download=false 3/5
7/27/2021 FDP-Day1
r,g,b=inp[:,:,0],inp[:,:,1],inp[:,:,2]
gray=0.2989*r+0.5870*g+0.1140*b
return gray
img_gray=rgb2gray(img)
plt.figure(4)
plt.imshow(img_gray,cmap='gray')
In [45]: plt.hist(img_gray)
plt.xlabel('graylevels')
plt.ylabel('frequency of graylevels')
localhost:8888/nbconvert/html/Desktop/PVT/FDP-Day1.ipynb?download=false 4/5
7/27/2021 FDP-Day1
In [48]: img_gray=img_gray+60;
plt.figure(5)
plt.imshow(img_gray,cmap='gray')
plt.figure(6)
plt.hist(img_gray)
plt.xlabel('graylevels')
plt.ylabel('frequency of graylevels')
plt.xlim([0,255])
In [ ]:
localhost:8888/nbconvert/html/Desktop/PVT/FDP-Day1.ipynb?download=false 5/5