Ders Çalışması - 31 Ekim
import matplotlib.pyplot as plt
import numpy as np
import numpy as np
img_1=plt.imread("b1.jpg")
img_1.ndim
img_1.shape
plt.imshow(img_1)
plt.show()
img_1.ndim
img_1.shape
plt.imshow(img_1)
plt.show()
import os
lista=[]
listb=[]
listc=[]
listd=[]
for i in os.listdir(): #parantez içine dosya uzantısı yazmayınca varsayılan dizinde işlem yapar -kubra da
if i.endswith('.jpg'):
if i[0]=='a':
lista.append(i)
#print(i)
if i[0]=='b':
listb.append(i)
#print(i)
if i[0]=='c':
listc.append(i)
#rint(i)
if i[0]=='d':
listd.append(i)
#print(i)
print(lista)
print(listb)
print(listc)
print(listd)
Out[8]:
lista=[]
listb=[]
listc=[]
listd=[]
for i in os.listdir(): #parantez içine dosya uzantısı yazmayınca varsayılan dizinde işlem yapar -kubra da
if i.endswith('.jpg'):
if i[0]=='a':
lista.append(i)
#print(i)
if i[0]=='b':
listb.append(i)
#print(i)
if i[0]=='c':
listc.append(i)
#rint(i)
if i[0]=='d':
listd.append(i)
#print(i)
print(lista)
print(listb)
print(listc)
print(listd)
Out[8]:
['a1.jpg', 'a2.jpg', 'a3.jpg', 'a4.jpg', 'a5.jpg']
['b1.jpg', 'b2.jpg', 'b3.jpg', 'b4.jpg', 'b5.jpg']
['c1.jpg', 'c2.jpg', 'c3.jpg', 'c4.jpg', 'c5.jpg']
['d1.jpg', 'd2.jpg', 'd3.jpg', 'd4.jpg', 'd5.jpg']
['b1.jpg', 'b2.jpg', 'b3.jpg', 'b4.jpg', 'b5.jpg']
['c1.jpg', 'c2.jpg', 'c3.jpg', 'c4.jpg', 'c5.jpg']
['d1.jpg', 'd2.jpg', 'd3.jpg', 'd4.jpg', 'd5.jpg']
##DENEME
img_1=plt.imread(lista[0])
img_1.ndim
img_1.shape
Out[8]: (182, 251, 3)
img_1=plt.imread(lista[0])
img_1.ndim
img_1.shape
Out[8]: (182, 251, 3)
def resimleri_BW_yapma_center_bulma(liste):
for i in range(len(liste)):
img_1=plt.imread(liste[i])
img_1.ndim
img_1.shape
img_2=np.zeros((img_1.shape[0:2]))
img_2.shape
img_3=np.zeros((img_1.shape[0:2]))
img_3.shape
img_4=np.zeros((img_1.shape[0:2]))
img_4.shape
for i in range(len(liste)):
img_1=plt.imread(liste[i])
img_1.ndim
img_1.shape
img_2=np.zeros((img_1.shape[0:2]))
img_2.shape
img_3=np.zeros((img_1.shape[0:2]))
img_3.shape
img_4=np.zeros((img_1.shape[0:2]))
img_4.shape
threshold=200
for i in range(img_1.shape[0]):
for j in range(img_1.shape[1]):
n=img_1[i,j,0]/3+img_1[i,j,1]/3+img_1[i,j,2]/3 #gray level yapma
img_2[i,j]=n
if n>threshold: # BW yapma
img_3[i,j]=255
else:
img_3[i,j]=0
for k in range(img_3.shape[0]):
for t in range(img_3.shape[1]):
img_4[k,t]=img_4[k,t]+img_3[k,t]/5
center=img_4
print(center)
return center
centerA=resimleri_BW_yapma_center_bulma(lista)
centerB=resimleri_BW_yapma_center_bulma(listb)
centerC=resimleri_BW_yapma_center_bulma(listc)
centerD=resimleri_BW_yapma_center_bulma(listd)
Out[12]:
for i in range(img_1.shape[0]):
for j in range(img_1.shape[1]):
n=img_1[i,j,0]/3+img_1[i,j,1]/3+img_1[i,j,2]/3 #gray level yapma
img_2[i,j]=n
if n>threshold: # BW yapma
img_3[i,j]=255
else:
img_3[i,j]=0
for k in range(img_3.shape[0]):
for t in range(img_3.shape[1]):
img_4[k,t]=img_4[k,t]+img_3[k,t]/5
center=img_4
print(center)
return center
centerA=resimleri_BW_yapma_center_bulma(lista)
centerB=resimleri_BW_yapma_center_bulma(listb)
centerC=resimleri_BW_yapma_center_bulma(listc)
centerD=resimleri_BW_yapma_center_bulma(listd)
Out[12]:
[[ 51. 51. 51. ..., 51. 51. 51.]
[ 51. 51. 51. ..., 51. 51. 51.]
[ 51. 51. 51. ..., 51. 51. 51.]
...,
centerA.ndim, centerA.shape
Out[12]: (2, (182, 251))
[ 51. 51. 51. ..., 51. 51. 51.]
[ 51. 51. 51. ..., 51. 51. 51.]
...,
centerA.ndim, centerA.shape
Out[12]: (2, (182, 251))
centerB[0,0:30]
Out[17]:
array([ 51., 51., 51., 51., 51., 51., 51., 51., 51., 51., 51.,
51., 51., 51., 51., 51., 51., 51., 51., 51., 51., 51.,
51., 51., 51., 51., 51., 51., 51., 51.])
51., 51., 51., 51., 51., 51., 51., 51., 51., 51., 51.,
51., 51., 51., 51., 51., 51., 51., 51.])
def distance(A,B):
c=A-B
d=c.sum()
return d
c=A-B
d=c.sum()
return d
d=distance(centerC,centerD)
d
Out[31]: 33864.0
d
Out[31]: 33864.0
d.sum()
Out[25]: -36516.0
Out[25]: -36516.0
Yorumlar
Yorum Gönder