M2_SETI/D3/TP/TP_SETI_Kmeans/TP1.ipynb

501 lines
575 KiB
Text
Raw Permalink Normal View History

2022-11-28 11:40:47 +01:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TP1 KMEANS\n",
"\n",
"On nous propose de coder l'algorithme des kmeans afin de faire du clustering sur 2 classes puis plus de 2 classes.\n",
"Plus tard, on utilisera notre algorithme pour segmenter une image sur l'information de couleur."
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 3,
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import scipy.spatial\n",
"from skimage import io"
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 4,
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
2023-01-05 20:28:08 +01:00
"clusters = 2\n",
2022-11-28 11:40:47 +01:00
"dim = 2\n",
2022-12-08 22:12:07 +01:00
"nb = 50\n",
2023-01-05 20:28:08 +01:00
"K = clusters\n",
"mean = np.random.randint(5, size=clusters)*2\n",
2022-11-29 12:15:07 +01:00
"mean = mean.T * np.random.random(size=clusters)\n",
2023-01-05 20:28:08 +01:00
"sd = np.random.random(size=clusters)"
2022-11-28 11:40:47 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fonctions à utiliser pour le clustering"
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 5,
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def gen_points(mean=1,sd=0.5, nb=100, dim=2, clusters=2):\n",
2023-01-05 20:28:08 +01:00
" \"\"\" Generates data\n",
" dim: dimension\n",
" nb: number of points\n",
" clusters: number of clusters\n",
" mean: mean\n",
" sd: standard deviation \n",
" \"\"\"\n",
2022-11-28 11:40:47 +01:00
" size = []\n",
" # for i in range(0,dim):\n",
" size.append(nb)\n",
" size.append(dim)\n",
" points = np.random.normal(mean[0],sd[0],size=size)\n",
" for i in range(1,clusters):\n",
" points = np.concatenate((points,np.random.normal(mean[i],sd[i],size=size)),axis=0)\n",
" \n",
2022-11-29 12:15:07 +01:00
" return points, mean"
2022-11-28 11:40:47 +01:00
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 6,
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def distance(points,Pc): \n",
2023-01-05 20:28:08 +01:00
" \"\"\" Returns spatial distance between two matrix\n",
" \"\"\"\n",
2022-11-28 11:40:47 +01:00
" return scipy.spatial.distance.cdist(points[:,:], Pc[:,:])"
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 7,
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def kmeans(points = [0,0], K = 1):\n",
2023-01-05 20:28:08 +01:00
" \"\"\" Create K clusters from points\n",
" \"\"\"\n",
2022-11-28 11:40:47 +01:00
" # Initialisation K prototypes\n",
" dim = points.shape[1]\n",
" N = points.shape[0]\n",
" iter = 0\n",
" eps = 0.1\n",
" Pc_index = []\n",
" Pc_save = np.zeros([K,dim])\n",
" clusters = []\n",
"\n",
" for i in range(0,K):\n",
" Pc_index.append(np.random.randint(0,N))\n",
" Pc = points[Pc_index,:]\n",
"\n",
2022-12-05 18:14:46 +01:00
" while (np.mean(distance(Pc,Pc_save)) > eps and iter < 3):\n",
2022-11-28 11:40:47 +01:00
" iter += 1\n",
" Pc_save = Pc\n",
" # print(Pc)\n",
" # print(points[:,:Pc.shape[0]])\n",
" dist = distance(points=points[:,:Pc.shape[1]],Pc=Pc)\n",
" clust = np.argmin(dist, axis=1)\n",
" clust = np.expand_dims(clust, axis=0)\n",
" points = np.append(points[:,:Pc.shape[1]], clust.T, axis=1)\n",
" # print(points)\n",
" Pc = np.zeros([K,dim])\n",
" index = np.array([])\n",
"\n",
" for n in range(0,N):\n",
" for k in range(0,K):\n",
" index = np.append(index, (clust==k).sum())\n",
" if points[n,-1] == k:\n",
" # print(points)\n",
" # print(Pc)\n",
" Pc[k,:] = np.add(Pc[k,:], points[n,:-1])\n",
"\n",
" for k in range(0,K):\n",
" Pc[k,:] = np.divide(Pc[k,:],index[k])\n",
"\n",
" # print(Pc)\n",
2022-11-29 12:15:07 +01:00
" indice = points[:,-1]\n",
2022-11-28 11:40:47 +01:00
" points = points[:,:-1]\n",
2022-11-29 12:15:07 +01:00
" return Pc, indice, points\n"
2022-11-28 11:40:47 +01:00
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 8,
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"colors=['red', 'green','yellow','blue','purple', 'orange']\n",
"def visualisation(points, index, Pc=[0,0], K=1):\n",
2023-01-05 20:28:08 +01:00
" \"\"\"Visualisation function of a dataset and its K clusters\n",
" \"\"\"\n",
2022-11-28 11:40:47 +01:00
" if(points.shape[1]==2):\n",
" # for k in range(0,K):\n",
" for n in range(0,len(points)):\n",
" plt.plot(points[n,0], points[n,1], 'o', color=colors[int(index[n])])\n",
2023-01-05 20:28:08 +01:00
" plt.plot(Pc[:,0],Pc[:,1],'ko')\n",
2022-11-28 11:40:47 +01:00
" plt.grid(True)\n",
" plt.axis([min(mean)-1,max(mean)+1,min(mean)-1,max(mean)+1])"
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 9,
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def img_2_mat(my_img):\n",
2023-01-05 20:28:08 +01:00
" \"\"\" Reshaping 3D img NxMx3 to 2D matrix N*Mx3\n",
" \"\"\"\n",
2022-11-28 11:40:47 +01:00
" mat = my_img.reshape(my_img.shape[0]*my_img.shape[1],my_img.shape[2])\n",
" return mat"
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 10,
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def mat_2_img(mat,my_img):\n",
2023-01-05 20:28:08 +01:00
" \"\"\" Reshaping 2D matrix N*Mx3 to 3D img NxMx3 \n",
" \"\"\"\n",
2022-11-28 11:40:47 +01:00
" img_seg = mat.reshape(my_img.shape[0], my_img.shape[1], my_img.shape[2])\n",
" return img_seg"
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 11,
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def kmeans_image(path_image, K):\n",
2023-01-05 20:28:08 +01:00
" \"\"\" Clustering an image and changing pixels to its closest cluster\n",
" \"\"\"\n",
2022-11-28 11:40:47 +01:00
" my_img = io.imread(path_image)\n",
" imgplot = plt.imshow(my_img)\n",
" Mat = img_2_mat(my_img)\n",
" \n",
" Pc, index, clusters = kmeans(Mat, K)\n",
"\n",
2022-11-29 12:15:07 +01:00
" for k in range(Mat.shape[0]):\n",
" Mat[k,:] = np.floor(Pc[index[k],:])\n",
2022-11-28 11:40:47 +01:00
"\n",
" img_seg = mat_2_img(Mat, my_img)\n",
"\n",
" io.imsave(path_image.split('.')[0] + \"_%d.jpg\" % K, img_seg)\n",
" imgplot = plt.imshow(img_seg)\n",
" return Pc, index, img_seg\n"
]
},
2023-01-05 20:28:08 +01:00
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exemple\n",
"### Clusterisation 2D\n",
"On fait la clusterisation d'un exemple simple avec 2 nuages de points éloignés"
]
},
2022-11-28 11:40:47 +01:00
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 12,
2023-01-05 20:28:08 +01:00
"metadata": {},
"outputs": [
{
"data": {
2023-01-12 16:00:39 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD4CAYAAADhNOGaAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAnhElEQVR4nO3df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ac223mua05H9k/crq8c6hzxr7sHOo8vb4ZsWVVluNrVGzAPo84pibRWPwicG5o+ZygLJxsjrr7dLA4DFxS6XulvWSp8XV0dJSBgQEmJiZwd8bHxxkYGGB0NFuTvZWalE7zFEklkkgEjwDnm9l5ZrYA6AN2hjcws2WhxauAHwavHwTeb2aLg0bi9wdl0qay1Pg6ODjI8eNFB9HjxxkczNZBtNTBXt1bpRJ1JwJ3PwHcTP4A/kNgh7s/aWa3m9lVwWZ/ZGZPmtnjwB8BNwTvfRn4C/LJ5BHg9qBM2lSWbihy5EjMQTSmPC2lDvZZusKS7EpkZLG7PwA8UFT26dDrTwGfinnv3cDdScQhc0NWRtH29vYyPj4eWZ4lvYt6GT8WEWfQgyncCwvUvVVm08hikRhDQ0N0dhZVU3V2MjQUfxDN0hiIQjfWcldYacQs2aK5hkRi9PfnD5af+MQnmJycpLe3l6GhodPlxbI4BqKwPu7704pZskWJQKSE/v5+li9fHjugLKxZE9BFqbU6LS7mj373o0oEbURVQ9LWkqwWacUeOnGxHX3tqKqI2ogSgbStpG8K34o9dErFprEG7UOJQNpW0oOtsjQGolKlYsvylYwkS4lA2lbSVTmt2EOn/6L+GbdxDcvylYw
2023-01-05 20:28:08 +01:00
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"points1, mean1 = gen_points(mean,sd,nb,dim,clusters)\n",
"Pc1, index1, clusters1 = kmeans(points1,K=K)\n",
"visualisation(clusters1, index1, Pc1, K=K)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Avec un K ne correspondant pas au nombre réel de groupes"
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 13,
2022-11-28 11:40:47 +01:00
"metadata": {},
2023-01-12 16:00:39 +01:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD4CAYAAADhNOGaAAAAOXRFWHRTb2Z0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4GrgkLsfdvdTwA5gY4nHvht42N1PuPuLwMPAdSnEVKDU/4jq3ieVq+bNNq7aaXh0uKTj69GTafDIYGZLSDJdGlNMrAB+FPr8PLkn/EK/ZWa/CjwN3ObuP4o5dkXUl5hZL8FCwkuXLi1rQqtrrungvPNGi+5z9mwbBw/ezNhY6eeNMj4+ntnJthTb7IZHhxk8MsjY5BgdbR30rOrhmtddU1JsNy+/ma3/byuT5yan0trmtHHz8psT/9v+eN8fR95UBw4PsGHvhlmPX8EKbnvTbTP+bSuOr6jadR+bHItMf+7kc5n4XWflby5KrWMzd092ArMbgevcvSf4fAvwdne/NbTPEmDc3SfN7PeBD7j7tWa2BTjP3e8M9vuvwMvuvrXYd1522WV+8ODBMqIsXJweYD7wn4AT5EoC/aQxDfXevXtZu3Zt4vNUg2IrrnCOIMg9Nd/2ptu48wN3lnyO8FTM/ev7U+kxNOdP5+DM/L9qGOc+cy7x+avhDXe9gdHJmQ9gnQs7Ofrxo7UPqEAW/ubiVCs2M3vU3a8qTE+jaugYcFHo84VB2hR3P+7u+cekQeBtpR6bjqiFZ+4BfgqcA46itQgkrrF38MggUFodffeabo5+/CjnPnMu1W6jcdVLHW0dqZy/GnpW9WhgXYNIIyP4PnCpma0ys/nAJmBXeAczWx76eD3ww+D9Q8C7zGxR0Ej8riCtCrrJ3fB145docY26Y5NjVesaWmoDcFwdf8+qnsj9s2DDsg2ZHFgnMyVuI3D
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
2022-11-28 11:40:47 +01:00
"source": [
2023-01-05 20:28:08 +01:00
"K = clusters+1\n",
2022-11-29 12:15:07 +01:00
"points, mean = gen_points(mean,sd,nb,dim,clusters)\n",
2023-01-05 20:28:08 +01:00
"Pc, index, clusters_ex = kmeans(points,K=K)\n",
"visualisation(clusters_ex, index, Pc, K=K)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Et un exemple un peu plus complexe avec des intensités différentes et relativement proche"
2022-11-28 11:40:47 +01:00
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 14,
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
2023-01-05 20:28:08 +01:00
"clusters = 5\n",
"dim = 2\n",
"nb = 50\n",
"K = clusters\n",
"mean = np.random.randint(5, size=clusters)\n",
"mean = mean.T * np.random.random(size=clusters)\n",
"sd = np.random.random(size=clusters)"
2022-11-28 11:40:47 +01:00
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 15,
2022-11-28 11:40:47 +01:00
"metadata": {},
2023-01-12 16:00:39 +01:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD4CAYAAADxeG0DAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAjaklEQVR4nO3dbWxc13kn8P/DEUVprJVcUyKbtc1hDMcEjGibNEZrw7tYyVIBR4AadHebOhgL3t0IA9lNIQMVugUG2NTAzi5QuK30IXZCKE4FcVBDQNI2yioIIkVMNkW9jV04pl+q1FA5XHcDEaJb2jQtmi+nH+5ccl7uue8z9557/z+AoObtzuHV8LmHz3nOOaKUAhERmWsg6QYQEVE0DORERIZjICciMhwDORGR4RjIiYgMty2JN7399tvVvffem8RbG+ODDz7AbbfdlnQzUo3nyBvPkTeTztErr7xyUym1r/P+RAL56OgoXn755STe2hjT09M4cOBA0s1INZ4jbzxH3kw6RyLScLqfqRUiIsMxkBMRGY6BnIjIcAzkRESGYyAnIjIcAzkRkeEYyImIDMdATkRkOAZyIiLDMZATERmOgZyIyHAM5EREhmMgJyIyHAM5EZHhGMiJiAzHQE5EZDgGciIiwzGQExEZjoGciMhwDORERIZjICciMhwDORGR4RjIiYgMFzmQi8gOEfkbEfmpiLwhIs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woBAbyfjKtbMBPb3bnzq1/Dw/rf54os3A17VgZGfF+rWnnnCgEBvJ+M2lwtlYDtm9vv2/7dut+OzAvLGw99uG
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
2022-11-28 11:40:47 +01:00
"source": [
2023-01-05 20:28:08 +01:00
"points, mean = gen_points(mean,sd,nb,dim,clusters)\n",
"Pc, index, clusters_ex = kmeans(points,K=K)\n",
"visualisation(clusters_ex, index, Pc, K=K)"
2022-11-28 11:40:47 +01:00
]
},
{
2023-01-05 20:28:08 +01:00
"attachments": {},
"cell_type": "markdown",
2022-11-28 11:40:47 +01:00
"metadata": {},
"source": [
2023-01-05 20:28:08 +01:00
"## Exemple de clusterisation sur une image\n",
"On souhaite pouvoir changer les pixels vers les le centre du cluster le plus proche.\n",
"\n",
"On observe ainsi pour un nombre différent de clusters :"
2022-11-28 11:40:47 +01:00
]
},
{
"cell_type": "code",
2023-01-12 16:00:39 +01:00
"execution_count": 17,
2023-01-05 20:28:08 +01:00
"metadata": {},
2023-01-12 16:00:39 +01:00
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x1a9ff9b4dc0>"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAUgAAAD8CAYAAAAVOD3kAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOy9d7wkd3nm+/2FSt19wuQ80mg0GuWAIsoIBQQCgYgCY4yx2cXYXnv37q733g1317vrzfde413bBBEkhCRAQoByQDmO8ihN1uR4UodKv3D/qO5zzoxGoBESkpbzzKenu6v7VFVXV7/1hud9XuG9ZwpTmMIUpvBqyLd7B6YwhSlM4Z2KKQM5hSlMYQqv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gS55vNJ03G+z4fij3js8HiEFrbQimAtfYjotEmH4yTU/5KWnnqA/jgiBhfMXsGndOqwK+Ed/9d/AG/r6aqRjQyR9/Ujv8d50U4d+0lYFpfc4KTF4pNacdvKp/PAHP8CVltPPOYcyTVFRTNJXJytylFbd4z+FtwNTOcgp7IMeXaUiPnsvurqHkIQhPu3gs5R853au+dbf843/+p958v670aIgH9mOy5uIfAyRjVGThtbOLdxzy08JsZC1iAOJzVpEEnyZU6YtYulpD+8mCjRJFLB93WqSOCKUikBIhIOyKFB48k4HiSMMFa3RYbbv2MYJp5zCjFmzqvcoRRDHVSHHy3H75Pe6Vf8LfGV8vEd6j8sz+pIIV2Y888gD/M1/+0/c9MMf8OKKh+nTHtcew4wNs33dKgJXIMuMm6+7BlF2uPHaqyh9SXt4FwqLxqK8RXbX3xM6M95jBMgwwBYly44
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAUgAAAD8CAYAAAAVOD3kAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOz9Z4xlaZrfif1ec8y14SMy0pfJ8rbLdLUf1+RwDFdLkcNZUhIhCuIHgYIAQZAI6IMAAQIoCPogAdIuZ3c4u8ulaIYc0+NnuqfNlPeVmVXpXWRk+IgbEdcd8xp9eM+NjKyqHnZPV3XWbMc/cfPeuO6ce8xzHvN//o/w3nOAAxzgAAf4KOTdXoEDHOAAB/is4sBAHuAABzjA98GBgTzAAQ5wgO+DAwN5gAMc4ADfBwcG8gAHOMABvg8ODOQBDnCAA3wffGoGUgjx80KIC0KIy0KIf/ZpLecABzjAAT4tiE+DBymEUMBF4OvAIvAG8F947z/4xBd2gAMc4ACfEj4tD/J54LL3/qr3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HUeoKKUxMU3UmkT7CE+EcJrSlERIsmKXjc4yU2NNGvWYWDXZWtsikh3I38adn+Doc3+bmp9GiAbOGbwKBtcbEzigB3H2XcGBgTzAnai8xT1qSSXVNcqPpWkEZGD6SAqKrQ55PkDoCGPBeklzfJpIxdhiBxWlWCtQOsZ6h7MgvUIhwYUleQc4j/AOgcELhxQSLyQ2gmEpaOigqIOPkFZQExLldtm68SrL5/8cm92grvKKFqlRUlVf/INBAJGWlNmAlVs3wHu0sGilKMo+EoVwOnAwhUI
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAUgAAAD8CAYAAAAVOD3kAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOz9WZBk+XXeCf7+y918jz0j96wdhZ0oUFxFiiJFiW3dMvWMNKNZrB/aTE/zNC+jp3kYszHrl34bs56WbHq6JTNRItUiKYgkSAIkCAprFYAq1F6VVZVb7BEevt31v83D9cjMKqA43UIVijTEl+YRHjfcw6973vvd8z/nO98RIQTOcY5znOMcPwj5Ue/AOc5xjnP8VcU5QZ7jHOc4x/vgnCDPcY5znON9cE6Q5zjHOc7xPjgnyHOc4xzneB+cE+Q5znGOc7wPPjSCFEL8XSHE60KIm0KIf/phvc45znGOc3xYEB+GDlIIoYA3gF8D7gHPAv84hPDKB/5i5zjHOc7xIeHDiiB/GrgZQng7hNAA/xr4+x/Sa53jHOc4x4cC/SH93UvA3Yd+vgf8jfd78Pr6erh+/dqHtCvn+GuPcP8LIN7z/aGHifDQ48J7HvNgpSQQhADi4fjgvX/+bINo74ez5xHa5wqBQEBg+XP7/ezxCA+E5Z+TEORyl0J7a3f4h76P9vk/dKfO8SHhO9/57nEIYeO92z8s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ppUUoDz2KrEGosKso1qadsFvQrIoca5CuUTtJQY70hTRVmeULsFUhq0AmVaSZG2sJ5Jps2MJ6+uUpS7PPuNL/D4kx+n20shaIKToEQblp+T40eKc4I8xw9
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAUgAAAD8CAYAAAAVOD3kAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOz9WbBk2XWeCX5r731Gn+4cU0ZOyAQSBECAJEiqOElkdVFUVaukKlnJVP3SD22mp35vPfdTvfVDm3Vb0dq6S9ZtUrUepJJUlDhoAEkQM5ADch5ijht3vj6eaU/9cDwiIxMAKQlIJNi4v1nEdT/u1/1c93P+s/Za//qXxBi5wAUucIELfC/Ux70DF7jABS7wk4oLgrzABS5wgR+AC4K8wAUucIEfgAuCvMAFLnCBH4ALgrzABS5wgR+AC4K8wAUucIEfgI+MIEXkd0TkLRF5V0T+wUf1Phe4wAUu8FFBPgodpIho4G3gvwDuAd8E/vsY4+s/8je7wAUucIGPCB9VBPlLwLsxxhsxxg74n4G/9RG91wUucIELfCQwH9HrXgPuPnb/HvDLP+jJOzs78emnn/6IduUC//+O77cGku95IIJEIBKJ/V1REOXhs/tnyWPP/56fsv5//Ttx/bKP/U4kgETk0W8+fP33YxH5vnv8PXt/gR8jvv3tb5/EGHc/vP2jIsi/ECLy94G/D/Dkk0/yzW9+8+PalQv8JcAHKGVNdA+3x4ckJwBCjKAiqLB+qkRQEMURJBCCJ3gPCAaNipoA+BhRaQJ4YrSABQmAJ8RIjJCoHEiQqBAUrnOYRPd7oiDigQACIUKIQvARJQlGJ2tyDHyYeN+H4n1SvcCPC0qp299v+0dFkPeB64/df2K97RFijL8L/C7A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1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
2023-01-05 20:28:08 +01:00
"source": [
"path_image = \"images/fruits.jpg\"\n",
2023-01-12 16:00:39 +01:00
"#for i in range(1,13):\n",
" # Pc, index, img_seg = kmeans_image(path_image=path_image, K=i)\n",
2023-01-05 20:28:08 +01:00
"plt.figure()\n",
"plt.imshow(io.imread(\"images/fruits_2.jpg\"))\n",
"plt.figure()\n",
"plt.imshow(io.imread(\"images/fruits_4.jpg\"))\n",
"plt.figure()\n",
"plt.imshow(io.imread(\"images/fruits_10.jpg\"))\n",
"plt.figure()\n",
"plt.imshow(io.imread(\"images/fruits_255_cuda.jpg\"))"
]
},
{
"attachments": {},
"cell_type": "markdown",
2022-11-28 11:40:47 +01:00
"metadata": {},
"source": [
2023-01-05 20:28:08 +01:00
"La clusterisation avec 255 couleurs à été réalisée à l'aide du script `Kmeans_skcuda.py` afin d'accélérer le temps d'exécution. \n",
"\n",
"Nous avons vu en A4 la puissance de CUDA pour le traitement de données importantes, ce qui est notre cas avec le nombre de pixels de l'image et le nombre d'itérations qui augmentent en fonction du nombre de clusters recherchés. J'ai ainsi décidé - pour voir à partir de combien de niveaux de couleurs peut-on apercevoir une image nette - d'observer le traitement Kmeans jusqu'à 255 clusters.\n",
"\n",
"On observe ainsi qu'au dessus de 40 clusters on arrive à bien distinguer les fruits et légumes présents sur l'image."
2022-11-28 11:40:47 +01:00
]
},
{
"cell_type": "code",
2022-12-05 18:14:46 +01:00
"execution_count": null,
2022-11-28 11:40:47 +01:00
"metadata": {},
2023-01-12 16:00:39 +01:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAaYAAAEWCAYAAAAtuzN2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAABHQklEQVR4nO2dd5hU5fXHP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B4MBQXlHxs/fVFraZW3vgqRlgBeuzoZFzVhqgDbvbnS5j00DCNuHnsMbimjiPP8+TBmTMlt//0vfPmlLn/3HYjAYYclvYvAxWiRTJ/30arReO2IZFw0o1MSVTU7d2q7Y0dq+2EYRopYtQqqVYNmzeI/19q1sGED7Nmj5/R54AEYOhTWr4caNXTb2WdrW1wMEydC165Qv378fYiGSD5wKnBdaOvfgWGIXI1WFR6QjEubxVQB/LElEybDyFEuvxyuvTYx51q7VkVpy5aS2wsL1S0zderezxk5Ui2mI49MTB+i4dxWnGuCcxtD2wpxrg/OdcG5U3BuXTIubcJUAUyYDCPHWboUVq5MzLnWrtV2w4aS2/31ceOCbXXravv738OaNXDEEYnpQ5piwlQBfGHyXXqGYeQYGzbA5s2JOZcvTOvX730NCITJOf3xycuD77/XbVkuTBk5xiQi/YB+tWrVqtLrmsVkGDnOhg3BuE887NoFmzYF5yx9DVBhck7/CRcVwd/+Bp07w+efQ48e8fchjclIi8k594Fz7tq8vLwquBbceitccEFswlRYqG5jwzAyhMmT4Z//LP+4HTv0UXpMqDIUFgbLZQlT8+Y
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
2022-11-28 11:40:47 +01:00
"source": [
2023-01-05 20:28:08 +01:00
"cpu = []\n",
"cuda = []\n",
"i = 0\n",
"with open(\"timing.txt\",'r') as data_file:\n",
" for line in data_file:\n",
" data = line.split()\n",
" if(len(data) < 4):\n",
" i=i+1\n",
" if(len(data) > 3):\n",
" if(i == 1):\n",
" cpu.append(float(data[2]))\n",
" if(i == 2):\n",
" cuda.append(float(data[2]))\n",
"\n",
"fig, ax1 = plt.subplots()\n",
"ax1.set_xlabel(\"K\")\n",
"ax1.set_ylabel(\"temps (s)\")\n",
"ax1.set_yscale('log')\n",
"ax1.plot(cpu,'b')\n",
"ax1.tick_params(axis ='y', labelcolor = 'blue') \n",
"plt.legend(['CPU'],loc='lower left')\n",
"\n",
"ax2 = ax1.twinx()\n",
"ax2.set_ylabel(\"temps (s)\")\n",
"ax2.plot(cuda,'r')\n",
"ax2.tick_params(axis ='y', labelcolor = 'red') \n",
"\n",
"plt.legend(['CUDA'],loc='lower right')\n",
"plt.title(\"Temps d'exécution Kmeans image\")\n",
"plt.show()\n"
2022-11-28 11:40:47 +01:00
]
}
],
"metadata": {
"kernelspec": {
2022-12-08 22:12:07 +01:00
"display_name": "Python 3.9.4 64-bit",
2022-11-28 11:40:47 +01:00
"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",
2023-01-05 20:28:08 +01:00
"version": "3.9.4"
2022-11-28 11:40:47 +01:00
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
2022-12-08 22:12:07 +01:00
"hash": "2ef431f6525756fa8a44688585fa332ef3b2e5fcfe8fe75df35bbf7028a8b511"
2022-11-28 11:40:47 +01:00
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}