Skip to content

Commit

Permalink
update crop rice and count frame
Browse files Browse the repository at this point in the history
  • Loading branch information
nrhevu committed Oct 15, 2024
1 parent 0422dce commit bed1291
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 2 additions & 7 deletions count_rice.ipynb
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# wlXlv Image"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -19,6 +12,7 @@
"from PIL import Image\n",
"from scipy import ndimage\n",
"\n",
"\n",
"def count_rice_number(img_path):\n",
" # Load the uploaded image\n",
" img = cv2.imread(img_path)\n",
Expand All @@ -31,6 +25,7 @@
" ##### Add MedianFilter to remove salt and pepper noise #####\n",
" ############################################################\n",
" gray = cv2.medianBlur(gray, 3)\n",
" gray = cv2.GaussianBlur(gray, (3, 3), 0)\n",
"\n",
" #############################################\n",
" ######## Apply Fourier Transform ############\n",
Expand Down
7 changes: 5 additions & 2 deletions crop_frame.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
"outputs": [],
"source": [
"import math\n",
"\n",
"import cv2\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from PIL import Image\n",
"from scipy import ndimage\n",
"\n",
"\n",
"def crop_cell(img_path):\n",
" # Load the uploaded image\n",
" img = cv2.imread(img_path)\n",
Expand Down Expand Up @@ -71,7 +74,7 @@
" \n",
" ######### PREPROCESS THE ROTATED IMAGE TO DETECT CELL ###########\n",
" ## Convert image to grayscale image \n",
" gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n",
" gray = cv2.cvtColor(rotated_image_raw, cv2.COLOR_BGR2GRAY)\n",
" ## Apply Gaussian Blur for smoothing\n",
" gray = cv2.GaussianBlur(gray, (5, 5), 4) \n",
" # Define the gamma value\n",
Expand Down Expand Up @@ -132,7 +135,7 @@
" sorted_contours = sort_contours(filtered_contours)\n",
" \n",
" print(f\"Number of cells : {len(sorted_contours)}\")\n",
" fig, ax = plt.subplots(math.ceil(len(sorted_contours) / 4), 4, figsize=(12, 6))\n",
" fig, ax = plt.subplots(math.ceil(len(sorted_contours) / 4), 4, figsize=(8, 6))\n",
" for a in ax.ravel():\n",
" a.axis('off')\n",
" print(ax.shape)\n",
Expand Down

0 comments on commit bed1291

Please sign in to comment.