utworzone pliki projektu indywidualnego
BIN
etykiety.h5
Normal file
BIN
parametry_zdjec.h5
Normal file
Before Width: | Height: | Size: 9.4 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 118 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 8.9 KiB |
Before Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 5.0 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 9.4 KiB |
70
tworzenie_danych_AO.py
Normal file
@ -0,0 +1,70 @@
|
||||
from sklearn.preprocessing import LabelEncoder
|
||||
import numpy as np
|
||||
import mahotas
|
||||
import cv2
|
||||
import os
|
||||
import h5py
|
||||
|
||||
rozmiar_zdj = tuple((500, 500))
|
||||
sciezka_do_zdj = "resources/smieci_stare"
|
||||
h5_dane = 'parametry_zdjec.h5'
|
||||
h5_etykiety = 'etykiety.h5'
|
||||
|
||||
|
||||
def hu_moments(zdj):
|
||||
zdj = cv2.cvtColor(zdj, cv2.COLOR_BGR2GRAY)
|
||||
momenty = cv2.HuMoments(cv2.moments(zdj)).flatten()
|
||||
return momenty
|
||||
|
||||
|
||||
def haralick(zdj):
|
||||
szare_zdj = cv2.cvtColor(zdj, cv2.COLOR_BGR2GRAY)
|
||||
haralick = mahotas.features.haralick(szare_zdj).mean(axis=0)
|
||||
return haralick
|
||||
|
||||
|
||||
def histogram(zdj, mask=None):
|
||||
zdj = cv2.cvtColor(zdj, cv2.COLOR_BGR2HSV)
|
||||
hist = cv2.calcHist([zdj], [0, 1, 2], mask, [8, 8, 8], [0, 256, 0, 256, 0, 256])
|
||||
cv2.normalize(hist, hist)
|
||||
return hist.flatten()
|
||||
|
||||
|
||||
klasy = os.listdir(sciezka_do_zdj)
|
||||
|
||||
klasy.sort()
|
||||
|
||||
dane = []
|
||||
wszystkie_typy_zdj = []
|
||||
|
||||
for klasa in klasy:
|
||||
katalog = os.path.join(sciezka_do_zdj, klasa)
|
||||
|
||||
biezaca_klasa = klasa
|
||||
for plik in os.listdir(katalog):
|
||||
zdj = cv2.imread(os.path.join(katalog, plik))
|
||||
zdj = cv2.resize(zdj, rozmiar_zdj)
|
||||
|
||||
fv_hu_moments = hu_moments(zdj)
|
||||
fv_haralick = haralick(zdj)
|
||||
fv_histogram = histogram(zdj)
|
||||
|
||||
wiersz = np.hstack([fv_hu_moments, fv_histogram, fv_haralick])
|
||||
wszystkie_typy_zdj.append(biezaca_klasa)
|
||||
dane.append(wiersz)
|
||||
|
||||
print(len(wszystkie_typy_zdj))
|
||||
targetNames = np.unique(wszystkie_typy_zdj)
|
||||
print(targetNames,targetNames.shape)
|
||||
le = LabelEncoder()
|
||||
target = le.fit_transform(wszystkie_typy_zdj)
|
||||
print(target.shape)
|
||||
|
||||
h5f_data = h5py.File(h5_dane, 'w')
|
||||
h5f_data.create_dataset('dataset_1', data=np.array(dane))
|
||||
|
||||
h5f_label = h5py.File(h5_etykiety, 'w')
|
||||
h5f_label.create_dataset('dataset_1', data=np.array(target))
|
||||
|
||||
h5f_data.close()
|
||||
h5f_label.close()
|