M2_SETI/D3/TP/TP_SETI_Kmeans/TP1.ipynb

393 lines
203 KiB
Text
Raw 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",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 174,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 196,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
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",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 175,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 197,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"# mean = [1,2,3,4]\n",
"# sd = [0.25, 0.25, 0.1, 0.2]\n",
"clusters = 5\n",
"dim = 2\n",
2022-12-05 09:01:01 +01:00
"nb = 100\n",
2022-11-28 11:40:47 +01:00
"K= clusters\n",
2022-11-29 12:15:07 +01:00
"mean = np.random.randint(5, size=clusters)\n",
"mean = mean.T * np.random.random(size=clusters)\n",
2022-12-05 09:01:01 +01:00
"sd = np.random.random(size=clusters)*0.5\n",
2022-11-28 11:40:47 +01:00
"path_image = \"fruits.jpg\"\n",
"# print(mean)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fonctions à utiliser pour le clustering"
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 176,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 198,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
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",
" 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",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 177,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 199,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def distance(points,Pc): \n",
" return scipy.spatial.distance.cdist(points[:,:], Pc[:,:])"
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 178,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 200,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def kmeans(points = [0,0], K = 1):\n",
" # 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",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 179,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 201,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
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",
" 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",
" plt.plot(Pc[:,0],Pc[:,1],'r+')\n",
" plt.grid(True)\n",
" plt.axis([min(mean)-1,max(mean)+1,min(mean)-1,max(mean)+1])"
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 180,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 202,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def img_2_mat(my_img):\n",
" mat = my_img.reshape(my_img.shape[0]*my_img.shape[1],my_img.shape[2])\n",
" return mat"
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 181,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 203,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def mat_2_img(mat,my_img):\n",
" img_seg = mat.reshape(my_img.shape[0], my_img.shape[1], my_img.shape[2])\n",
" return img_seg"
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 182,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 204,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"def kmeans_image(path_image, K):\n",
" 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"
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 183,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 205,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
2022-11-29 12:15:07 +01:00
"points, mean = gen_points(mean,sd,nb,dim,clusters)\n",
2022-11-28 11:40:47 +01:00
"# print(points.shape)\n",
"# print(points.mean(axis=0))\n",
"# print(points)"
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 184,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 206,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"dist = distance(points,points)\n",
"# print(dist)"
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 185,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 207,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [],
"source": [
"Pc, index, clusters = kmeans(points,K=K)\n",
"# print(index)\n",
"# print(clusters)\n"
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 186,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 208,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
"outputs": [
{
"data": {
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD4CAYAAADvsV2wAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAw+UlEQVR4nO2df2wd13Xnv4e0RJlRTEe0yChO+BghthNvhaaOkShtUVuiFnBUyE6zXqyylNZ2I7CSa8DeRsC6JVBJablJF0KtBI7i5SppHPEhijYJtpbrrFHqh7PFrtzIgWPaMeTYqqjYdcVYLujQsiiaPPvHzEjz3ps7P+/M3Jk5H+DhvTdz5/6YH2fOPffcc4mZIQiCIJSftrwrIAiCIGSDCHxBEISKIAJfEAShIojAFwRBqAgi8AVBECrCFXlXQMXVV1/NH/nIR/KuRmLefvttvOc978m7GokpQzvK0AagHO0I24Y333kTr731Gi7OX8Ti9sW49qprsezKZRnUMBwmXotnnnnmDWZe7rXPWIHf29uLEydO5F2NxBw7dgy33npr3tVITBnaUYY2AOVoR5g21CfqGDo0hItzFwEAF3ERZxedxV9s+AsMrhrMoJbBmHgtiGhStU9MOoIgGMnw4WGcnzvfsO383HkMHx7OqUbFRwS+IAhGcmb6TKTtQjAi8AVBMJK+rr5I24VgROALgmAkIwMj6FzU2bCtc1EnRgZGtJdVn6ijf08/2na1oX9PP+oTde1lmIAIfEEQjGRw1SBGN4yi1lUDgVDrqmF0w6j2AVtncHhyehIMxuT0JIYODZVS6BvrpSMIVWOiPoH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zvv/9l3Dmmf22rr1tWyUef/xM9PeXjB4rKxvCN7+5HbNmGU9JvPhiFVat+ryte6WyGq8sA1dffQH6+yciNWBQpQYS6uPp1ltfTRu73veZ6fi2bavEvfeePfKZ+P3tvkaWgR07yvDhhxNx3HEfY+bMfl/MSLjh0KFDuOyyy7B//36Ew2HTc10PRI4cOYJdu3Zh//79aG9vx+OPP44tW7Zg5syZaefqzYhUV1ejt7cXZWVlbg6THDA8PIxNmzZh3rx5KC4u9no4ZILvlbfWrZPwta9Zzwz8538exeLFivD7tWGDOlOQOtOitaRft874t/stWyTMm5fdJLk2XjPaGAHr2QxAHXtVFfCXv6TPZmgzP7GYhEcesX6i641PloFTThmHnh4I39/qNYCCSETBX/4i522gYWVgYADl5eVCgYjrSzPjx4/HKaecAgD43Oc+h1dffRWtra149NFH086dMGECJkyYkHa8uLiY/1gGCN+v4OB75Y3qatHzxiHx7TF7v2QZuOkmoxwPCZIE3HzzOCxapJ8XMGeOeRfdTMarp6kJGDcuvQus/gNdHXt3N/DKK8VpxbyKi4G5c9XrPfJIZuP7/e8xElDo07u/1WsACd3dEl55pSijAmT5wM6/KzmvIxKPx5NmPYiICo0bOymyLZxlllQpws54E3dvLF0q9hqzRNdsfp6Z1PnwQ22QfOJqIHLbbbfhxRdfRFdXF7Zv347bbrsNHR0duPzyy928LRGRr7mxk8KJh6NRrQkRdser7d5YtEjsfLM6G9n8PDOp8+GX2iD5wtVA5IMPPsDXvvY1TJ8+Heeffz5effVVPPfcc5g3b56btyUi8j2nC0w59XBMrTXR3DzWyVdPWZm63dZqvEbbXJ2
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"text/plain": [
2022-12-05 09:01:01 +01:00
"<Figure size 640x480 with 1 Axes>"
2022-11-28 11:40:47 +01:00
]
},
2022-12-05 09:01:01 +01:00
"metadata": {},
2022-11-28 11:40:47 +01:00
"output_type": "display_data"
}
],
"source": [
"visualisation(clusters, index, Pc, K=K)\n",
"# print(Pc)\n",
"# print(mean)"
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": 187,
2022-11-28 11:40:47 +01:00
"metadata": {},
2022-11-29 12:15:07 +01:00
"outputs": [
{
2022-12-05 18:14:46 +01:00
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_348\\152532697.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mPc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mimg_seg\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mkmeans_image\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath_image\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mpath_image\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mK\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m250\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_348\\1699160287.py\u001b[0m in \u001b[0;36mkmeans_image\u001b[1;34m(path_image, K)\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mMat\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mimg_2_mat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmy_img\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mPc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mclusters\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mkmeans\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mMat\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mK\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mMat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_348\\144608849.py\u001b[0m in \u001b[0;36mkmeans\u001b[1;34m(points, K)\u001b[0m\n\u001b[0;32m 28\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mn\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mN\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 29\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mK\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 30\u001b[1;33m \u001b[0mindex\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mclust\u001b[0m\u001b[1;33m==\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 31\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mpoints\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mk\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 32\u001b[0m \u001b[1;31m# print(points)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m<__array_function__ internals>\u001b[0m in \u001b[0;36mappend\u001b[1;34m(*args, **kwargs)\u001b[0m\n",
"\u001b[1;32mc:\\Users\\Sasa\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\numpy\\lib\\function_base.py\u001b[0m in \u001b[0;36mappend\u001b[1;34m(arr, values, axis)\u001b[0m\n\u001b[0;32m 4815\u001b[0m \u001b[0mvalues\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mravel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4816\u001b[0m \u001b[0maxis\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0marr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4817\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mconcatenate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalues\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4818\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4819\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32m<__array_function__ internals>\u001b[0m in \u001b[0;36mconcatenate\u001b[1;34m(*args, **kwargs)\u001b[0m\n",
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
2022-11-29 12:15:07 +01:00
]
},
{
"data": {
2022-12-05 18:14:46 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAUgAAAD8CAYAAAAVOD3kAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOz9V5Bt2XnfCf6+t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fcJVwR5hW8BSowgVrhYnPHym5/jZP4mWSZEHyiSIV1jeeGpH+HW9Q9hxeG14/DwDrvbN8jMCIOAWJq2Imokz3O6riNNellNwLCoK8bFAINgtI+eREFNIK7TeQk1h3c/zRuv/EtG+jZ7WwOGPmNgMkwoIZRoLNAYQEJPtCpYDFEj1lrEWKICKhjrevFkV0GzQusS6Tq09cSmxviG2LRE10AItHVF4hICU2zniPUSa8COk15gbiwaIlHAJEmfgncdIEiITAw0BJ7fGfCl2/f5+ld/g+nHdynyDcCtrSQNkcDVgM37hyuCvMK3gEiIEWctD47f4jMv/hpkR2zt7jAsNik7i3aGUh7j4UXO7tZ1Ds7e4Pc//xv8lZ/5O1zb+hC+jRjTUIWS09NT9vb2mc9ndF3HjWs3mLeXnJ2fYfduIsEwLqYQzXrSpG+TGIR6dsj5vd8hb7/I7mDKoMspkgL8ClVP0BGWihgDwNrOLEUkocUjapHYN5UMEdoG2gq6EuoVVGXfc4kJ0oE0Dqk7AgF8h9YeO8po2kjhlLZeoqI4mwAG0hFiBcT1pE6HjYI6g48ducnZMpHEJcy2U95+5VNc3/8QLzzzcazZQNaNMJGr9Pr9xBVBXuFPjRADd++/STaynM7eZl49oG7
2022-11-29 12:15:07 +01:00
"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": [
2022-12-05 18:14:46 +01:00
"Pc, index, img_seg = kmeans_image(path_image=path_image, K=250)"
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 209,
2022-11-28 11:40:47 +01:00
"metadata": {},
2022-12-05 09:01:01 +01:00
"outputs": [],
2022-11-28 11:40:47 +01:00
"source": [
2022-12-05 09:01:01 +01:00
"# for k in range(1,50):\n",
"# Pc, index, img_seg = kmeans_image(path_image=path_image, K=k)"
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
]
},
{
"cell_type": "code",
2022-12-08 02:06:12 +01:00
<<<<<<< HEAD
2022-12-05 18:14:46 +01:00
"execution_count": null,
2022-12-08 02:06:12 +01:00
=======
2022-12-05 09:01:01 +01:00
"execution_count": 210,
2022-12-08 02:06:12 +01:00
>>>>>>> a3a978f4f7cba37939976062fd710d891e0bcc2b
2022-11-28 11:40:47 +01:00
"metadata": {},
2022-12-05 09:01:01 +01:00
"outputs": [],
2022-11-28 11:40:47 +01:00
"source": [
2022-12-05 09:01:01 +01:00
"# print(index.shape)\n",
"# print(Pc)\n",
"# print(img_seg)"
2022-11-28 11:40:47 +01:00
]
}
],
"metadata": {
"kernelspec": {
2022-12-05 09:01:01 +01:00
"display_name": "Python 3.8.10 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",
2022-12-05 09:01:01 +01:00
"version": "3.8.10"
2022-11-28 11:40:47 +01:00
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
2022-12-05 09:01:01 +01:00
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
2022-11-28 11:40:47 +01:00
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}