152 lines
3.5 KiB
Text
152 lines
3.5 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "e2a5d1d7-6bb3-4e24-9067-880296de1fc9",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"import imageio\n",
|
|
"from skimage import color, transform\n",
|
|
"import numpy as np\n",
|
|
"import pandas as pd"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "b37f1351-0a00-4a4b-9067-ea55a662bc80",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"main_folder = 'data/Bel_Training_Set/'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "76f41177-fd53-4bf6-9e75-ba1a98c414ff",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"subfolders = [f for f in os.listdir(main_folder) if os.path.isdir(os.path.join(main_folder, f))]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "706d2a6d-8147-42a1-ba19-3cc7108fcfea",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"image_data = []\n",
|
|
"label_data = []"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "86841170-b9bc-46cf-b482-f2d653060bc0",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"docnames = [\"Pixel \" + str(i) for i in range(1024)]\n",
|
|
"docnames.insert(0, 'Label')\n",
|
|
"df1 = pd.DataFrame(columns = docnames) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "d9e5d953-1652-47d3-a832-d71d87c2b7ee",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"def add_to_dataset(x,y,z,l):\n",
|
|
" y.at[z,'Label'] = l\n",
|
|
" for i in range(0,1024):\n",
|
|
" y.at[z,docnames[i+1]] = x[i]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"id": "82fe02ed-8471-493f-aded-58c54edb7ef6",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"i = 0\n",
|
|
"for subfolder in subfolders:\n",
|
|
" subfolder_path = os.path.join(main_folder, subfolder)\n",
|
|
" for filename in os.listdir(subfolder_path):\n",
|
|
" \n",
|
|
" file_path = os.path.join(subfolder_path, filename)\n",
|
|
" if filename.lower().endswith('.ppm'):\n",
|
|
" img_array = imageio.v2.imread(file_path)\n",
|
|
" resized_img_array = transform.resize(img_array, (32, 32))\n",
|
|
" gray_img_array = color.rgb2gray(resized_img_array)\n",
|
|
" flattened_img_array = gray_img_array.flatten()\n",
|
|
" add_to_dataset(flattened_img_array,df1,i,int(subfolder))\n",
|
|
" i = i + 1\n",
|
|
" #print(\"Image From\", int(subfolder), \"Image Name\", filename)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"id": "7bdcd7d7-56f3-4b9f-924f-dd811dddf605",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"df1.to_csv('bel_data_test.csv', index = False) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "12d9c974-85ed-4d10-af2e-0984a367d4be",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"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.7.16"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|