├── Data_Preprocessing.ipynb ├── LICENSE ├── README.md ├── api ├── V1 │ ├── __pycache__ │ │ ├── imageprocess.cpython-38.pyc │ │ └── predictor.cpython-38.pyc │ ├── imageprocess.py │ ├── main.py │ ├── models │ │ ├── Applemodel_V1.sav │ │ ├── Tomatomodel_V1.sav │ │ ├── cornmodel_V1.sav │ │ ├── grapesmodel_V1.sav │ │ └── potatomodel_V1.sav │ ├── predictor.py │ ├── test │ │ ├── a1.JPG │ │ ├── a2.JPG │ │ ├── a3.JPG │ │ ├── a4.JPG │ │ ├── c5.jpg │ │ ├── c6.JPG │ │ ├── g7.JPG │ │ ├── g8.JPG │ │ ├── p10.JPG │ │ ├── p9.JPG │ │ ├── t11.JPG │ │ ├── t12.JPG │ │ └── t13.JPG │ └── testing_script.py ├── V2_flask_integration │ ├── __pycache__ │ │ ├── imageprocess.cpython-38.pyc │ │ └── predictor.cpython-38.pyc │ ├── app.py │ ├── imageprocess.py │ ├── models │ │ ├── Applemodel_V1.sav │ │ ├── Tomatomodel_V1.sav │ │ ├── cornmodel_V1.sav │ │ ├── grapesmodel_V1.sav │ │ └── potatomodel_V1.sav │ ├── predictor.py │ ├── static │ │ └── style1.css │ └── templates │ │ └── index.html ├── api testing │ ├── AppleCedarRust2.JPG │ ├── PotatoEarlyBlight1.JPG │ ├── PotatoHealthy1.JPG │ ├── TomatoEarlyBlight1.JPG │ └── TomatoYellowCurlVirus6.JPG └── v4_ibmcloud_failed │ ├── Dockerfile │ ├── Procfile │ ├── imageprocess.py │ ├── manifest.yml │ ├── models │ ├── Applemodel_V1.sav │ ├── Tomatomodel_V1.sav │ ├── cornmodel_V1.sav │ ├── grapesmodel_V1.sav │ └── potatomodel_V1.sav │ ├── predictor.py │ ├── requirements.txt │ ├── runtime.txt │ ├── server.py │ ├── setup.py │ ├── static │ └── style1.css │ └── templates │ └── index.html ├── da_and_md ├── apple │ ├── Apple_DA_and_MD.ipynb │ ├── Applemodel_V1.sav │ ├── acuuracyandf1.png │ ├── cf.png │ ├── correlation.png │ └── roc.png ├── corn │ ├── .ipynb_checkpoints │ │ └── Corn_DA_and_MD-checkpoint.ipynb │ ├── Corn_DA_and_MD.ipynb │ ├── accuracy.png │ ├── cf.png │ ├── cornmodel_V1.sav │ ├── correlation.png │ └── roc.png ├── grapes │ ├── accuracy.png │ ├── cf.png │ ├── correlation.png │ ├── grapes_DA_and_MD.ipynb │ ├── grapesmodel_V1.sav │ └── roc.png ├── potato │ ├── accuracy.png │ ├── cf.png │ ├── correlation.png │ ├── potato_DA_and_MD.ipynb │ ├── potatomodel_V1.sav │ └── roc.png └── tomato │ ├── Tomatomodel_V1.sav │ ├── accuracy.png │ ├── cf.png │ ├── correlation.png │ ├── roc.png │ └── tomato_DA_and_MD.ipynb ├── dataset ├── hist │ ├── apple.png │ ├── corn.png │ ├── grapes.png │ ├── potato.png │ └── tomato.png └── processed datasets │ ├── dataset_apple.xlsx │ ├── dataset_corn.xlsx │ ├── dataset_grapes.xlsx │ ├── dataset_potato.xlsx │ └── dataset_tomato.xlsx ├── process_image.py └── report ├── 1_g8.JPG ├── 2_greayscale.png ├── 3_blur.png ├── 4_otsus.png ├── 5_closing.png ├── closing.png ├── final_output.png ├── final_report └── COURSE PROJECT report.docx └── ipsteps.py /Data_Preprocessing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "OSEFD254k6ra" 7 | }, 8 | "source": [ 9 | "# Importing Libraries" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "id": "BXkvSCx8jYjU" 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "import os\n", 21 | "import cv2\n", 22 | "import numpy as np\n", 23 | "import pandas as pd\n", 24 | "from skimage.feature import greycomatrix, greycoprops\n", 25 | "from matplotlib import pyplot as plt\n", 26 | "%matplotlib inline\n", 27 | "from os import listdir\n", 28 | "from os.path import isfile, join" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": { 34 | "id": "xmPD16fSlDZZ" 35 | }, 36 | "source": [ 37 | "# Function to Create a new dataframe" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": { 44 | "id": "QFRdk1x_lAai" 45 | }, 46 | "outputs": [], 47 | "source": [ 48 | "def create_empty_df():\n", 49 | " df = pd.DataFrame()\n", 50 | " df['area'] = None\n", 51 | " df['perimeter'] = None\n", 52 | " df['red_mean'] = None\n", 53 | " df['green_mean'] = None\n", 54 | " df['blue_mean'] = None\n", 55 | " df['f1'] = None\n", 56 | " df['f2'] = None\n", 57 | " df['red_std'] = None\n", 58 | " df['green_std'] = None\n", 59 | " df['blue_std'] = None\n", 60 | " df['f4'] = None\n", 61 | " df['f5'] = None\n", 62 | " df['f6'] = None\n", 63 | " df['f7'] = None\n", 64 | " df['f8'] = None\n", 65 | " df['label'] = None\n", 66 | " return df" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": { 72 | "id": "Q68D0Eq3luq6" 73 | }, 74 | "source": [ 75 | "# Function to extract the features" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": null, 81 | "metadata": { 82 | "id": "E0mwRfQdluPf" 83 | }, 84 | "outputs": [], 85 | "source": [ 86 | "def feature_extractor(filename):\n", 87 | " '''\n", 88 | " input params: \n", 89 | " filename : path of the file that we want to process\n", 90 | "\n", 91 | " Output params:\n", 92 | " l : Feature vector\n", 93 | " '''\n", 94 | "\n", 95 | " try:\n", 96 | " main_img = cv2.imread(filename)\n", 97 | " img = cv2.cvtColor(main_img, cv2.COLOR_BGR2RGB)\n", 98 | " except:\n", 99 | " return \"Invalid\"\n", 100 | "\n", 101 | " #Preprocessing\n", 102 | " \n", 103 | "\n", 104 | " gs = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)\n", 105 | " blur = cv2.GaussianBlur(gs, (25,25),0)\n", 106 | " ret_otsu,im_bw_otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)\n", 107 | " kernel = np.ones((25,25),np.uint8)\n", 108 | " closing = cv2.morphologyEx(im_bw_otsu, cv2.MORPH_CLOSE, kernel)\n", 109 | "\n", 110 | " #Shape features\n", 111 | " contours, _ = cv2.findContours(closing,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)\n", 112 | " cnt = contours[0]\n", 113 | " M = cv2.moments(cnt)\n", 114 | " area = cv2.contourArea(cnt)\n", 115 | " if area==0:\n", 116 | " return \"Invalid\"\n", 117 | " perimeter = cv2.arcLength(cnt,True)\n", 118 | "\n", 119 | " current_frame = main_img\n", 120 | " filtered_image = closing/255\n", 121 | "\n", 122 | " #Elementwise Multiplication of range bounded filtered_image with current_frame\n", 123 | " current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 0] = np.multiply(current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 0], filtered_image) #B channel\n", 124 | " current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 1] = np.multiply(current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 1], filtered_image) #G channel\n", 125 | " current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 2] = np.multiply(current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 2], filtered_image) #R channel\n", 126 | "\n", 127 | " img = current_frame\n", 128 | "\n", 129 | "\n", 130 | " #Color features\n", 131 | " red_channel = img[:,:,0]\n", 132 | " green_channel = img[:,:,1] #show the intensities of green channe\n", 133 | " blue_channel = img[:,:,2]\n", 134 | "\n", 135 | " red_mean = np.mean(red_channel)\n", 136 | " green_mean = np.mean(green_channel)\n", 137 | " blue_mean = np.mean(blue_channel)\n", 138 | " #standard deviation for colour feature from the image. \n", 139 | " red_std = np.std(red_channel)\n", 140 | " green_std = np.std(green_channel)\n", 141 | " blue_std = np.std(blue_channel)\n", 142 | " \n", 143 | " #amt.of green color in the image\n", 144 | " gr = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)\n", 145 | " boundaries = [([30,0,0],[70,255,255])]\n", 146 | " for (lower, upper) in boundaries:\n", 147 | " mask = cv2.inRange(gr, (36, 0, 0), (70, 255,255))\n", 148 | " ratio_green = cv2.countNonZero(mask)/(img.size/3)\n", 149 | " f1=np.round(ratio_green, 2)\n", 150 | " #amt. of non green part of the image \n", 151 | " f2=1-f1\n", 152 | "\n", 153 | " #Texture features using grey level cooccurance matrix\n", 154 | " img=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n", 155 | " g=greycomatrix(img, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4])\n", 156 | "\n", 157 | " #with the help of glcm find the contrast\n", 158 | " contrast = greycoprops(g, 'contrast')\n", 159 | " f4=contrast[0][0]+contrast[0][1]+contrast[0][2]+contrast[0][3]\n", 160 | " #[0][3] represent no. of times grey level 3 appears at the right of 0\n", 161 | "\n", 162 | "\n", 163 | " #with the help of glcm find the dissimilarity \n", 164 | " dissimilarity = greycoprops(g, prop='dissimilarity')\n", 165 | " f5=dissimilarity[0][0]+dissimilarity[0][1]+dissimilarity[0][2]+dissimilarity[0][3]\n", 166 | "\n", 167 | " #with the help of glcm find the homogeneity\n", 168 | " homogeneity = greycoprops(g, prop='homogeneity')\n", 169 | " f6=homogeneity[0][0]+homogeneity[0][1]+homogeneity[0][2]+homogeneity[0][3]\n", 170 | "\n", 171 | " energy = greycoprops(g, prop='energy')\n", 172 | " f7=energy[0][0]+energy[0][1]+energy[0][2]+energy[0][3]\n", 173 | "\n", 174 | "\n", 175 | " correlation = greycoprops(g,prop= 'correlation')\n", 176 | " f8=correlation[0][0]+correlation[0][1]+correlation[0][2]+correlation[0][3]\n", 177 | "\n", 178 | "\n", 179 | "\n", 180 | " l = [area, perimeter, red_mean, green_mean, blue_mean,\n", 181 | " f1, f2, red_std, green_std, blue_std,\n", 182 | " f4,f5,f6,f7,f8]\n", 183 | " return l" 184 | ] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "metadata": { 189 | "id": "LVEOVsrZlJNN" 190 | }, 191 | "source": [ 192 | "# Function to process one folder" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": { 199 | "id": "YMXnaP7llM5-" 200 | }, 201 | "outputs": [], 202 | "source": [ 203 | "def process_folder(folderpath,df_f,label_f):\n", 204 | " '''\n", 205 | " input params:\n", 206 | " folderpath : Path of the folder that we want to process\n", 207 | " df_f = dataframe for specific disease\n", 208 | " label_f : label corresponding to the specific disease\n", 209 | "\n", 210 | " Output params:\n", 211 | " df_f = Dataframe consisting processed vectors\n", 212 | " '''\n", 213 | " imagelist = os.listdir(folderpath) # stores all the imagepaths in the python list\n", 214 | " for image in imagelist:\n", 215 | " imagepath = os.path.join(folderpath, image)\n", 216 | " im_feature = feature_extractor(imagepath) \n", 217 | " if im_feature == \"Invalid\":\n", 218 | " continue\n", 219 | " im_feature.append(label_f) # appending label to feature vector\n", 220 | " df_f.loc[len(df_f)] = im_feature \n", 221 | " if len(df_f)%500 ==0:\n", 222 | " print(len(df_f))\n", 223 | "\n", 224 | " return df_f\n" 225 | ] 226 | }, 227 | { 228 | "cell_type": "markdown", 229 | "metadata": { 230 | "id": "e_j-0tsClOhc" 231 | }, 232 | "source": [ 233 | "# Function to process one plant" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": null, 239 | "metadata": { 240 | "id": "BZlSK_KtlShp" 241 | }, 242 | "outputs": [], 243 | "source": [ 244 | "def process_plant(folderpaths, labels, savepath):\n", 245 | " '''\n", 246 | " input params:\n", 247 | " folderpaths : List of the folderpaths for specific Plant\n", 248 | " labels : List of labels \n", 249 | " savepath : Path to export datasheet\n", 250 | "\n", 251 | " Output params:\n", 252 | " None\n", 253 | " '''\n", 254 | " datasheet = create_empty_df()\n", 255 | " for i in range(len(folderpaths)):\n", 256 | " datasheet = process_folder(folderpaths[i],datasheet,labels[i])\n", 257 | "\n", 258 | " datasheet.to_excel(savepath)\n", 259 | "\n", 260 | " return None" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": null, 266 | "metadata": { 267 | "id": "S9XeDa4SvCsK" 268 | }, 269 | "outputs": [], 270 | "source": [] 271 | }, 272 | { 273 | "cell_type": "markdown", 274 | "metadata": { 275 | "id": "m1ZJGflvvDVs" 276 | }, 277 | "source": [ 278 | "# Data Preprocessing" 279 | ] 280 | }, 281 | { 282 | "cell_type": "markdown", 283 | "metadata": { 284 | "id": "QPNfuzCpu-sB" 285 | }, 286 | "source": [ 287 | "**Apple**" 288 | ] 289 | }, 290 | { 291 | "cell_type": "code", 292 | "execution_count": null, 293 | "metadata": { 294 | "colab": { 295 | "base_uri": "https://localhost:8080/" 296 | }, 297 | "executionInfo": { 298 | "elapsed": 2304165, 299 | "status": "ok", 300 | "timestamp": 1619251897673, 301 | "user": { 302 | "displayName": "PRANESH KULKARNI", 303 | "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvgFvelpvTbQgkznPwzxNtGpPH76MqnWgXlEnr0w=s64", 304 | "userId": "16614981567397361462" 305 | }, 306 | "user_tz": -330 307 | }, 308 | "id": "sda9zebgtbDy", 309 | "outputId": "4332a5e3-8521-4065-9bc6-47e8d9507fad" 310 | }, 311 | "outputs": [ 312 | { 313 | "name": "stdout", 314 | "output_type": "stream", 315 | "text": [ 316 | "500\n", 317 | "1000\n", 318 | "1500\n", 319 | "2000\n", 320 | "2500\n", 321 | "3000\n", 322 | "3500\n", 323 | "4000\n", 324 | "4500\n", 325 | "5000\n", 326 | "5500\n", 327 | "6000\n", 328 | "6500\n", 329 | "7000\n", 330 | "7500\n" 331 | ] 332 | } 333 | ], 334 | "source": [ 335 | "folderpaths = ['/content/drive/MyDrive/Plant Disease Detection /Raw_Dataset/New Plant Diseases Dataset(Augmented)/New Plant Diseases Dataset(Augmented)/train/Apple___healthy',\n", 336 | " '/content/drive/MyDrive/Plant Disease Detection /Raw_Dataset/New Plant Diseases Dataset(Augmented)/New Plant Diseases Dataset(Augmented)/train/Apple___Apple_scab',\n", 337 | " '/content/drive/MyDrive/Plant Disease Detection /Raw_Dataset/New Plant Diseases Dataset(Augmented)/New Plant Diseases Dataset(Augmented)/train/Apple___Black_rot',\n", 338 | " '/content/drive/MyDrive/Plant Disease Detection /Raw_Dataset/New Plant Diseases Dataset(Augmented)/New Plant Diseases Dataset(Augmented)/train/Apple___Cedar_apple_rust'\n", 339 | "\n", 340 | "]\n", 341 | "\n", 342 | "labels = [0,1,2,3]\n", 343 | "savepath = '/content/drive/MyDrive/Plant Disease Detection /Processed_data&models/Apple/dataset.xlsx'\n", 344 | "process_plant(folderpaths, labels, savepath)" 345 | ] 346 | }, 347 | { 348 | "cell_type": "markdown", 349 | "metadata": { 350 | "id": "qrr0rX5ZzT2f" 351 | }, 352 | "source": [ 353 | "**Corn**" 354 | ] 355 | }, 356 | { 357 | "cell_type": "code", 358 | "execution_count": null, 359 | "metadata": { 360 | "id": "Ki3NOAXJzdhE" 361 | }, 362 | "outputs": [], 363 | "source": [ 364 | "global_folder = '/content/drive/MyDrive/Plant Disease Detection /Raw_Dataset/New Plant Diseases Dataset(Augmented)/New Plant Diseases Dataset(Augmented)/train/'" 365 | ] 366 | }, 367 | { 368 | "cell_type": "code", 369 | "execution_count": null, 370 | "metadata": { 371 | "colab": { 372 | "base_uri": "https://localhost:8080/" 373 | }, 374 | "executionInfo": { 375 | "elapsed": 2199820, 376 | "status": "ok", 377 | "timestamp": 1619254122224, 378 | "user": { 379 | "displayName": "PRANESH KULKARNI", 380 | "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvgFvelpvTbQgkznPwzxNtGpPH76MqnWgXlEnr0w=s64", 381 | "userId": "16614981567397361462" 382 | }, 383 | "user_tz": -330 384 | }, 385 | "id": "4I2h1VfYyvYs", 386 | "outputId": "179b6ffe-7790-473b-bfd2-d2478b017b8b" 387 | }, 388 | "outputs": [ 389 | { 390 | "name": "stdout", 391 | "output_type": "stream", 392 | "text": [ 393 | "500\n", 394 | "1000\n", 395 | "1500\n", 396 | "2000\n", 397 | "2500\n", 398 | "3000\n", 399 | "3500\n", 400 | "4000\n", 401 | "4500\n", 402 | "5000\n", 403 | "5500\n", 404 | "6000\n", 405 | "6500\n", 406 | "7000\n" 407 | ] 408 | } 409 | ], 410 | "source": [ 411 | "folderpaths = [global_folder+ 'Corn_(maize)___healthy',\n", 412 | " global_folder+ 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot',\n", 413 | " global_folder+ 'Corn_(maize)___Common_rust_',\n", 414 | " global_folder+ 'Corn_(maize)___Northern_Leaf_Blight'\n", 415 | " ]\n", 416 | "\n", 417 | "labels = [0,1,2,3]\n", 418 | "savepath = '/content/drive/MyDrive/Plant Disease Detection /Processed_data&models/Corn/dataset.xlsx'\n", 419 | "process_plant(folderpaths, labels, savepath)" 420 | ] 421 | }, 422 | { 423 | "cell_type": "code", 424 | "execution_count": null, 425 | "metadata": { 426 | "id": "g6_HtHCc0aA2" 427 | }, 428 | "outputs": [], 429 | "source": [] 430 | }, 431 | { 432 | "cell_type": "markdown", 433 | "metadata": { 434 | "id": "uVJTlZKo8gHW" 435 | }, 436 | "source": [ 437 | "**Grape**" 438 | ] 439 | }, 440 | { 441 | "cell_type": "code", 442 | "execution_count": null, 443 | "metadata": { 444 | "colab": { 445 | "base_uri": "https://localhost:8080/" 446 | }, 447 | "executionInfo": { 448 | "elapsed": 243266, 449 | "status": "ok", 450 | "timestamp": 1619268768601, 451 | "user": { 452 | "displayName": "PRANESH KULKARNI", 453 | "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvgFvelpvTbQgkznPwzxNtGpPH76MqnWgXlEnr0w=s64", 454 | "userId": "16614981567397361462" 455 | }, 456 | "user_tz": -330 457 | }, 458 | "id": "ZlecZPtF0Z6C", 459 | "outputId": "e9cab57c-35f9-4639-ba04-ce1672cc774c" 460 | }, 461 | "outputs": [ 462 | { 463 | "name": "stdout", 464 | "output_type": "stream", 465 | "text": [ 466 | "500\n", 467 | "1000\n", 468 | "1500\n", 469 | "2000\n", 470 | "2500\n", 471 | "3000\n", 472 | "3500\n", 473 | "4000\n", 474 | "4500\n", 475 | "5000\n", 476 | "5500\n", 477 | "6000\n", 478 | "6500\n", 479 | "7000\n" 480 | ] 481 | } 482 | ], 483 | "source": [ 484 | "global_folder = '/content/drive/MyDrive/Plant Disease Detection /Raw_Dataset/New Plant Diseases Dataset(Augmented)/New Plant Diseases Dataset(Augmented)/train/'\n", 485 | "\n", 486 | "folderpaths = [global_folder+ 'Grape___healthy',\n", 487 | " global_folder+ 'Grape___Black_rot',\n", 488 | " global_folder+ 'Grape___Esca_(Black_Measles)',\n", 489 | " global_folder+ 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)'\n", 490 | " ]\n", 491 | "\n", 492 | "labels = [0,1,2,3]\n", 493 | "savepath = '/content/drive/MyDrive/Plant Disease Detection /Processed_data&models/Grapes/dataset.xlsx'\n", 494 | "process_plant(folderpaths, labels, savepath)" 495 | ] 496 | }, 497 | { 498 | "cell_type": "markdown", 499 | "metadata": { 500 | "id": "_WHzZFWh9Hz6" 501 | }, 502 | "source": [ 503 | "**Tomato**" 504 | ] 505 | }, 506 | { 507 | "cell_type": "code", 508 | "execution_count": null, 509 | "metadata": { 510 | "colab": { 511 | "base_uri": "https://localhost:8080/" 512 | }, 513 | "executionInfo": { 514 | "elapsed": 632858, 515 | "status": "ok", 516 | "timestamp": 1619269440910, 517 | "user": { 518 | "displayName": "PRANESH KULKARNI", 519 | "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvgFvelpvTbQgkznPwzxNtGpPH76MqnWgXlEnr0w=s64", 520 | "userId": "16614981567397361462" 521 | }, 522 | "user_tz": -330 523 | }, 524 | "id": "ojtESB1E0Zw8", 525 | "outputId": "8f894c81-1f41-4b18-e3a3-083ab1677c19" 526 | }, 527 | "outputs": [ 528 | { 529 | "name": "stdout", 530 | "output_type": "stream", 531 | "text": [ 532 | "500\n", 533 | "1000\n", 534 | "1500\n", 535 | "2000\n", 536 | "2500\n", 537 | "3000\n", 538 | "3500\n", 539 | "4000\n", 540 | "4500\n", 541 | "5000\n", 542 | "5500\n", 543 | "6000\n", 544 | "6500\n", 545 | "7000\n", 546 | "7500\n", 547 | "8000\n", 548 | "8500\n", 549 | "9000\n", 550 | "9500\n", 551 | "10000\n", 552 | "10500\n", 553 | "11000\n", 554 | "11500\n", 555 | "12000\n", 556 | "12500\n", 557 | "13000\n", 558 | "13500\n", 559 | "14000\n", 560 | "14500\n", 561 | "15000\n", 562 | "15500\n", 563 | "16000\n", 564 | "16500\n", 565 | "17000\n", 566 | "17500\n", 567 | "18000\n" 568 | ] 569 | } 570 | ], 571 | "source": [ 572 | "global_folder = '/content/drive/MyDrive/Plant Disease Detection /Raw_Dataset/New Plant Diseases Dataset(Augmented)/New Plant Diseases Dataset(Augmented)/train/'\n", 573 | "\n", 574 | "folderpaths = [global_folder+ 'Tomato___healthy',\n", 575 | " global_folder+ 'Tomato___Bacterial_spot',\n", 576 | " global_folder+ 'Tomato___Early_blight',\n", 577 | " global_folder+ 'Tomato___Late_blight',\n", 578 | " global_folder+ 'Tomato___Leaf_Mold',\n", 579 | " global_folder+ 'Tomato___Septoria_leaf_spot',\n", 580 | " global_folder+'Tomato___Spider_mites Two-spotted_spider_mite',\n", 581 | " global_folder+ 'Tomato___Target_Spot',\n", 582 | " global_folder+'Tomato___Tomato_Yellow_Leaf_Curl_Virus',\n", 583 | " global_folder+ 'Tomato___Tomato_mosaic_virus'\n", 584 | " ]\n", 585 | "\n", 586 | "labels = [0,1,2,3,4,5,6,7,8,9,10]\n", 587 | "savepath = '/content/drive/MyDrive/Plant Disease Detection /Processed_data&models/Tomato/dataset.xlsx'\n", 588 | "process_plant(folderpaths, labels, savepath)" 589 | ] 590 | }, 591 | { 592 | "cell_type": "markdown", 593 | "metadata": { 594 | "id": "YbztYIOEvY7b" 595 | }, 596 | "source": [ 597 | "**Potato**" 598 | ] 599 | }, 600 | { 601 | "cell_type": "code", 602 | "execution_count": null, 603 | "metadata": { 604 | "colab": { 605 | "base_uri": "https://localhost:8080/" 606 | }, 607 | "executionInfo": { 608 | "elapsed": 186975, 609 | "status": "ok", 610 | "timestamp": 1619269628008, 611 | "user": { 612 | "displayName": "PRANESH KULKARNI", 613 | "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgvgFvelpvTbQgkznPwzxNtGpPH76MqnWgXlEnr0w=s64", 614 | "userId": "16614981567397361462" 615 | }, 616 | "user_tz": -330 617 | }, 618 | "id": "YPhb5u2vjBxt", 619 | "outputId": "386891d6-3fde-4948-b9c2-96e2f1c43458" 620 | }, 621 | "outputs": [ 622 | { 623 | "name": "stdout", 624 | "output_type": "stream", 625 | "text": [ 626 | "500\n", 627 | "1000\n", 628 | "1500\n", 629 | "2000\n", 630 | "2500\n", 631 | "3000\n", 632 | "3500\n", 633 | "4000\n", 634 | "4500\n", 635 | "5000\n", 636 | "5500\n" 637 | ] 638 | } 639 | ], 640 | "source": [ 641 | "global_folder = '/content/drive/MyDrive/Plant Disease Detection /Raw_Dataset/New Plant Diseases Dataset(Augmented)/New Plant Diseases Dataset(Augmented)/train/'\n", 642 | "\n", 643 | "folderpaths = [global_folder+ 'Potato___healthy',\n", 644 | " global_folder+ 'Potato___Early_blight',\n", 645 | " global_folder+ 'Potato___Late_blight'\n", 646 | " ]\n", 647 | "\n", 648 | "labels = [0,1,2]\n", 649 | "savepath = '/content/drive/MyDrive/Plant Disease Detection /Processed_data&models/Potato/dataset.xlsx'\n", 650 | "process_plant(folderpaths, labels, savepath)" 651 | ] 652 | }, 653 | { 654 | "cell_type": "code", 655 | "execution_count": null, 656 | "metadata": { 657 | "id": "tqEFoGf5wO9-" 658 | }, 659 | "outputs": [], 660 | "source": [ 661 | "from google.colab import drive\n", 662 | "drive.flush_and_unmount()" 663 | ] 664 | }, 665 | { 666 | "cell_type": "code", 667 | "execution_count": null, 668 | "metadata": { 669 | "id": "xfYu9gEF6gcz" 670 | }, 671 | "outputs": [], 672 | "source": [] 673 | } 674 | ], 675 | "metadata": { 676 | "colab": { 677 | "collapsed_sections": [], 678 | "name": "Data_Preprocessing.ipynb", 679 | "provenance": [], 680 | "toc_visible": true 681 | }, 682 | "kernelspec": { 683 | "display_name": "Python 3", 684 | "language": "python", 685 | "name": "python3" 686 | }, 687 | "language_info": { 688 | "codemirror_mode": { 689 | "name": "ipython", 690 | "version": 3 691 | }, 692 | "file_extension": ".py", 693 | "mimetype": "text/x-python", 694 | "name": "python", 695 | "nbconvert_exporter": "python", 696 | "pygments_lexer": "ipython3", 697 | "version": "3.8.7" 698 | } 699 | }, 700 | "nbformat": 4, 701 | "nbformat_minor": 4 702 | } 703 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Pranesh6767 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Plant-Disease-Detection-Using-Digital-Image-Processing 2 | The plant disease detection system with efficient image segmentation and feature extraction algorithms and statistical models. 3 | -------------------------------------------------------------------------------- /api/V1/__pycache__/imageprocess.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/__pycache__/imageprocess.cpython-38.pyc -------------------------------------------------------------------------------- /api/V1/__pycache__/predictor.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/__pycache__/predictor.cpython-38.pyc -------------------------------------------------------------------------------- /api/V1/imageprocess.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | from skimage.feature import local_binary_pattern , greycomatrix , greycoprops 4 | 5 | def feature_extractor(filename): 6 | ''' 7 | input params: 8 | filename : path of the file that we want to process 9 | 10 | Output params: 11 | l : Feature vector 12 | ''' 13 | 14 | #try: 15 | main_img = cv2.imread(filename) 16 | img = cv2.cvtColor(main_img, cv2.COLOR_BGR2RGB) 17 | #except: 18 | # return "Invalid" 19 | 20 | #Preprocessing 21 | 22 | 23 | gs = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY) 24 | blur = cv2.GaussianBlur(gs, (25,25),0) 25 | ret_otsu,im_bw_otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) 26 | kernel = np.ones((50,50),np.uint8) 27 | closing = cv2.morphologyEx(im_bw_otsu, cv2.MORPH_CLOSE, kernel) 28 | 29 | #Shape features 30 | contours, _ = cv2.findContours(closing,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) 31 | cnt = contours[0] 32 | M = cv2.moments(cnt) 33 | area = cv2.contourArea(cnt) 34 | if area==0: 35 | return "Invalid" 36 | perimeter = cv2.arcLength(cnt,True) 37 | x,y,w,h = cv2.boundingRect(cnt) 38 | aspect_ratio = float(w)/h 39 | 40 | 41 | #Color features 42 | #can set rgb from 0-255, and by setting it to 1, we only get 1/255 of the chosen color, 43 | #where 0 is black and 255 is red/green/blue. Depending on oour sight, will have to enter 44 | #a higher number in order to see the actual color. 45 | red_channel = img[:,:,0] 46 | green_channel = img[:,:,1] #show the intensities of green channe 47 | blue_channel = img[:,:,2] 48 | 49 | blue_channel[blue_channel == 255] = 0 50 | green_channel[green_channel == 255] = 0 51 | red_channel[red_channel == 255] = 0 52 | 53 | red_mean = np.mean(red_channel) 54 | green_mean = np.mean(green_channel) 55 | blue_mean = np.mean(blue_channel) 56 | #standard deviation for colour feature from the image. 57 | red_std = np.std(red_channel) 58 | green_std = np.std(green_channel) 59 | blue_std = np.std(blue_channel) 60 | 61 | #amt.of green color in the image 62 | gr = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) 63 | boundaries = [([30,0,0],[70,255,255])] 64 | for (lower, upper) in boundaries: 65 | mask = cv2.inRange(gr, (36, 0, 0), (70, 255,255)) 66 | ratio_green = cv2.countNonZero(mask)/(img.size/3) 67 | f1=np.round(ratio_green, 2) 68 | #amt. of non green part of the image 69 | f2=1-f1 70 | 71 | #Texture features using grey level cooccurance matrix 72 | img=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 73 | g=greycomatrix(img, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4]) 74 | 75 | #with the help of glcm find the contrast 76 | contrast = greycoprops(g, 'contrast') 77 | f4=contrast[0][0]+contrast[0][1]+contrast[0][2]+contrast[0][3] 78 | #[0][3] represent no. of times grey level 3 appears at the right of 0 79 | 80 | 81 | #with the help of glcm find the dissimilarity 82 | dissimilarity = greycoprops(g, prop='dissimilarity') 83 | f5=dissimilarity[0][0]+dissimilarity[0][1]+dissimilarity[0][2]+dissimilarity[0][3] 84 | 85 | #with the help of glcm find the homogeneity 86 | homogeneity = greycoprops(g, prop='homogeneity') 87 | f6=homogeneity[0][0]+homogeneity[0][1]+homogeneity[0][2]+homogeneity[0][3] 88 | 89 | #with the help of glcm find the energy. 90 | energy = greycoprops(g, prop='energy') 91 | f7=energy[0][0]+energy[0][1]+energy[0][2]+energy[0][3] 92 | 93 | 94 | #with the help of glcm find the correlation 95 | correlation = greycoprops(g,prop= 'correlation') 96 | f8=correlation[0][0]+correlation[0][1]+correlation[0][2]+correlation[0][3] 97 | 98 | 99 | 100 | l = {'area':area, 'perimeter': perimeter,'red_mean': red_mean, 'green_mean': green_mean, 101 | 'blue_mean': blue_mean,'f1': f1,'f2': f2,'red_std': red_std,'green_std': green_std,'blue_std': blue_std, 102 | 'f4':f4,'f5':f5,'f6':f6,'f7':f7,'f8':f8} 103 | return l -------------------------------------------------------------------------------- /api/V1/main.py: -------------------------------------------------------------------------------- 1 | import imageprocess 2 | import predictor 3 | 4 | import pickle 5 | 6 | import os 7 | 8 | response = 't' 9 | 10 | applemodelpath = 'models/Applemodel_V1.sav' 11 | apple_model = pickle.load(open(applemodelpath, 'rb')) 12 | 13 | cornmodelpath = 'models/cornmodel_V1.sav' 14 | corn_model = pickle.load(open(cornmodelpath, 'rb')) 15 | 16 | grapesmodelpath = 'models/grapesmodel_V1.sav' 17 | grapes_model = pickle.load(open(grapesmodelpath, 'rb')) 18 | 19 | potatomodelpath = 'models/potatomodel_V1.sav' 20 | potato_model = pickle.load(open(potatomodelpath, 'rb')) 21 | 22 | tomatomodelpath = 'models/Tomatomodel_V1.sav' 23 | tomato_model = pickle.load(open(tomatomodelpath, 'rb')) 24 | 25 | img = 'test/13.JPG' 26 | 27 | f_vector = imageprocess.feature_extractor(img) 28 | 29 | if response=='a': 30 | p_vector = [f_vector['area'],f_vector['perimeter'],f_vector['red_mean'],f_vector['blue_mean'],f_vector['f2'],f_vector['green_std'], 31 | f_vector['f4'],f_vector['f6'],f_vector['f7']] 32 | 33 | res = predictor.apple_p(p_vector,apple_model) 34 | print(res) 35 | 36 | if response=='c': 37 | p_vector = [f_vector['red_mean'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], f_vector['red_std'], f_vector['blue_std'], 38 | f_vector['f7'], f_vector['f8']] 39 | 40 | res = predictor.corn_p(p_vector,corn_model) 41 | print(res) 42 | 43 | if response=='g': 44 | p_vector = [f_vector['area'], f_vector['perimeter'], f_vector['red_mean'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], 45 | f_vector['red_std'], f_vector['green_std'], f_vector['blue_std'], f_vector['f4'], f_vector['f5'], f_vector['f6'], f_vector['f7'], f_vector['f8']] 46 | 47 | res = predictor.grapes_p(p_vector,grapes_model) 48 | print(res) 49 | 50 | if response=='p': 51 | p_vector = [f_vector['area'], f_vector['perimeter'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], f_vector['red_std'], 52 | f_vector['green_std'], f_vector['blue_std'], f_vector['f4'], f_vector['f5'], f_vector['f7'], f_vector['f8']] 53 | 54 | res = predictor.potato_p(p_vector,potato_model) 55 | print(res) 56 | 57 | if response=='t': 58 | del f_vector["f1"] 59 | p_vector = list(f_vector.values()) 60 | 61 | res = predictor.tomato_p(p_vector,tomato_model) 62 | print(res) 63 | -------------------------------------------------------------------------------- /api/V1/models/Applemodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/models/Applemodel_V1.sav -------------------------------------------------------------------------------- /api/V1/models/Tomatomodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/models/Tomatomodel_V1.sav -------------------------------------------------------------------------------- /api/V1/models/cornmodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/models/cornmodel_V1.sav -------------------------------------------------------------------------------- /api/V1/models/grapesmodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/models/grapesmodel_V1.sav -------------------------------------------------------------------------------- /api/V1/models/potatomodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/models/potatomodel_V1.sav -------------------------------------------------------------------------------- /api/V1/predictor.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def apple_p(feature_vector,model): 4 | processed_vector = np.array(feature_vector).reshape(1, -1) 5 | output = model.predict(processed_vector) 6 | output = int(output) 7 | label_dict = {0 :'Apple___healthy', 1: 'Apple___Apple_scab', 2: 'Apple___Black_rot', 3: 'Apple___Cedar_apple_rust'} 8 | output = label_dict[output] 9 | return output 10 | 11 | def corn_p(feature_vector,model): 12 | processed_vector = np.array(feature_vector).reshape(1, -1) 13 | output = model.predict(processed_vector) 14 | output = int(output) 15 | label_dict = {0: 'Corn_(maize)___healthy', 16 | 1: 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot', 17 | 2: 'Corn_(maize)__Common_rust', 18 | 3: 'Corn_(maize)___Northern_Leaf_Blight'} 19 | output = label_dict[output] 20 | return output 21 | 22 | def grapes_p(feature_vector,model): 23 | processed_vector = np.array(feature_vector).reshape(1, -1) 24 | output = model.predict(processed_vector) 25 | output = int(output) 26 | label_dict = {0 : 'Grape___healthy', 27 | 1 : 'Grape___Black_rot', 28 | 2 : 'Grape___Esca_(Black_Measles)', 29 | 3 : 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)'} 30 | output = label_dict[output] 31 | return output 32 | 33 | def potato_p(feature_vector,model): 34 | processed_vector = np.array(feature_vector).reshape(1, -1) 35 | output = model.predict(processed_vector) 36 | output = int(output) 37 | label_dict = {0: 'Potato___healthy', 38 | 1: 'Potato___Early_blight', 39 | 2: 'Potato___Late_blight'} 40 | output = label_dict[output] 41 | return output 42 | 43 | def tomato_p(feature_vector,model): 44 | processed_vector = np.array(feature_vector).reshape(1, -1) 45 | output = model.predict(processed_vector) 46 | output = int(output) 47 | label_dict = {0 : 'Tomato___healthy', 48 | 1 : 'Tomato___Bacterial_spot', 49 | 2 : 'Tomato___Early_blight', 50 | 3 : 'Tomato___Late_blight', 51 | 4 : 'Tomato___Leaf_Mold', 52 | 5 : 'Tomato___Septoria_leaf_spot', 53 | 6 : 'Tomato___Spider_mites Two-spotted_spider_mite', 54 | 7 : 'Tomato___Target_Spot', 55 | 8 : 'Tomato___Tomato_Yellow_Leaf_Curl_Virus', 56 | 9 : 'Tomato___Tomato_mosaic_virus'} 57 | output = label_dict[output] 58 | return output 59 | 60 | -------------------------------------------------------------------------------- /api/V1/test/a1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/a1.JPG -------------------------------------------------------------------------------- /api/V1/test/a2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/a2.JPG -------------------------------------------------------------------------------- /api/V1/test/a3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/a3.JPG -------------------------------------------------------------------------------- /api/V1/test/a4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/a4.JPG -------------------------------------------------------------------------------- /api/V1/test/c5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/c5.jpg -------------------------------------------------------------------------------- /api/V1/test/c6.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/c6.JPG -------------------------------------------------------------------------------- /api/V1/test/g7.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/g7.JPG -------------------------------------------------------------------------------- /api/V1/test/g8.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/g8.JPG -------------------------------------------------------------------------------- /api/V1/test/p10.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/p10.JPG -------------------------------------------------------------------------------- /api/V1/test/p9.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/p9.JPG -------------------------------------------------------------------------------- /api/V1/test/t11.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/t11.JPG -------------------------------------------------------------------------------- /api/V1/test/t12.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/t12.JPG -------------------------------------------------------------------------------- /api/V1/test/t13.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V1/test/t13.JPG -------------------------------------------------------------------------------- /api/V1/testing_script.py: -------------------------------------------------------------------------------- 1 | ############################################################### 2 | # Plant disease detection 3 | # API V1 4 | # Version 0.1 5 | # Testing Script 6 | ############################################################### 7 | # Importing libraries 8 | import imageprocess 9 | import predictor 10 | import pickle 11 | import os 12 | 13 | ############################################################### 14 | # Loading the models with pickle 15 | 16 | applemodelpath = 'models/Applemodel_V1.sav' 17 | apple_model = pickle.load(open(applemodelpath, 'rb')) 18 | 19 | cornmodelpath = 'models/cornmodel_V1.sav' 20 | corn_model = pickle.load(open(cornmodelpath, 'rb')) 21 | 22 | grapesmodelpath = 'models/grapesmodel_V1.sav' 23 | grapes_model = pickle.load(open(grapesmodelpath, 'rb')) 24 | 25 | potatomodelpath = 'models/potatomodel_V1.sav' 26 | potato_model = pickle.load(open(potatomodelpath, 'rb')) 27 | 28 | tomatomodelpath = 'models/Tomatomodel_V1.sav' 29 | tomato_model = pickle.load(open(tomatomodelpath, 'rb')) 30 | 31 | ############################################################### 32 | 33 | def main(): 34 | f_vector = imageprocess.feature_extractor(img) 35 | 36 | if response=='a': 37 | p_vector = [f_vector['area'],f_vector['perimeter'],f_vector['red_mean'],f_vector['blue_mean'],f_vector['f2'],f_vector['green_std'], 38 | f_vector['f4'],f_vector['f6'],f_vector['f7']] 39 | 40 | res = predictor.apple_p(p_vector,apple_model) 41 | return res 42 | 43 | if response=='c': 44 | p_vector = [f_vector['red_mean'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], f_vector['red_std'], f_vector['blue_std'], 45 | f_vector['f7'], f_vector['f8']] 46 | 47 | res = predictor.corn_p(p_vector,corn_model) 48 | return res 49 | 50 | if response=='g': 51 | p_vector = [f_vector['area'], f_vector['perimeter'], f_vector['red_mean'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], 52 | f_vector['red_std'], f_vector['green_std'], f_vector['blue_std'], f_vector['f4'], f_vector['f5'], f_vector['f6'], f_vector['f7'], f_vector['f8']] 53 | 54 | res = predictor.grapes_p(p_vector,grapes_model) 55 | return res 56 | 57 | if response=='p': 58 | p_vector = [f_vector['area'], f_vector['perimeter'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], f_vector['red_std'], 59 | f_vector['green_std'], f_vector['blue_std'], f_vector['f4'], f_vector['f5'], f_vector['f7'], f_vector['f8']] 60 | 61 | res = predictor.potato_p(p_vector,potato_model) 62 | return res 63 | 64 | if response=='t': 65 | del f_vector["f1"] 66 | p_vector = list(f_vector.values()) 67 | 68 | res = predictor.tomato_p(p_vector,tomato_model) 69 | return res 70 | 71 | 72 | print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") 73 | print("!!!!!!!!!!!!!!! Initiating The Testing Lop !!!!!!!!!!!!!!!!") 74 | testimagelist = os.listdir('test') 75 | testimagelist.sort() 76 | predicted_labels = [] 77 | k = 0 78 | for i in testimagelist: 79 | response = i[0] 80 | img = 'test/'+i 81 | el = main() 82 | predicted_labels.append(el) 83 | print("!!!!! sample ",k," processed !!!!" ) 84 | k=k+1 85 | 86 | target_labels = ['Apple___Black_rot', 'Apple___Apple_scab', 'Apple___Cedar_apple_rust', 'Apple___healthy', 87 | 'Corn_(maize)___healthy', 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot', 'Grape___healthy', 'Grape___Esca_(Black_Measles)', 88 | 'Potato___Late_blight', 'Potato___healthy', 'Tomato___healthy', 'Tomato___Leaf_Mold', 'Tomato___Tomato_mosaic_virus'] 89 | 90 | flag = True 91 | for i in range(len(predicted_labels)): 92 | if predicted_labels[i] == target_labels[i]: 93 | print("!!!! Test Successfully passed !!!!") 94 | else: 95 | flag = False 96 | print("!!!! Test Failed !!!") 97 | 98 | print("!!!!! Testing Completed !!!!!!") 99 | print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") 100 | if flag: 101 | print("All tests passed Successfully") 102 | else: 103 | print("Might be some error !") 104 | print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") 105 | 106 | a = input() 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /api/V2_flask_integration/__pycache__/imageprocess.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V2_flask_integration/__pycache__/imageprocess.cpython-38.pyc -------------------------------------------------------------------------------- /api/V2_flask_integration/__pycache__/predictor.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V2_flask_integration/__pycache__/predictor.cpython-38.pyc -------------------------------------------------------------------------------- /api/V2_flask_integration/app.py: -------------------------------------------------------------------------------- 1 | ############################################################### 2 | # Plant disease detection 3 | # API V2 4 | # Version 1.1 5 | # API Main Script 6 | ############################################################### 7 | 8 | ############################################################### 9 | # Importing required Libraries and modules 10 | import imageprocess 11 | import predictor 12 | import pickle 13 | import os 14 | from flask import Flask 15 | import flask 16 | from flask import request 17 | from flask import render_template 18 | import numpy as np 19 | import cv2 20 | ############################################################## 21 | 22 | 23 | app = Flask(__name__) 24 | 25 | applemodelpath = 'models/Applemodel_V1.sav' 26 | apple_model = pickle.load(open(applemodelpath, 'rb')) 27 | 28 | cornmodelpath = 'models/cornmodel_V1.sav' 29 | corn_model = pickle.load(open(cornmodelpath, 'rb')) 30 | 31 | grapesmodelpath = 'models/grapesmodel_V1.sav' 32 | grapes_model = pickle.load(open(grapesmodelpath, 'rb')) 33 | 34 | potatomodelpath = 'models/potatomodel_V1.sav' 35 | potato_model = pickle.load(open(potatomodelpath, 'rb')) 36 | 37 | tomatomodelpath = 'models/Tomatomodel_V1.sav' 38 | tomato_model = pickle.load(open(tomatomodelpath, 'rb')) 39 | 40 | 41 | @app.route("/") 42 | def home(): 43 | version = "1.1" 44 | return render_template('index.html', version1 = version) 45 | 46 | @app.route("/predict", methods = ['GET', 'POST']) 47 | def submit(): 48 | imagefile = flask.request.files["data_file"].read() 49 | dname = request.form.get('Name') 50 | dname = str(dname) 51 | response = dname[0] 52 | npimg = np.frombuffer(imagefile, np.uint8) 53 | # convert numpy array to image 54 | img = cv2.imdecode(npimg,cv2.IMREAD_COLOR) 55 | 56 | f_vector = imageprocess.feature_extractor(img) 57 | 58 | if response=='n': 59 | res = "Please select the appropriate plant from the list" 60 | return '

'+res+'

' 61 | 62 | if response=='a': 63 | p_vector = [f_vector['area'],f_vector['perimeter'],f_vector['red_mean'],f_vector['blue_mean'],f_vector['f2'],f_vector['green_std'], 64 | f_vector['f4'],f_vector['f6'],f_vector['f7']] 65 | 66 | res = predictor.apple_p(p_vector,apple_model) 67 | return '

'+res+'

' 68 | 69 | if response=='c': 70 | p_vector = [f_vector['red_mean'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], f_vector['red_std'], f_vector['blue_std'], 71 | f_vector['f7'], f_vector['f8']] 72 | 73 | res = predictor.corn_p(p_vector,corn_model) 74 | return '

'+res+'

' 75 | 76 | if response=='g': 77 | p_vector = [f_vector['area'], f_vector['perimeter'], f_vector['red_mean'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], 78 | f_vector['red_std'], f_vector['green_std'], f_vector['blue_std'], f_vector['f4'], f_vector['f5'], f_vector['f6'], f_vector['f7'], f_vector['f8']] 79 | 80 | res = predictor.grapes_p(p_vector,grapes_model) 81 | return '

'+res+'

' 82 | 83 | if response=='p': 84 | p_vector = [f_vector['area'], f_vector['perimeter'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], f_vector['red_std'], 85 | f_vector['green_std'], f_vector['blue_std'], f_vector['f4'], f_vector['f5'], f_vector['f7'], f_vector['f8']] 86 | 87 | res = predictor.potato_p(p_vector,potato_model) 88 | return '

'+res+'

' 89 | 90 | if response=='t': 91 | del f_vector["f1"] 92 | p_vector = list(f_vector.values()) 93 | 94 | res = predictor.tomato_p(p_vector,tomato_model) 95 | return '

'+res+'

' 96 | 97 | if __name__ == "__main__": 98 | app.run(port = 5000) -------------------------------------------------------------------------------- /api/V2_flask_integration/imageprocess.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | from skimage.feature import local_binary_pattern , greycomatrix , greycoprops 4 | 5 | def feature_extractor(filename): 6 | ''' 7 | input params: 8 | filename : path of the file that we want to process 9 | 10 | Output params: 11 | l : Feature vector 12 | ''' 13 | main_img = filename 14 | img = cv2.cvtColor(main_img, cv2.COLOR_BGR2RGB) 15 | 16 | #Preprocessing 17 | 18 | 19 | gs = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY) 20 | blur = cv2.GaussianBlur(gs, (25,25),0) 21 | ret_otsu,im_bw_otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) 22 | kernel = np.ones((50,50),np.uint8) 23 | closing = cv2.morphologyEx(im_bw_otsu, cv2.MORPH_CLOSE, kernel) 24 | 25 | #Shape features 26 | contours, _ = cv2.findContours(closing,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) 27 | cnt = contours[0] 28 | M = cv2.moments(cnt) 29 | area = cv2.contourArea(cnt) 30 | if area==0: 31 | return "Invalid" 32 | perimeter = cv2.arcLength(cnt,True) 33 | x,y,w,h = cv2.boundingRect(cnt) 34 | aspect_ratio = float(w)/h 35 | 36 | 37 | #Color features 38 | #can set rgb from 0-255, and by setting it to 1, we only get 1/255 of the chosen color, 39 | #where 0 is black and 255 is red/green/blue. Depending on oour sight, will have to enter 40 | #a higher number in order to see the actual color. 41 | red_channel = img[:,:,0] 42 | green_channel = img[:,:,1] #show the intensities of green channe 43 | blue_channel = img[:,:,2] 44 | 45 | blue_channel[blue_channel == 255] = 0 46 | green_channel[green_channel == 255] = 0 47 | red_channel[red_channel == 255] = 0 48 | 49 | red_mean = np.mean(red_channel) 50 | green_mean = np.mean(green_channel) 51 | blue_mean = np.mean(blue_channel) 52 | #standard deviation for colour feature from the image. 53 | red_std = np.std(red_channel) 54 | green_std = np.std(green_channel) 55 | blue_std = np.std(blue_channel) 56 | 57 | #amt.of green color in the image 58 | gr = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) 59 | boundaries = [([30,0,0],[70,255,255])] 60 | for (lower, upper) in boundaries: 61 | mask = cv2.inRange(gr, (36, 0, 0), (70, 255,255)) 62 | ratio_green = cv2.countNonZero(mask)/(img.size/3) 63 | f1=np.round(ratio_green, 2) 64 | #amt. of non green part of the image 65 | f2=1-f1 66 | 67 | #Texture features using grey level cooccurance matrix 68 | img=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 69 | g=greycomatrix(img, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4]) 70 | 71 | #with the help of glcm find the contrast 72 | contrast = greycoprops(g, 'contrast') 73 | f4=contrast[0][0]+contrast[0][1]+contrast[0][2]+contrast[0][3] 74 | #[0][3] represent no. of times grey level 3 appears at the right of 0 75 | 76 | 77 | #with the help of glcm find the dissimilarity 78 | dissimilarity = greycoprops(g, prop='dissimilarity') 79 | f5=dissimilarity[0][0]+dissimilarity[0][1]+dissimilarity[0][2]+dissimilarity[0][3] 80 | 81 | #with the help of glcm find the homogeneity 82 | homogeneity = greycoprops(g, prop='homogeneity') 83 | f6=homogeneity[0][0]+homogeneity[0][1]+homogeneity[0][2]+homogeneity[0][3] 84 | 85 | #with the help of glcm find the energy. 86 | energy = greycoprops(g, prop='energy') 87 | f7=energy[0][0]+energy[0][1]+energy[0][2]+energy[0][3] 88 | 89 | 90 | #with the help of glcm find the correlation 91 | correlation = greycoprops(g,prop= 'correlation') 92 | f8=correlation[0][0]+correlation[0][1]+correlation[0][2]+correlation[0][3] 93 | 94 | 95 | 96 | l = {'area':area, 'perimeter': perimeter,'red_mean': red_mean, 'green_mean': green_mean, 97 | 'blue_mean': blue_mean,'f1': f1,'f2': f2,'red_std': red_std,'green_std': green_std,'blue_std': blue_std, 98 | 'f4':f4,'f5':f5,'f6':f6,'f7':f7,'f8':f8} 99 | return l -------------------------------------------------------------------------------- /api/V2_flask_integration/models/Applemodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V2_flask_integration/models/Applemodel_V1.sav -------------------------------------------------------------------------------- /api/V2_flask_integration/models/Tomatomodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V2_flask_integration/models/Tomatomodel_V1.sav -------------------------------------------------------------------------------- /api/V2_flask_integration/models/cornmodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V2_flask_integration/models/cornmodel_V1.sav -------------------------------------------------------------------------------- /api/V2_flask_integration/models/grapesmodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V2_flask_integration/models/grapesmodel_V1.sav -------------------------------------------------------------------------------- /api/V2_flask_integration/models/potatomodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/V2_flask_integration/models/potatomodel_V1.sav -------------------------------------------------------------------------------- /api/V2_flask_integration/predictor.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def apple_p(feature_vector,model): 4 | processed_vector = np.array(feature_vector).reshape(1, -1) 5 | output = model.predict(processed_vector) 6 | output = int(output) 7 | label_dict = {0 :'Apple___healthy', 1: 'Apple___Apple_scab', 2: 'Apple___Black_rot', 3: 'Apple___Cedar_apple_rust'} 8 | output = label_dict[output] 9 | return output 10 | 11 | def corn_p(feature_vector,model): 12 | processed_vector = np.array(feature_vector).reshape(1, -1) 13 | output = model.predict(processed_vector) 14 | output = int(output) 15 | label_dict = {0: 'Corn_(maize)___healthy', 16 | 1: 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot', 17 | 2: 'Corn_(maize)__Common_rust', 18 | 3: 'Corn_(maize)___Northern_Leaf_Blight'} 19 | output = label_dict[output] 20 | return output 21 | 22 | def grapes_p(feature_vector,model): 23 | processed_vector = np.array(feature_vector).reshape(1, -1) 24 | output = model.predict(processed_vector) 25 | output = int(output) 26 | label_dict = {0 : 'Grape___healthy', 27 | 1 : 'Grape___Black_rot', 28 | 2 : 'Grape___Esca_(Black_Measles)', 29 | 3 : 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)'} 30 | output = label_dict[output] 31 | return output 32 | 33 | def potato_p(feature_vector,model): 34 | processed_vector = np.array(feature_vector).reshape(1, -1) 35 | output = model.predict(processed_vector) 36 | output = int(output) 37 | label_dict = {0: 'Potato___healthy', 38 | 1: 'Potato___Early_blight', 39 | 2: 'Potato___Late_blight'} 40 | output = label_dict[output] 41 | return output 42 | 43 | def tomato_p(feature_vector,model): 44 | processed_vector = np.array(feature_vector).reshape(1, -1) 45 | output = model.predict(processed_vector) 46 | output = int(output) 47 | label_dict = {0 : 'Tomato___healthy', 48 | 1 : 'Tomato___Bacterial_spot', 49 | 2 : 'Tomato___Early_blight', 50 | 3 : 'Tomato___Late_blight', 51 | 4 : 'Tomato___Leaf_Mold', 52 | 5 : 'Tomato___Septoria_leaf_spot', 53 | 6 : 'Tomato___Spider_mites Two-spotted_spider_mite', 54 | 7 : 'Tomato___Target_Spot', 55 | 8 : 'Tomato___Tomato_Yellow_Leaf_Curl_Virus', 56 | 9 : 'Tomato___Tomato_mosaic_virus'} 57 | output = label_dict[output] 58 | return output 59 | 60 | -------------------------------------------------------------------------------- /api/V2_flask_integration/static/style1.css: -------------------------------------------------------------------------------- 1 | /* static/style.css */ 2 | 3 | h1 { 4 | color: navajowhite; 5 | font-variant-caps: all-small-caps; 6 | font-size: 46px; 7 | } 8 | 9 | h3 { 10 | color: white; 11 | font-size: 25px; 12 | } 13 | 14 | li { 15 | color: blue; 16 | font-size: 12px; 17 | } 18 | 19 | p { 20 | color: white; 21 | font-size: 12px; 22 | } 23 | 24 | body { 25 | background: black; 26 | } -------------------------------------------------------------------------------- /api/V2_flask_integration/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Plant disease detector 5 | 6 | 7 | 15 | 16 |

Plant disease detection Application

17 |

Version: {{version1}}

18 |

Fill up these details and upload the image

19 | 20 |
21 |

Plant Name:

22 | 23 | 31 | 32 |

Image

33 | 34 | 35 |
36 | 37 | -------------------------------------------------------------------------------- /api/api testing/AppleCedarRust2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/api testing/AppleCedarRust2.JPG -------------------------------------------------------------------------------- /api/api testing/PotatoEarlyBlight1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/api testing/PotatoEarlyBlight1.JPG -------------------------------------------------------------------------------- /api/api testing/PotatoHealthy1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/api testing/PotatoHealthy1.JPG -------------------------------------------------------------------------------- /api/api testing/TomatoEarlyBlight1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/api testing/TomatoEarlyBlight1.JPG -------------------------------------------------------------------------------- /api/api testing/TomatoYellowCurlVirus6.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/api testing/TomatoYellowCurlVirus6.JPG -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.6-alpine as base 2 | 3 | FROM base as builder 4 | 5 | RUN mkdir /install 6 | WORKDIR /install 7 | 8 | # Install app dependencies 9 | COPY ./requirements.txt /requirements.txt 10 | 11 | RUN pip install --install-option="--prefix=/install" -r /requirements.txt 12 | 13 | FROM base 14 | COPY --from=builder /install /usr/local 15 | COPY . /app 16 | 17 | WORKDIR /app 18 | 19 | EXPOSE 5000 20 | 21 | CMD [ "python", "server.py" ] -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/Procfile: -------------------------------------------------------------------------------- 1 | web: python3 server.py -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/imageprocess.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | from skimage.feature import local_binary_pattern , greycomatrix , greycoprops 4 | 5 | def feature_extractor(filename): 6 | ''' 7 | input params: 8 | filename : path of the file that we want to process 9 | 10 | Output params: 11 | l : Feature vector 12 | ''' 13 | main_img = filename 14 | img = cv2.cvtColor(main_img, cv2.COLOR_BGR2RGB) 15 | 16 | #Preprocessing 17 | 18 | 19 | gs = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY) 20 | blur = cv2.GaussianBlur(gs, (25,25),0) 21 | ret_otsu,im_bw_otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) 22 | kernel = np.ones((50,50),np.uint8) 23 | closing = cv2.morphologyEx(im_bw_otsu, cv2.MORPH_CLOSE, kernel) 24 | 25 | #Shape features 26 | contours, _ = cv2.findContours(closing,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) 27 | cnt = contours[0] 28 | M = cv2.moments(cnt) 29 | area = cv2.contourArea(cnt) 30 | if area==0: 31 | return "Invalid" 32 | perimeter = cv2.arcLength(cnt,True) 33 | x,y,w,h = cv2.boundingRect(cnt) 34 | aspect_ratio = float(w)/h 35 | 36 | 37 | #Color features 38 | #can set rgb from 0-255, and by setting it to 1, we only get 1/255 of the chosen color, 39 | #where 0 is black and 255 is red/green/blue. Depending on oour sight, will have to enter 40 | #a higher number in order to see the actual color. 41 | red_channel = img[:,:,0] 42 | green_channel = img[:,:,1] #show the intensities of green channe 43 | blue_channel = img[:,:,2] 44 | 45 | blue_channel[blue_channel == 255] = 0 46 | green_channel[green_channel == 255] = 0 47 | red_channel[red_channel == 255] = 0 48 | 49 | red_mean = np.mean(red_channel) 50 | green_mean = np.mean(green_channel) 51 | blue_mean = np.mean(blue_channel) 52 | #standard deviation for colour feature from the image. 53 | red_std = np.std(red_channel) 54 | green_std = np.std(green_channel) 55 | blue_std = np.std(blue_channel) 56 | 57 | #amt.of green color in the image 58 | gr = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) 59 | boundaries = [([30,0,0],[70,255,255])] 60 | for (lower, upper) in boundaries: 61 | mask = cv2.inRange(gr, (36, 0, 0), (70, 255,255)) 62 | ratio_green = cv2.countNonZero(mask)/(img.size/3) 63 | f1=np.round(ratio_green, 2) 64 | #amt. of non green part of the image 65 | f2=1-f1 66 | 67 | #Texture features using grey level cooccurance matrix 68 | img=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 69 | g=greycomatrix(img, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4]) 70 | 71 | #with the help of glcm find the contrast 72 | contrast = greycoprops(g, 'contrast') 73 | f4=contrast[0][0]+contrast[0][1]+contrast[0][2]+contrast[0][3] 74 | #[0][3] represent no. of times grey level 3 appears at the right of 0 75 | 76 | 77 | #with the help of glcm find the dissimilarity 78 | dissimilarity = greycoprops(g, prop='dissimilarity') 79 | f5=dissimilarity[0][0]+dissimilarity[0][1]+dissimilarity[0][2]+dissimilarity[0][3] 80 | 81 | #with the help of glcm find the homogeneity 82 | homogeneity = greycoprops(g, prop='homogeneity') 83 | f6=homogeneity[0][0]+homogeneity[0][1]+homogeneity[0][2]+homogeneity[0][3] 84 | 85 | #with the help of glcm find the energy. 86 | energy = greycoprops(g, prop='energy') 87 | f7=energy[0][0]+energy[0][1]+energy[0][2]+energy[0][3] 88 | 89 | 90 | #with the help of glcm find the correlation 91 | correlation = greycoprops(g,prop= 'correlation') 92 | f8=correlation[0][0]+correlation[0][1]+correlation[0][2]+correlation[0][3] 93 | 94 | 95 | 96 | l = {'area':area, 'perimeter': perimeter,'red_mean': red_mean, 'green_mean': green_mean, 97 | 'blue_mean': blue_mean,'f1': f1,'f2': f2,'red_std': red_std,'green_std': green_std,'blue_std': blue_std, 98 | 'f4':f4,'f5':f5,'f6':f6,'f7':f7,'f8':f8} 99 | return l -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: plant-disease 4 | random-random: true 5 | memory: 128M -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/models/Applemodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/v4_ibmcloud_failed/models/Applemodel_V1.sav -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/models/Tomatomodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/v4_ibmcloud_failed/models/Tomatomodel_V1.sav -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/models/cornmodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/v4_ibmcloud_failed/models/cornmodel_V1.sav -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/models/grapesmodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/v4_ibmcloud_failed/models/grapesmodel_V1.sav -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/models/potatomodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/api/v4_ibmcloud_failed/models/potatomodel_V1.sav -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/predictor.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def apple_p(feature_vector,model): 4 | processed_vector = np.array(feature_vector).reshape(1, -1) 5 | output = model.predict(processed_vector) 6 | output = int(output) 7 | label_dict = {0 :'Apple___healthy', 1: 'Apple___Apple_scab', 2: 'Apple___Black_rot', 3: 'Apple___Cedar_apple_rust'} 8 | output = label_dict[output] 9 | return output 10 | 11 | def corn_p(feature_vector,model): 12 | processed_vector = np.array(feature_vector).reshape(1, -1) 13 | output = model.predict(processed_vector) 14 | output = int(output) 15 | label_dict = {0: 'Corn_(maize)___healthy', 16 | 1: 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot', 17 | 2: 'Corn_(maize)__Common_rust', 18 | 3: 'Corn_(maize)___Northern_Leaf_Blight'} 19 | output = label_dict[output] 20 | return output 21 | 22 | def grapes_p(feature_vector,model): 23 | processed_vector = np.array(feature_vector).reshape(1, -1) 24 | output = model.predict(processed_vector) 25 | output = int(output) 26 | label_dict = {0 : 'Grape___healthy', 27 | 1 : 'Grape___Black_rot', 28 | 2 : 'Grape___Esca_(Black_Measles)', 29 | 3 : 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)'} 30 | output = label_dict[output] 31 | return output 32 | 33 | def potato_p(feature_vector,model): 34 | processed_vector = np.array(feature_vector).reshape(1, -1) 35 | output = model.predict(processed_vector) 36 | output = int(output) 37 | label_dict = {0: 'Potato___healthy', 38 | 1: 'Potato___Early_blight', 39 | 2: 'Potato___Late_blight'} 40 | output = label_dict[output] 41 | return output 42 | 43 | def tomato_p(feature_vector,model): 44 | processed_vector = np.array(feature_vector).reshape(1, -1) 45 | output = model.predict(processed_vector) 46 | output = int(output) 47 | label_dict = {0 : 'Tomato___healthy', 48 | 1 : 'Tomato___Bacterial_spot', 49 | 2 : 'Tomato___Early_blight', 50 | 3 : 'Tomato___Late_blight', 51 | 4 : 'Tomato___Leaf_Mold', 52 | 5 : 'Tomato___Septoria_leaf_spot', 53 | 6 : 'Tomato___Spider_mites Two-spotted_spider_mite', 54 | 7 : 'Tomato___Target_Spot', 55 | 8 : 'Tomato___Tomato_Yellow_Leaf_Curl_Virus', 56 | 9 : 'Tomato___Tomato_mosaic_virus'} 57 | output = label_dict[output] 58 | return output 59 | 60 | -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==1.1.2 2 | numpy==1.19.5 3 | opencv-python==4.5.1.48 4 | scikit-image==0.18.1 5 | scikit-learn==0.24.1 6 | opencv-python-headless==4.5.1.48 -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.8.9 -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/server.py: -------------------------------------------------------------------------------- 1 | ############################################################### 2 | # Plant disease detection 3 | # API V2 4 | # Version 1.1 5 | # API Main Script 6 | ############################################################### 7 | 8 | ############################################################### 9 | # Importing required Libraries and modules 10 | import imageprocess 11 | import predictor 12 | import pickle 13 | import os 14 | from flask import Flask 15 | import flask 16 | from flask import request 17 | from flask import render_template 18 | import numpy as np 19 | import cv2 20 | ############################################################## 21 | 22 | 23 | app = Flask(__name__) 24 | 25 | 26 | port = int (os.getenv("VCAP_APP_PORT", 5000)) 27 | 28 | applemodelpath = 'models/Applemodel_V1.sav' 29 | apple_model = pickle.load(open(applemodelpath, 'rb')) 30 | 31 | cornmodelpath = 'models/cornmodel_V1.sav' 32 | corn_model = pickle.load(open(cornmodelpath, 'rb')) 33 | 34 | grapesmodelpath = 'models/grapesmodel_V1.sav' 35 | grapes_model = pickle.load(open(grapesmodelpath, 'rb')) 36 | 37 | potatomodelpath = 'models/potatomodel_V1.sav' 38 | potato_model = pickle.load(open(potatomodelpath, 'rb')) 39 | 40 | tomatomodelpath = 'models/Tomatomodel_V1.sav' 41 | tomato_model = pickle.load(open(tomatomodelpath, 'rb')) 42 | 43 | 44 | @app.route("/") 45 | def home(): 46 | version = "1.1" 47 | return render_template('index.html', version1 = version) 48 | 49 | @app.route("/predict", methods = ['GET', 'POST']) 50 | def submit(): 51 | imagefile = flask.request.files["data_file"].read() 52 | dname = request.form.get('Name') 53 | dname = str(dname) 54 | response = dname[0] 55 | npimg = np.frombuffer(imagefile, np.uint8) 56 | # convert numpy array to image 57 | img = cv2.imdecode(npimg,cv2.IMREAD_COLOR) 58 | 59 | f_vector = imageprocess.feature_extractor(img) 60 | 61 | if response=='n': 62 | res = "Please select the appropriate plant from the list" 63 | return '

'+res+'

' 64 | 65 | if response=='a': 66 | p_vector = [f_vector['area'],f_vector['perimeter'],f_vector['red_mean'],f_vector['blue_mean'],f_vector['f2'],f_vector['green_std'], 67 | f_vector['f4'],f_vector['f6'],f_vector['f7']] 68 | 69 | res = predictor.apple_p(p_vector,apple_model) 70 | return '

'+res+'

' 71 | 72 | if response=='c': 73 | p_vector = [f_vector['red_mean'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], f_vector['red_std'], f_vector['blue_std'], 74 | f_vector['f7'], f_vector['f8']] 75 | 76 | res = predictor.corn_p(p_vector,corn_model) 77 | return '

'+res+'

' 78 | 79 | if response=='g': 80 | p_vector = [f_vector['area'], f_vector['perimeter'], f_vector['red_mean'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], 81 | f_vector['red_std'], f_vector['green_std'], f_vector['blue_std'], f_vector['f4'], f_vector['f5'], f_vector['f6'], f_vector['f7'], f_vector['f8']] 82 | 83 | res = predictor.grapes_p(p_vector,grapes_model) 84 | return '

'+res+'

' 85 | 86 | if response=='p': 87 | p_vector = [f_vector['area'], f_vector['perimeter'], f_vector['green_mean'], f_vector['blue_mean'], f_vector['f2'], f_vector['red_std'], 88 | f_vector['green_std'], f_vector['blue_std'], f_vector['f4'], f_vector['f5'], f_vector['f7'], f_vector['f8']] 89 | 90 | res = predictor.potato_p(p_vector,potato_model) 91 | return '

'+res+'

' 92 | 93 | if response=='t': 94 | del f_vector["f1"] 95 | p_vector = list(f_vector.values()) 96 | 97 | res = predictor.tomato_p(p_vector,tomato_model) 98 | return '

'+res+'

' 99 | 100 | if __name__ == "__main__": 101 | app.run(host='0.0.0.0', port=port) -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | from codecs import open 3 | from os import path 4 | 5 | here = path.abspath( path.dirname( __file__ ) ) 6 | 7 | setup( 8 | name='app-name', 9 | version='1.0.2', 10 | description='Python Flask app for uploading images to a pre-built WAtson custom classifier and viewing results in a web app', 11 | license='Apache-2.0' 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/static/style1.css: -------------------------------------------------------------------------------- 1 | /* static/style.css */ 2 | 3 | h1 { 4 | color: navajowhite; 5 | font-variant-caps: all-small-caps; 6 | font-size: 46px; 7 | } 8 | 9 | h3 { 10 | color: white; 11 | font-size: 25px; 12 | } 13 | 14 | li { 15 | color: blue; 16 | font-size: 12px; 17 | } 18 | 19 | p { 20 | color: white; 21 | font-size: 12px; 22 | } 23 | 24 | body { 25 | background: black; 26 | } -------------------------------------------------------------------------------- /api/v4_ibmcloud_failed/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Plant disease detector 5 | 6 | 7 | 15 | 16 |

Plant disease detection Application

17 |

Version: {{version1}}

18 |

Fill up these details and upload the image

19 | 20 |
21 |

Plant Name:

22 | 23 | 31 | 32 |

Image

33 | 34 | 35 |
36 | 37 | -------------------------------------------------------------------------------- /da_and_md/apple/Applemodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/apple/Applemodel_V1.sav -------------------------------------------------------------------------------- /da_and_md/apple/acuuracyandf1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/apple/acuuracyandf1.png -------------------------------------------------------------------------------- /da_and_md/apple/cf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/apple/cf.png -------------------------------------------------------------------------------- /da_and_md/apple/correlation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/apple/correlation.png -------------------------------------------------------------------------------- /da_and_md/apple/roc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/apple/roc.png -------------------------------------------------------------------------------- /da_and_md/corn/accuracy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/corn/accuracy.png -------------------------------------------------------------------------------- /da_and_md/corn/cf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/corn/cf.png -------------------------------------------------------------------------------- /da_and_md/corn/cornmodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/corn/cornmodel_V1.sav -------------------------------------------------------------------------------- /da_and_md/corn/correlation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/corn/correlation.png -------------------------------------------------------------------------------- /da_and_md/corn/roc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/corn/roc.png -------------------------------------------------------------------------------- /da_and_md/grapes/accuracy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/grapes/accuracy.png -------------------------------------------------------------------------------- /da_and_md/grapes/cf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/grapes/cf.png -------------------------------------------------------------------------------- /da_and_md/grapes/correlation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/grapes/correlation.png -------------------------------------------------------------------------------- /da_and_md/grapes/grapesmodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/grapes/grapesmodel_V1.sav -------------------------------------------------------------------------------- /da_and_md/grapes/roc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/grapes/roc.png -------------------------------------------------------------------------------- /da_and_md/potato/accuracy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/potato/accuracy.png -------------------------------------------------------------------------------- /da_and_md/potato/cf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/potato/cf.png -------------------------------------------------------------------------------- /da_and_md/potato/correlation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/potato/correlation.png -------------------------------------------------------------------------------- /da_and_md/potato/potatomodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/potato/potatomodel_V1.sav -------------------------------------------------------------------------------- /da_and_md/potato/roc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/potato/roc.png -------------------------------------------------------------------------------- /da_and_md/tomato/Tomatomodel_V1.sav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/tomato/Tomatomodel_V1.sav -------------------------------------------------------------------------------- /da_and_md/tomato/accuracy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/tomato/accuracy.png -------------------------------------------------------------------------------- /da_and_md/tomato/cf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/tomato/cf.png -------------------------------------------------------------------------------- /da_and_md/tomato/correlation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/tomato/correlation.png -------------------------------------------------------------------------------- /da_and_md/tomato/roc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/da_and_md/tomato/roc.png -------------------------------------------------------------------------------- /dataset/hist/apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/dataset/hist/apple.png -------------------------------------------------------------------------------- /dataset/hist/corn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/dataset/hist/corn.png -------------------------------------------------------------------------------- /dataset/hist/grapes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/dataset/hist/grapes.png -------------------------------------------------------------------------------- /dataset/hist/potato.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/dataset/hist/potato.png -------------------------------------------------------------------------------- /dataset/hist/tomato.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/dataset/hist/tomato.png -------------------------------------------------------------------------------- /dataset/processed datasets/dataset_apple.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/dataset/processed datasets/dataset_apple.xlsx -------------------------------------------------------------------------------- /dataset/processed datasets/dataset_corn.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/dataset/processed datasets/dataset_corn.xlsx -------------------------------------------------------------------------------- /dataset/processed datasets/dataset_grapes.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/dataset/processed datasets/dataset_grapes.xlsx -------------------------------------------------------------------------------- /dataset/processed datasets/dataset_potato.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/dataset/processed datasets/dataset_potato.xlsx -------------------------------------------------------------------------------- /dataset/processed datasets/dataset_tomato.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/dataset/processed datasets/dataset_tomato.xlsx -------------------------------------------------------------------------------- /process_image.py: -------------------------------------------------------------------------------- 1 | def feature_extractor(filename): 2 | ''' 3 | input params: 4 | filename : path of the file that we want to process 5 | 6 | Output params: 7 | l : Feature vector 8 | ''' 9 | 10 | try: 11 | main_img = cv2.imread(filename) 12 | img = cv2.cvtColor(main_img, cv2.COLOR_BGR2RGB) 13 | except: 14 | return "Invalid" 15 | 16 | #Preprocessing 17 | 18 | 19 | gs = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY) 20 | blur = cv2.GaussianBlur(gs, (25,25),0) 21 | ret_otsu,im_bw_otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) 22 | kernel = np.ones((25,25),np.uint8) 23 | closing = cv2.morphologyEx(im_bw_otsu, cv2.MORPH_CLOSE, kernel) 24 | 25 | #Shape features 26 | contours, _ = cv2.findContours(closing,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) 27 | cnt = contours[0] 28 | M = cv2.moments(cnt) 29 | area = cv2.contourArea(cnt) 30 | if area==0: 31 | return "Invalid" 32 | perimeter = cv2.arcLength(cnt,True) 33 | 34 | current_frame = main_img 35 | filtered_image = closing/255 36 | 37 | #Elementwise Multiplication of range bounded filtered_image with current_frame 38 | current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 0] = np.multiply(current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 0], filtered_image) #B channel 39 | current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 1] = np.multiply(current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 1], filtered_image) #G channel 40 | current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 2] = np.multiply(current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 2], filtered_image) #R channel 41 | 42 | img = current_frame 43 | 44 | 45 | #Color features 46 | red_channel = img[:,:,0] 47 | green_channel = img[:,:,1] #show the intensities of green channe 48 | blue_channel = img[:,:,2] 49 | 50 | red_mean = np.mean(red_channel) 51 | green_mean = np.mean(green_channel) 52 | blue_mean = np.mean(blue_channel) 53 | #standard deviation for colour feature from the image. 54 | red_std = np.std(red_channel) 55 | green_std = np.std(green_channel) 56 | blue_std = np.std(blue_channel) 57 | 58 | #amt.of green color in the image 59 | gr = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) 60 | boundaries = [([30,0,0],[70,255,255])] 61 | for (lower, upper) in boundaries: 62 | mask = cv2.inRange(gr, (36, 0, 0), (70, 255,255)) 63 | ratio_green = cv2.countNonZero(mask)/(img.size/3) 64 | f1=np.round(ratio_green, 2) 65 | #amt. of non green part of the image 66 | f2=1-f1 67 | 68 | #Texture features using grey level cooccurance matrix 69 | img=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 70 | g=greycomatrix(img, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4]) 71 | 72 | #with the help of glcm find the contrast 73 | contrast = greycoprops(g, 'contrast') 74 | f4=contrast[0][0]+contrast[0][1]+contrast[0][2]+contrast[0][3] 75 | #[0][3] represent no. of times grey level 3 appears at the right of 0 76 | 77 | 78 | #with the help of glcm find the dissimilarity 79 | dissimilarity = greycoprops(g, prop='dissimilarity') 80 | f5=dissimilarity[0][0]+dissimilarity[0][1]+dissimilarity[0][2]+dissimilarity[0][3] 81 | 82 | #with the help of glcm find the homogeneity 83 | homogeneity = greycoprops(g, prop='homogeneity') 84 | f6=homogeneity[0][0]+homogeneity[0][1]+homogeneity[0][2]+homogeneity[0][3] 85 | 86 | #with the help of glcm find the energy. 87 | energy = greycoprops(g, prop='energy') 88 | f7=energy[0][0]+energy[0][1]+energy[0][2]+energy[0][3] 89 | 90 | 91 | #with the help of glcm find the correlation 92 | correlation = greycoprops(g,prop= 'correlation') 93 | f8=correlation[0][0]+correlation[0][1]+correlation[0][2]+correlation[0][3] 94 | 95 | 96 | 97 | l = [area, perimeter, red_mean, green_mean, blue_mean, 98 | f1, f2, red_std, green_std, blue_std, 99 | f4,f5,f6,f7,f8] 100 | return l -------------------------------------------------------------------------------- /report/1_g8.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/report/1_g8.JPG -------------------------------------------------------------------------------- /report/2_greayscale.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/report/2_greayscale.png -------------------------------------------------------------------------------- /report/3_blur.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/report/3_blur.png -------------------------------------------------------------------------------- /report/4_otsus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/report/4_otsus.png -------------------------------------------------------------------------------- /report/5_closing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/report/5_closing.png -------------------------------------------------------------------------------- /report/closing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/report/closing.png -------------------------------------------------------------------------------- /report/final_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/report/final_output.png -------------------------------------------------------------------------------- /report/final_report/COURSE PROJECT report.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pranesh6767/Plant-Disease-Detection-Using-Digital-Image-Processing/3a420fcb865666f3b06fd07e8b3c1520e1ea2fa3/report/final_report/COURSE PROJECT report.docx -------------------------------------------------------------------------------- /report/ipsteps.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | filename = '1_g8.jpg' 5 | main_img = cv2.imread(filename) 6 | img = cv2.cvtColor(main_img, cv2.COLOR_BGR2RGB) 7 | #except: 8 | # return "Invalid" 9 | 10 | #Preprocessing 11 | 12 | 13 | gs = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY) 14 | #cv2.imwrite('greayscale.png',gs) 15 | 16 | blur = cv2.GaussianBlur(gs, (25,25),0) 17 | #cv2.imwrite('blur.png',blur) 18 | 19 | ret_otsu,im_bw_otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) 20 | #cv2.imwrite('otsus.png',im_bw_otsu) 21 | 22 | kernel = np.ones((25,25),np.uint8) 23 | closing = cv2.morphologyEx(im_bw_otsu, cv2.MORPH_CLOSE, kernel) 24 | cv2.imwrite('closing.png',closing) 25 | 26 | 27 | #Shape features 28 | contours, _ = cv2.findContours(closing,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) 29 | #cv2.imwrite('contours.png',contours) 30 | cnt = contours[0] 31 | 32 | current_frame = main_img 33 | filtered_image = closing/255 34 | 35 | #Elementwise Multiplication of range bounded filtered_image with current_frame 36 | current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 0] = np.multiply(current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 0], filtered_image) #B channel 37 | current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 1] = np.multiply(current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 1], filtered_image) #G channel 38 | current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 2] = np.multiply(current_frame[0:current_frame.shape[0], 0:current_frame.shape[1], 2], filtered_image) #R channel 39 | 40 | cv2.imwrite('final_output.png',current_frame) 41 | --------------------------------------------------------------------------------