K0nkere / DL_Dice-detection-project

DnD dice detection with CNN and transfer learning / Project for ML Bookcamp
0 stars 0 forks source link

How to: EDA for images, analisys of RGB color distribution #4

Open K0nkere opened 1 year ago

K0nkere commented 1 year ago
def histogram(df, name):
    red = []; green = []; blue = []
    for i in tqdm(df.index):
        img_path = './images/' + df['image_id'][i] + '.jpg'
        img = tf.keras.preprocessing.image.load_img(img_path)
        x = np.array(img)
        red.append(np.mean(x[0][:,0])); green.append(np.mean(x[0][:,1])); blue.append(np.mean(x[0][:,2]))
    df['redm']= red; df['greenm']= green; df['bluem']= blue

    plt.figure(figsize = (10,5))
    sns.histplot(df.redm.values, bins=80, color='red', alpha=0.3, kde=True)
    sns.histplot(df.greenm.values, bins=80, color='green', alpha=0.3, kde=True)
    sns.histplot(df.bluem.values, bins=80, color='blue', alpha=0.3, kde=True)
    plt.ylabel('Frequency')
    plt.xlabel('Intensity')
    plt.title('Distribution of colors in %s dataset' % name)