update models and jupyter files

parent 5925c870
.ipynb_checkpoints/ organic dataset
organic dataset/ mobile captures
mobile captures/ \ No newline at end of file
\ No newline at end of file
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import cv2\n",
"import numpy as np\n",
"import pandas as pd\n",
"import mahotas as mt\n",
"from matplotlib import pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'ds_path' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-2-a2d39a958a1b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mdatas_path\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"..\\\\organic dataset\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mimg_files\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlistdir\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mds_path\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mNameError\u001b[0m: name 'ds_path' is not defined"
]
}
],
"source": [
"datas_path = \"..\\\\organic dataset\"\n",
"img_files = os.listdir(ds_path)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def create_dataset():\n",
" names = ['area','perimeter','physiological_length','physiological_width','aspect_ratio','rectangularity','circularity', \\\n",
" 'mean_r','mean_g','mean_b','stddev_r','stddev_g','stddev_b', \\\n",
" 'contrast','correlation','inverse_difference_moments','entropy'\n",
" ]\n",
" df = pd.DataFrame([], columns=names)\n",
" for file in img_files:\n",
" imgpath = ds_path + \"\\\\\" + file\n",
" main_img = cv2.imread(imgpath)\n",
" \n",
" #Preprocessing\n",
" img = cv2.cvtColor(main_img, cv2.COLOR_BGR2RGB)\n",
" gs = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)\n",
" blur = cv2.GaussianBlur(gs, (5,5),0)\n",
" ret_otsu,im_bw_otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)\n",
" kernel = np.ones((50,50),np.uint8)\n",
" closing = cv2.morphologyEx(im_bw_otsu, cv2.MORPH_CLOSE, kernel)\n",
" \n",
" #Shape features\n",
" contours, _ = cv2.findContours(closing,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)\n",
" cnt = contours[0]\n",
" M = cv2.moments(cnt)\n",
" area = cv2.contourArea(cnt)\n",
" perimeter = cv2.arcLength(cnt,True)\n",
" x,y,w,h = cv2.boundingRect(cnt)\n",
" aspect_ratio = float(w)/h\n",
" rectangularity = w*h/area\n",
" circularity = ((perimeter)**2)/area\n",
" \n",
" #Color features\n",
" red_channel = img[:,:,0]\n",
" green_channel = img[:,:,1]\n",
" blue_channel = img[:,:,2]\n",
" blue_channel[blue_channel == 255] = 0\n",
" green_channel[green_channel == 255] = 0\n",
" red_channel[red_channel == 255] = 0\n",
" \n",
" red_mean = np.mean(red_channel)\n",
" green_mean = np.mean(green_channel)\n",
" blue_mean = np.mean(blue_channel)\n",
" \n",
" red_std = np.std(red_channel)\n",
" green_std = np.std(green_channel)\n",
" blue_std = np.std(blue_channel)\n",
" \n",
" #Texture features\n",
" textures = mt.features.haralick(gs)\n",
" ht_mean = textures.mean(axis=0)\n",
" contrast = ht_mean[1]\n",
" correlation = ht_mean[2]\n",
" inverse_diff_moments = ht_mean[4]\n",
" entropy = ht_mean[8]\n",
" \n",
" vector = [area,perimeter,w,h,aspect_ratio,rectangularity,circularity,\\\n",
" red_mean,green_mean,blue_mean,red_std,green_std,blue_std,\\\n",
" contrast,correlation,inverse_diff_moments,entropy\n",
" ]\n",
" \n",
" df_temp = pd.DataFrame([vector],columns=names)\n",
" df = df.append(df_temp)\n",
" print(file)\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"101.jpg\n",
"102.jpg\n",
"103.jpg\n",
"104.jpg\n",
"105.jpg\n",
"106.jpg\n",
"107.jpg\n",
"108.jpg\n",
"109.jpg\n",
"110.jpg\n",
"111.jpg\n",
"112.jpg\n",
"113.jpg\n",
"114.jpg\n",
"115.jpg\n",
"116.jpg\n",
"117.jpg\n",
"118.jpg\n",
"120.jpg\n",
"121.jpg\n",
"122.jpg\n",
"123.jpg\n",
"124.jpg\n",
"125.jpg\n",
"126.jpg\n",
"127.jpg\n",
"128.jpg\n",
"129.jpg\n",
"130.jpg\n",
"131.jpg\n",
"132.jpg\n",
"133.jpg\n",
"134.jpg\n",
"135.jpg\n",
"136.jpg\n",
"137.jpg\n",
"138.jpg\n",
"139.jpg\n",
"140.jpg\n",
"141.jpg\n",
"142.jpg\n",
"143.jpg\n",
"144.jpg\n",
"145.jpg\n",
"146.jpg\n",
"147.jpg\n",
"148.jpg\n",
"149.jpg\n",
"150.jpg\n",
"151.jpg\n",
"152.jpg\n",
"153.jpg\n",
"154.jpg\n",
"155.jpg\n",
"156.jpg\n",
"157.jpg\n",
"158.jpg\n",
"159.jpg\n",
"160.jpg\n",
"161.jpg\n",
"162.jpg\n",
"163.jpg\n",
"164.jpg\n",
"165.jpg\n",
"166.jpg\n",
"167.jpg\n",
"168.jpg\n",
"169.jpg\n",
"170.jpg\n",
"171.jpg\n",
"172.jpg\n",
"173.jpg\n",
"174.jpg\n",
"175.jpg\n",
"176.jpg\n",
"177.jpg\n",
"178.jpg\n",
"179.jpg\n",
"180.jpg\n",
"181.jpg\n",
"182.jpg\n",
"183.jpg\n",
"184.jpg\n",
"185.jpg\n",
"186.jpg\n",
"187.jpg\n",
"188.jpg\n",
"189.jpg\n",
"190.jpg\n",
"191.jpg\n",
"192.jpg\n",
"193.jpg\n",
"194.jpg\n",
"195.jpg\n",
"196.jpg\n",
"197.jpg\n",
"198.jpg\n",
"199.jpg\n",
"200.jpg\n",
"201.jpg\n",
"202.jpg\n",
"203.jpg\n",
"204.jpg\n",
"205.jpg\n",
"206.jpg\n"
]
}
],
"source": [
"dataset = create_dataset()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(105, 17)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dataset.shape"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas.core.frame.DataFrame"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(dataset)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"dataset.to_csv(\"organic_inorganic.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
" imgpath = dataset_path + \"\\\\\" + file\n", " imgpath = dataset_path + \"\\\\\" + file\n",
" main_img = cv2.imread(imgpath)\n", " main_img = cv2.imread(imgpath)\n",
" \n", " \n",
" \n",
" #Preprocessing\n", " #Preprocessing\n",
" img = cv2.cvtColor(main_img, cv2.COLOR_BGR2RGB)\n", " img = cv2.cvtColor(main_img, cv2.COLOR_BGR2RGB)\n",
" gr_scale = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)\n", " gr_scale = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)\n",
...@@ -97,7 +98,7 @@ ...@@ -97,7 +98,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -122,6 +123,7 @@ ...@@ -122,6 +123,7 @@
"116.jpg\n", "116.jpg\n",
"117.jpg\n", "117.jpg\n",
"118.jpg\n", "118.jpg\n",
"119.jpg\n",
"120.jpg\n", "120.jpg\n",
"121.jpg\n", "121.jpg\n",
"122.jpg\n", "122.jpg\n",
...@@ -208,7 +210,117 @@ ...@@ -208,7 +210,117 @@
"203.jpg\n", "203.jpg\n",
"204.jpg\n", "204.jpg\n",
"205.jpg\n", "205.jpg\n",
"206.jpg\n" "206.jpg\n",
"207.jpg\n",
"208.jpg\n",
"209.jpg\n",
"210.jpg\n",
"211.jpg\n",
"212.jpg\n",
"213.jpg\n",
"214.jpg\n",
"215.jpg\n",
"216.jpg\n",
"217.jpg\n",
"218.jpg\n",
"219.jpg\n",
"220.jpg\n",
"221.jpg\n",
"222.jpg\n",
"223.jpg\n",
"224.jpg\n",
"225.jpg\n",
"226.jpg\n",
"227.jpg\n",
"228.jpg\n",
"229.jpg\n",
"230.jpg\n",
"231.jpg\n",
"232.jpg\n",
"233.jpg\n",
"234.jpg\n",
"235.jpg\n",
"236.jpg\n",
"237.jpg\n",
"238.jpg\n",
"239.jpg\n",
"240.jpg\n",
"241.jpg\n",
"242.jpg\n",
"243.jpg\n",
"244.jpg\n",
"245.jpg\n",
"246.jpg\n",
"247.jpg\n",
"248.jpg\n",
"249.jpg\n",
"250.jpg\n",
"252.jpg\n",
"253.jpg\n",
"254.jpg\n",
"255.jpg\n",
"256.jpg\n",
"257.jpg\n",
"258.jpg\n",
"259.jpg\n",
"260.jpg\n",
"261.jpg\n",
"262.jpg\n",
"263.jpg\n",
"264.jpg\n",
"265.jpg\n",
"266.jpg\n",
"267.jpg\n",
"268.jpg\n",
"269.jpg\n",
"270.jpg\n",
"271.jpg\n",
"272.jpg\n",
"273.jpg\n",
"274.jpg\n",
"275.jpg\n",
"276.jpg\n",
"277.jpg\n",
"278.jpg\n",
"279.jpg\n",
"280.jpg\n",
"281.jpg\n",
"282.jpg\n",
"283.jpg\n",
"284.jpg\n",
"285.jpg\n",
"286.jpg\n",
"287.jpg\n",
"288.jpg\n",
"289.jpg\n",
"290.jpg\n",
"291.jpg\n",
"292.jpg\n",
"293.jpg\n",
"294.jpg\n",
"295.jpg\n",
"296.jpg\n",
"297.jpg\n",
"298.jpg\n",
"299.jpg\n",
"300.jpg\n",
"301.jpg\n",
"302.jpg\n",
"303.jpg\n",
"304.jpg\n",
"305.jpg\n",
"306.jpg\n",
"307.jpg\n",
"308.jpg\n",
"309.jpg\n",
"310.jpg\n",
"311.jpg\n",
"312.jpg\n",
"313.jpg\n",
"314.jpg\n",
"315.jpg\n",
"316.jpg\n",
"317.jpg\n"
] ]
} }
], ],
...@@ -218,16 +330,16 @@ ...@@ -218,16 +330,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"(105, 17)" "(216, 17)"
] ]
}, },
"execution_count": 17, "execution_count": 15,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -238,7 +350,7 @@ ...@@ -238,7 +350,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 16,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -247,7 +359,7 @@ ...@@ -247,7 +359,7 @@
"pandas.core.frame.DataFrame" "pandas.core.frame.DataFrame"
] ]
}, },
"execution_count": 18, "execution_count": 16,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -258,7 +370,7 @@ ...@@ -258,7 +370,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 17,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment