16 Kasım 2017 Perşembe

5 Ekim 2017 Perşembe Görüntü İşleme - Python - Resmin Negatifini, Transpozesini Alan Kod

import matplotlib.pyplot as plt
import matplotlib.image as mypimg
import numpy as np

img=mypimg.imread(r'C:\Users\ezgi\Desktop\stinkbug.png')  #resmi okuma

img.ndim
# 3

img.shape
# (375, 500, 3)

plt.imshow(img)  # resmi gösterme
plt.show()


maxPixelDeger=img[:1,100,2:].max()
maxPixelDeger
# 0.49411765

img_1=img[1:375:2,:,:]
plt.imshow(img_1)
plt.show()


img_2=img[:,1:500:2,:]
plt.imshow(img_2)
plt.show()



#üç resimi göstermek için
plt.subplot(1,3,1),plt.imshow(img) 
plt.subplot(1,3,2),plt.imshow(img_1)
plt.subplot(1,3,3),plt.imshow(img_2)
plt.show()


img.ndim,img.shape
# (3, (375, 500, 3))

img_20=np.zeros((500,375,3))
img_20.shape
img_20.ndim,img_20.shape
# (3, (500, 375, 3))

for i in range(375):
    for j in range(500):
        img_20[j,i,:]=img[i,j,:]   #resmin transpozesini aldık

plt.imshow(img_20)
plt.show()


img_30=np.zeros((500,375,3))
img_30.shape
for i in range(375):
    for j in range(500):
        img_30[j,i,:]=1-img[i,j,:] # 1- ile negatifini aldık

#üç resimi göstermek için
plt.subplot(1,3,1),plt.imshow(img)
plt.subplot(1,3,2),plt.imshow(img_20)
plt.subplot(1,3,3),plt.imshow(img_30)
plt.show()


#4 resimi göstermek için
plt.subplot(2,3,1),plt.imshow(img)
plt.subplot(2,3,2),plt.imshow(img_20)
plt.subplot(2,3,3),plt.imshow(img_30)
plt.subplot(2,3,4),plt.imshow(img_30)
plt.show()


img_40=np.zeros((375,500,3))
img_40.shape
for i in range(375):
    for j in range(500):
        img_40[375-i-1,500-j-1,:]=1-img[i,j,:]  #Resmin negatifini aldık

img_50=np.zeros((375,500,3))
img_50.shape
for i in range(375):
    for j in range(500):
        img_40[375-i-1,j,:]=1-img[i,j,:]

#5 resimi göstermek için
plt.subplot(2,3,1),plt.imshow(img)
plt.subplot(2,3,2),plt.imshow(img_20)
plt.subplot(2,3,3),plt.imshow(img_30)
plt.subplot(2,3,4),plt.imshow(img_40)
plt.subplot(2,3,5),plt.imshow(img_50)
plt.show()

Hiç yorum yok:

Yorum Gönder