{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt \nimport seaborn as sns\nimport cv2\nimport random\nplt.show()\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"*Due to the fact that wheat has been selected from all over the world, there are a couple of ideas on how to convert the color.*\n\n p.s. I am from Russia and my English is not very good.","execution_count":null},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"path = '../input/global-wheat-detection/'\npath_img = '../input/global-wheat-detection/train/'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def Df_info(df):\n    print('Size = ', *df.shape)\n    print('Count null values', df.isnull().sum().sum())\n    print('Count unique Id', len(df.image_id.unique()))\n    \ndef random_images(df):   \n    fig , ax = plt.subplots(2, 2, figsize = (12,12))\n    name = random.choice(df.image_id.unique())\n    ax[0][0].imshow(cv2.imread(path_img + name + '.jpg')[...,[2,1,0]])\n    ax[0][0].set_title('Id: '+ name, fontsize=14)\n    name = random.choice(df.image_id.unique())\n    ax[0][1].imshow(cv2.imread(path_img + name + '.jpg')[...,[2,1,0]])\n    ax[0][1].set_title('Id: '+ name, fontsize=14)\n    name = random.choice(df.image_id.unique())\n    ax[1][0].imshow(cv2.imread(path_img + name + '.jpg')[...,[2,1,0]])\n    ax[1][0].set_title('Id: '+ name, fontsize=14)\n    name = random.choice(df.image_id.unique())\n    ax[1][1].imshow(cv2.imread(path_img + name + '.jpg')[...,[2,1,0]])\n    ax[1][1].set_title('Id: '+ name, fontsize=14)    \n    plt.show()\n    \ndef images_from_sourse(source, df):  \n    df = df.loc[df['source'] == source]\n    fig , ax = plt.subplots(1, 4, figsize = (35,35))\n    name = random.choice(df.image_id.unique())\n    ax[0].imshow(cv2.imread(path_img + name + '.jpg')[...,[2,1,0]])\n    ax[0].set_title(source + ' id: '+ name, fontsize=14)\n    name = random.choice(df.image_id.unique())\n    ax[1].imshow(cv2.imread(path_img + name + '.jpg')[...,[2,1,0]])\n    ax[1].set_title(source + ' id: '+ name, fontsize=14)\n    name = random.choice(df.image_id.unique())\n    ax[2].imshow(cv2.imread(path_img + name + '.jpg')[...,[2,1,0]])\n    ax[2].set_title(source + ' id: '+ name, fontsize=14)\n    name = random.choice(df.image_id.unique())\n    ax[3].imshow(cv2.imread(path_img + name + '.jpg')[...,[2,1,0]])\n    ax[3].set_title(source + ' id: '+ name, fontsize=14)\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df = pd.read_csv(path + 'train.csv')\nsample_submission = pd.read_csv(path + 'sample_submission.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Df_info(train_df)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"random_images(train_df)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for source in train_df.source.unique():\n    print(source)\n    images_from_sourse(source, train_df)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def R_G_B_statics(source, df):\n    df = df.loc[df['source'] == source]\n    R = 0\n    G = 0\n    B = 0\n    for id in df.image_id.unique():\n        img = cv2.imread(path_img + id + '.jpg')\n        R += np.mean(img[:,:,2])\n        G += np.mean(img[:,:,1])\n        B += np.mean(img[:,:,0])\n    R = R/len(df.image_id.unique())\n    G = G/len(df.image_id.unique())\n    B = B/len(df.image_id.unique())\n    return R, G, B","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for source in train_df.source.unique():\n    print(source)\n    print(R_G_B_statics(source, train_df))\n    print('*'*100)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"R_mean = 0\nG_mean = 0\nB_mean = 0\nfor id in train_df.image_id.unique():\n    img = cv2.imread(path_img + id + '.jpg')\n    R_mean += np.mean(img[:,:,2])\n    G_mean += np.mean(img[:,:,1])\n    B_mean += np.mean(img[:,:,0])\nR_mean = R_mean/len(train_df.image_id.unique())\nG_mean = G_mean/len(train_df.image_id.unique())\nB_mean = B_mean/len(train_df.image_id.unique())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def color_conversion(img, R_mean, B_mean, G_mean):\n    img = img\n    blue = img[:,:,0]\n    green = img[:,:,1]\n    red = img[:,:,2]\n    mean_blue = np.mean(blue)\n    mean_red = np.mean(red)\n    mean_green = np.mean(green)\n    for i in range(0, blue.shape[0]):\n        for j in range(0, blue.shape[1]):\n            blue[i][j] = np.minimum((blue[i][j]/mean_blue)*B_mean, 255)\n            green[i][j] = np.minimum((green[i][j]/mean_green)*G_mean, 255)\n            red[i][j] = np.minimum((red[i][j]/mean_red)*R_mean, 255)\n    img = cv2.merge((blue, green, red))\n    return img","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(2,3, figsize=(15,15))\nimg_1 = cv2.imread(path_img + '4c572095f' + '.jpg')\nimg_2 =  cv2.imread(path_img + '00b70a919' + '.jpg')\nimg_3 = cv2.imread(path_img +  '6c9cf179f' + '.jpg') \nax[0][0].imshow(img_1[...,[2,1,0]])\nax[0][0].set_title('original_img '+ ' id: '+ '00e903abe', fontsize=14)\nax[0][1].imshow(img_2[...,[2,1,0]])\nax[0][1].set_title('original_img '+ ' id: '+ '00b70a919', fontsize=14)\nax[0][2].imshow(img_3[...,[2,1,0]])\nax[0][2].set_title('original_img '+ ' id: '+ '6c9cf179f', fontsize=14)\nax[1][0].imshow(color_conversion(img_1, R_mean, B_mean, G_mean)[...,[2,1,0]])\nax[1][0].set_title('color_conversion_img '+ ' id: '+ '00e903abe', fontsize=14)\nax[1][1].imshow(color_conversion(img_2, R_mean, B_mean, G_mean)[...,[2,1,0]])\nax[1][1].set_title('color_conversion_img '+ ' id: '+ '00e903abe', fontsize=14)\nax[1][2].imshow(color_conversion(img_3, R_mean, B_mean, G_mean)[...,[2,1,0]])\nax[1][2].set_title('color_conversion_img '+ ' id: '+ '6c9cf179f', fontsize=14)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}