{"id":398552,"date":"2024-06-29T14:08:26","date_gmt":"2024-06-29T14:08:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=398552"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=398552","title":{"rendered":"<span>\u041a\u0430\u043a \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0432\u0451\u0437\u0434 \u043d\u0430 \u0444\u043e\u0442\u043e?<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f5d\/c3e\/152\/f5dc3e152f538159be97768fc9470675.png\" width=\"588\" height=\"429\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f5d\/c3e\/152\/f5dc3e152f538159be97768fc9470675.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0432 \u043e\u043b\u0438\u043c\u043f\u0438\u0430\u0434\u0435 \u043f\u043e \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0443 \u043d\u0430 Python \u0438 \u0442\u0430\u043c \u0431\u044b\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043d\u043e \u0441\u0430\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u044d\u0442\u043e \u043f\u0440\u043e \u0437\u0432\u0435\u0437\u0434\u044b \u043d\u0430 \u043d\u0435\u0431\u0435: <em>&#171;\u0414\u0430\u043d\u043e \u0444\u043e\u0442\u043e \u0437\u0432\u0435\u0437\u0434\u043d\u043e\u0433\u043e \u043d\u0435\u0431\u0430 \u0441 \u0437\u0435\u043c\u043b\u0438. \u0417\u0430\u0434\u0430\u0447\u0430: \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0432\u0451\u0437\u0434 \u043d\u0430 \u043d\u0435\u0431\u0435&#187;<\/em><\/p>\n<p> \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0444\u043e\u0442\u043a\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e \u0437\u0432\u0435\u0437\u0434\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/6ab\/a61\/3fa\/6aba613fa90dd078a99e8405c6d0dc34.jpg\" alt=\"\u0424\u043e\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e \u0437\u0432\u0451\u0437\u0434\u0430\u043c\u0438\" title=\"\u0424\u043e\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e \u0437\u0432\u0451\u0437\u0434\u0430\u043c\u0438\" width=\"626\" height=\"313\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6ab\/a61\/3fa\/6aba613fa90dd078a99e8405c6d0dc34.jpg\" data-blurred=\"true\"\/><figcaption>\u0424\u043e\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e \u0437\u0432\u0451\u0437\u0434\u0430\u043c\u0438<\/figcaption><\/figure>\n<p>\u041b\u0430\u0434\u043d\u043e, \u0442\u0443\u0442 \u0432\u0441\u0435 \u043b\u0435\u0433\u043a\u043e! \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/p>\n<pre><code class=\"python\">from scipy.spatial import distance from skimage import io from skimage.feature import blob_dog, blob_log, blob_doh from skimage.color import rgb2gray  import matplotlib.pyplot as plt<\/code><\/pre>\n<p>\u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>skimage<\/code> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c, <code>scipy<\/code> &#8212; \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438 <code>matplotlib.pyplot<\/code>  \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430.<\/p>\n<pre><code class=\"python\">image = io.imread(input(\"\u041f\u0443\u0442\u044c \u0434\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f: \")) image_gray = rgb2gray(image)<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u043e\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u0447\u0435\u0440\u043d\u043e \u0431\u0435\u043b\u043e\u0435 \u0434\u043b\u044f \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0435\u0433\u043e \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043c\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0438\u043a\u0441\u0435\u043b\u044c \u0432 RGB \u0438 GrayScale:<\/p>\n<pre><code class=\"python\">print(image[0, 0]) print(image_gray[0, 0])<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<pre><code class=\"python\">[24 16 14] #RGB 0.06884627450980392 #GrayScale<\/code><\/pre>\n<p><strong>\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 float \u043f\u0440\u043e\u0449\u0435 \u0447\u0435\u043c \u0441 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u043c<\/strong><\/p>\n<p> \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0438\u0441\u043a\u0430\u0442\u044c \u0437\u0432\u0435\u0437\u0434\u044b. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 <code>skimage<\/code>  \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u043f\u0435\u043b\u044c(blobs). \u0418\u0445 \u0442\u0440\u0438 \u0432\u0438\u0434\u0430:<\/p>\n<ul>\n<li>\n<p> Laplacian of Gaussian (LoG)<\/p>\n<\/li>\n<li>\n<p>Difference of Gaussian (DoG)<\/p>\n<\/li>\n<li>\n<p>Determinant of Hessian (DoH)<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/scikit-image.org\/docs\/stable\/auto_examples\/features_detection\/plot_blob.html\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0443\u0442<\/u><\/a><u>.<\/u><\/p>\n<p>\u041d\u0430 \u043b\u0438\u0447\u043d\u043e\u043c \u043e\u043f\u044b\u0442\u0435 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044f \u043f\u0440\u0438\u0448\u0435\u043b \u043a \u0432\u044b\u0432\u043e\u0434\u0443, \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c  \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<pre><code class=\"python\">blobs_log = blob_log(image_gray, max_sigma=20, num_sigma=10, threshold=.05)<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u044f \u043e\u0442\u043c\u0435\u0447\u0430\u044e \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0438 \u0441\u0447\u0438\u0442\u0430\u044e \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e<\/p>\n<pre><code class=\"python\">fig = plt.figure() ax = fig.add_subplot(1, 1, 1)  ax.set_title('Laplacian of Gaussian') ax.imshow(image) c_stars = 0 for blob in blobs_log:     y, x, r = blob     if r > 2:         continue     ax.add_patch(plt.Circle((x, y), r, color='purple', linewidth=2, fill=False))     c_stars += 1 print(\"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0432\u0451\u0437\u0434: \" + str(c_stars)) ax.set_axis_off() plt.tight_layout() plt.show()<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044f, \u044f \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"python\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0432\u0451\u0437\u0434: 353<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/330\/65e\/315\/33065e315be44b1f7e1f63a693915f4d.png\" alt=\"\u0412\u044b\u0432\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b\" title=\"\u0412\u044b\u0432\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b\" width=\"619\" height=\"349\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/330\/65e\/315\/33065e315be44b1f7e1f63a693915f4d.png\"\/><figcaption>\u0412\u044b\u0432\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/figcaption><\/figure>\n<p>\u041d\u043e \u0432\u0435\u0440\u043d\u043e \u043b\u0438 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0435\u0441\u043b\u0438 \u0432\u0432\u0435\u0441\u0442\u0438 \u0435\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/a22\/4d6\/c6f\/a224d6c6f1d8bc1152e55feb38fd3354.jpg\" alt=\"\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \" title=\"\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \" width=\"1920\" height=\"1280\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a22\/4d6\/c6f\/a224d6c6f1d8bc1152e55feb38fd3354.jpg\" data-blurred=\"true\"\/><figcaption>\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0438 <\/figcaption><\/figure>\n<p>\u0418 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043c\u043d\u043e\u0433\u043e \u043b\u043e\u0436\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c89\/75c\/87b\/c8975c87be07b3fd8297a30b1b5c6c7c.png\" alt=\"\" title=\"\" width=\"631\" height=\"448\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c89\/75c\/87b\/c8975c87be07b3fd8297a30b1b5c6c7c.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/h2>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0442\u043e\u0447\u0435\u043a. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0439 \u0444\u0438\u0448\u043a\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>skimage<\/code>  \u044d\u0442\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 <a href=\"https:\/\/stackoverflow.com\/questions\/26237580\/skimage-slic-getting-neighbouring-segments\/26243226\" rel=\"noopener noreferrer nofollow\"><u>\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/u><\/a>, \u0433\u0434\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u044b \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. <\/p>\n<p>\u0412\u0437\u044f\u0432 \u043e\u0442 \u0442\u0443\u0434\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430, \u043c\u044b \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u043c \u043d\u044b\u043d\u0435\u0448\u043d\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c.<\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438:<\/p>\n<pre><code>from skimage.segmentation import slic, mark_boundaries import numpy as np from sklearn.cluster import KMeans<\/code><\/pre>\n<p>\u0421\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>slic<\/code><\/p>\n<pre><code class=\"python\">segments = slic(img, start_label=0, n_segments=200, compactness=20) segments_ids = np.unique(segments) print(segments_ids)  # centers centers = np.array([np.mean(np.nonzero(segments == i), axis=1) for i in segments_ids]) print(centers) vs_right = np.vstack([segments[:, :-1].ravel(), segments[:, 1:].ravel()]) vs_below = np.vstack([segments[:-1, :].ravel(), segments[1:, :].ravel()]) bneighbors = np.unique(np.hstack([vs_right, vs_below]), axis=1)   fig = plt.figure(figsize=(10, 10)) ax = fig.add_subplot(111) plt.imshow(mark_boundaries(img, segments)) plt.scatter(centers[:, 1], centers[:, 0], c='y')  for i in range(bneighbors.shape[1]):     y0, x0 = centers[bneighbors[0, i]]     y1, x1 = centers[bneighbors[1, i]]      l = Line2D([x0, x1], [y0, y1], alpha=0.5)     ax.add_line(l) <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6d3\/bc7\/b17\/6d3bc7b17b4c66a0fc4d5e747ee0f4e8.png\" alt=\"\u0421\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\" title=\"\u0421\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\" width=\"474\" height=\"329\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6d3\/bc7\/b17\/6d3bc7b17b4c66a0fc4d5e747ee0f4e8.png\"\/><figcaption>\u0421\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/figcaption><\/figure>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0443 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0438\u043a\u0441\u0435\u043b\u044c.<\/p>\n<pre><code class=\"python\">dict_seg = {} for i in range(img.shape[0]):     for j in range(img.shape[1]):         seg = segments[i, j]         if seg not in dict_seg.keys():             dict_seg[seg] = [img[i, j]]             continue         dict_seg[seg].append(img[i, j])<\/code><\/pre>\n<p>\u0412\u044b\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0446\u0432\u0435\u0442 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430<\/p>\n<pre><code class=\"python\">def middle(a, b):     color = []     for i, j in zip(a, b):         color.append((i + j) \/\/ 2)     return color     for k, v in dict_seg.items():     # \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044c \u0434\u043b\u044f \u0432\u044b\u0431\u0440\u043e\u0441\u0430 \u043f\u0435\u0440\u0435\u0441\u0432\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u0432 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0435      p = int(0.9 * len(v))     v = sorted(list(v), key=lambda x: my_distance(x, white))     s = [0, 0, 0]     for c in v:         s[0] += c[0]         s[1] += c[1]         s[2] += c[2]     s[0] \/\/= len(v[:p])     s[1] \/\/= len(v[:p])     s[2] \/\/= len(v[:p])     dict_seg[k] = s<\/code><\/pre>\n<p>\u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u043e \u0441\u0440\u0435\u0434\u043d\u0438\u043c\u0438 \u0446\u0432\u0435\u0442\u0430\u043c\u0438 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0435<\/p>\n<pre><code class=\"powershell\">>>> {0: [5, 3, 14], 1: [5, 3, 16], 2: [7, 4, 17] ... 190: [23, 19, 37]}<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c <code>dict_seg<\/code>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>KMeans<\/code> \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>sklearn<\/code><\/p>\n<pre><code class=\"python\">kmeans = KMeans(n_clusters=3, algorithm=\"elkan\") kmeans.fit(list(dict_seg.values())) labels, counts = np.unique(kmeans.labels_, return_counts=True)<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0432\u0438\u0434\u0430 <code>{segment: claster_num(\u0438\u0445 \u0432\u0441\u0435\u0433\u043e 3)}<\/code><\/p>\n<pre><code>dic_seg_claster = {} for key, value in dict_seg.items():     dic_seg_claster[key] = kmeans.predict([value])[0] max_l = max(dic_seg_claster.values(), key=lambda x: list(dic_seg_claster.values()).count(x))<\/code><\/pre>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u0442 \u043d\u0430\u0448 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043a\u043e\u0434, \u043d\u043e \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"python\">blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.05) fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ... for blob in blobs_log:     y, x, r = blob     # \u043d\u043e\u0432\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442     if dic_seg_claster[segments[int(y), int(x)]] == max_l:         c = plt.Circle((x, y), r, color='purple', linewidth=2, fill=False)         count += 1         ax.add_patch(c) ...<\/code><\/pre>\n<p>\u0418 \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u043b\u0443\u0447\u0448\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/32e\/49a\/b82\/32e49ab828f22d34e78969132f09a565.png\" alt=\"1418 \u0437\u0432\u0435\u0437\u0434\" title=\"1418 \u0437\u0432\u0435\u0437\u0434\" width=\"620\" height=\"451\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/32e\/49a\/b82\/32e49ab828f22d34e78969132f09a565.png\"\/><figcaption>1418 \u0437\u0432\u0435\u0437\u0434<\/figcaption><\/figure>\n<p>\u0412\u044b\u0441\u0447\u0438\u0442\u0430\u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u043f\u0440\u0438\u0448\u0435\u043b \u043a \u0432\u044b\u0432\u043e\u0434\u0443, \u0447\u0442\u043e \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043b\u0438\u0448\u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445 \u043a\u043e\u043c\u043f\u0435\u043d\u0441\u0438\u0440\u0443\u044e\u0442 \u043d\u0435\u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u0432\u0435\u0437\u0434\u044b.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043b\u0433\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c, \u043f\u043e\u0434\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u041d\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0441\u044c.<\/p>\n<p>\u0412\u0441\u0435 \u0432\u0430\u0448\u0438 \u043f\u043e\u0436\u0435\u043b\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043d\u0435\u0433\u043e\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0430 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u043c\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0445, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043c\u043e\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f) <\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/github.com\/LivelyPuer\/Astrologer\/tree\/master\" rel=\"noopener noreferrer nofollow\">gitHub<\/a><\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/589003\/\"> https:\/\/habr.com\/ru\/articles\/589003\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u0432 \u043e\u043b\u0438\u043c\u043f\u0438\u0430\u0434\u0435 \u043f\u043e \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0443 \u043d\u0430 Python \u0438 \u0442\u0430\u043c \u0431\u044b\u043b\u043e \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043d\u043e \u0441\u0430\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u044d\u0442\u043e \u043f\u0440\u043e \u0437\u0432\u0435\u0437\u0434\u044b \u043d\u0430 \u043d\u0435\u0431\u0435: <em>&#171;\u0414\u0430\u043d\u043e \u0444\u043e\u0442\u043e \u0437\u0432\u0435\u0437\u0434\u043d\u043e\u0433\u043e \u043d\u0435\u0431\u0430 \u0441 \u0437\u0435\u043c\u043b\u0438. \u0417\u0430\u0434\u0430\u0447\u0430: \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0432\u0451\u0437\u0434 \u043d\u0430 \u043d\u0435\u0431\u0435&#187;<\/em><\/p>\n<p> \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0444\u043e\u0442\u043a\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e \u0437\u0432\u0435\u0437\u0434\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<figure class=\"full-width\"><figcaption>\u0424\u043e\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e \u0437\u0432\u0451\u0437\u0434\u0430\u043c\u0438<\/figcaption><\/figure>\n<p>\u041b\u0430\u0434\u043d\u043e, \u0442\u0443\u0442 \u0432\u0441\u0435 \u043b\u0435\u0433\u043a\u043e! \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/p>\n<pre><code class=\"python\">from scipy.spatial import distance from skimage import io from skimage.feature import blob_dog, blob_log, blob_doh from skimage.color import rgb2gray  import matplotlib.pyplot as plt<\/code><\/pre>\n<p>\u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>skimage<\/code> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c, <code>scipy<\/code> &#8212; \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438 <code>matplotlib.pyplot<\/code>  \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430.<\/p>\n<pre><code class=\"python\">image = io.imread(input(\"\u041f\u0443\u0442\u044c \u0434\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f: \")) image_gray = rgb2gray(image)<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u043e\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u0447\u0435\u0440\u043d\u043e \u0431\u0435\u043b\u043e\u0435 \u0434\u043b\u044f \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0435\u0433\u043e \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043c\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0438\u043a\u0441\u0435\u043b\u044c \u0432 RGB \u0438 GrayScale:<\/p>\n<pre><code class=\"python\">print(image[0, 0]) print(image_gray[0, 0])<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<pre><code class=\"python\">[24 16 14] #RGB 0.06884627450980392 #GrayScale<\/code><\/pre>\n<p><strong>\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 float \u043f\u0440\u043e\u0449\u0435 \u0447\u0435\u043c \u0441 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u043c<\/strong><\/p>\n<p> \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0438\u0441\u043a\u0430\u0442\u044c \u0437\u0432\u0435\u0437\u0434\u044b. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 <code>skimage<\/code>  \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u043f\u0435\u043b\u044c(blobs). \u0418\u0445 \u0442\u0440\u0438 \u0432\u0438\u0434\u0430:<\/p>\n<ul>\n<li>\n<p> Laplacian of Gaussian (LoG)<\/p>\n<\/li>\n<li>\n<p>Difference of Gaussian (DoG)<\/p>\n<\/li>\n<li>\n<p>Determinant of Hessian (DoH)<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/scikit-image.org\/docs\/stable\/auto_examples\/features_detection\/plot_blob.html\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0443\u0442<\/u><\/a><u>.<\/u><\/p>\n<p>\u041d\u0430 \u043b\u0438\u0447\u043d\u043e\u043c \u043e\u043f\u044b\u0442\u0435 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044f \u043f\u0440\u0438\u0448\u0435\u043b \u043a \u0432\u044b\u0432\u043e\u0434\u0443, \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c  \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<pre><code class=\"python\">blobs_log = blob_log(image_gray, max_sigma=20, num_sigma=10, threshold=.05)<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u044f \u043e\u0442\u043c\u0435\u0447\u0430\u044e \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0438 \u0441\u0447\u0438\u0442\u0430\u044e \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e<\/p>\n<pre><code class=\"python\">fig = plt.figure() ax = fig.add_subplot(1, 1, 1)  ax.set_title('Laplacian of Gaussian') ax.imshow(image) c_stars = 0 for blob in blobs_log:     y, x, r = blob     if r > 2:         continue     ax.add_patch(plt.Circle((x, y), r, color='purple', linewidth=2, fill=False))     c_stars += 1 print(\"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0432\u0451\u0437\u0434: \" + str(c_stars)) ax.set_axis_off() plt.tight_layout() plt.show()<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044f, \u044f \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"python\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0432\u0451\u0437\u0434: 353<\/code><\/pre>\n<figure class=\"full-width\"><figcaption>\u0412\u044b\u0432\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/figcaption><\/figure>\n<p>\u041d\u043e \u0432\u0435\u0440\u043d\u043e \u043b\u0438 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0435\u0441\u043b\u0438 \u0432\u0432\u0435\u0441\u0442\u0438 \u0435\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<figure class=\"full-width\"><figcaption>\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0438 <\/figcaption><\/figure>\n<p>\u0418 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043c\u043d\u043e\u0433\u043e \u043b\u043e\u0436\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/h2>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0442\u043e\u0447\u0435\u043a. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0439 \u0444\u0438\u0448\u043a\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>skimage<\/code>  \u044d\u0442\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 <a href=\"https:\/\/stackoverflow.com\/questions\/26237580\/skimage-slic-getting-neighbouring-segments\/26243226\" rel=\"noopener noreferrer nofollow\"><u>\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/u><\/a>, \u0433\u0434\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u044b \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. <\/p>\n<p>\u0412\u0437\u044f\u0432 \u043e\u0442 \u0442\u0443\u0434\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430, \u043c\u044b \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u043c \u043d\u044b\u043d\u0435\u0448\u043d\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c.<\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438:<\/p>\n<pre><code>from skimage.segmentation import slic, mark_boundaries import numpy as np from sklearn.cluster import KMeans<\/code><\/pre>\n<p>\u0421\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>slic<\/code><\/p>\n<pre><code class=\"python\">segments = slic(img, start_label=0, n_segments=200, compactness=20) segments_ids = np.unique(segments) print(segments_ids)  # centers centers = np.array([np.mean(np.nonzero(segments == i), axis=1) for i in segments_ids]) print(centers) vs_right = np.vstack([segments[:, :-1].ravel(), segments[:, 1:].ravel()]) vs_below = np.vstack([segments[:-1, :].ravel(), segments[1:, :].ravel()]) bneighbors = np.unique(np.hstack([vs_right, vs_below]), axis=1)   fig = plt.figure(figsize=(10, 10)) ax = fig.add_subplot(111) plt.imshow(mark_boundaries(img, segments)) plt.scatter(centers[:, 1], centers[:, 0], c='y')  for i in range(bneighbors.shape[1]):     y0, x0 = centers[bneighbors[0, i]]     y1, x1 = centers[bneighbors[1, i]]      l = Line2D([x0, x1], [y0, y1], alpha=0.5)     ax.add_line(l) <\/code><\/pre>\n<figure class=\"\"><figcaption>\u0421\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/figcaption><\/figure>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0443 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0438\u043a\u0441\u0435\u043b\u044c.<\/p>\n<pre><code class=\"python\">dict_seg = {} for i in range(img.shape[0]):     for j in range(img.shape[1]):         seg = segments[i, j]         if seg not in dict_seg.keys():             dict_seg[seg] = [img[i, j]]             continue         dict_seg[seg].append(img[i, j])<\/code><\/pre>\n<p>\u0412\u044b\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u0446\u0432\u0435\u0442 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430<\/p>\n<pre><code class=\"python\">def middle(a, b):     color = []     for i, j in zip(a, b):         color.append((i + j) \/\/ 2)     return color     for k, v in dict_seg.items():     # \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0446\u0435\u043d\u0442\u0438\u043b\u044c \u0434\u043b\u044f \u0432\u044b\u0431\u0440\u043e\u0441\u0430 \u043f\u0435\u0440\u0435\u0441\u0432\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u0432 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0435      p = int(0.9 * len(v))     v = sorted(list(v), key=lambda x: my_distance(x, white))     s = [0, 0, 0]     for c in v:         s[0] += c[0]         s[1] += c[1]         s[2] += c[2]     s[0] \/\/= len(v[:p])     s[1] \/\/= len(v[:p])     s[2] \/\/= len(v[:p])     dict_seg[k] = s<\/code><\/pre>\n<p>\u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441\u043e \u0441\u0440\u0435\u0434\u043d\u0438\u043c\u0438 \u0446\u0432\u0435\u0442\u0430\u043c\u0438 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0435<\/p>\n<pre><code class=\"powershell\">>>> {0: [5, 3, 14], 1: [5, 3, 16], 2: [7, 4, 17] ... 190: [23, 19, 37]}<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0443\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c <code>dict_seg<\/code>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>KMeans<\/code> \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>sklearn<\/code><\/p>\n<pre><code class=\"python\">kmeans = KMeans(n_clusters=3, algorithm=\"elkan\") kmeans.fit(list(dict_seg.values())) labels, counts = np.unique(kmeans.labels_, return_counts=True)<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0432\u0438\u0434\u0430 <code>{segment: claster_num(\u0438\u0445 \u0432\u0441\u0435\u0433\u043e 3)}<\/code><\/p>\n<pre><code>dic_seg_claster = {} for key, value in dict_seg.items():     dic_seg_claster[key] = kmeans.predict([value])[0] max_l = max(dic_seg_claster.values(), key=lambda x: list(dic_seg_claster.values()).count(x))<\/code><\/pre>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u0442 \u043d\u0430\u0448 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043a\u043e\u0434, \u043d\u043e \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"python\">blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.05) fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ... for blob in blobs_log:     y, x, r = blob     # \u043d\u043e\u0432\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442     if dic_seg_claster[segments[int(y), int(x)]] == max_l:         c = plt.Circle((x, y), r, color='purple', linewidth=2, fill=False)         count += 1         ax.add_patch(c) ...<\/code><\/pre>\n<p>\u0418 \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u043b\u0443\u0447\u0448\u0435.<\/p>\n<figure class=\"full-width\"><figcaption>1418 \u0437\u0432\u0435\u0437\u0434<\/figcaption><\/figure>\n<p>\u0412\u044b\u0441\u0447\u0438\u0442\u0430\u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u043f\u0440\u0438\u0448\u0435\u043b \u043a \u0432\u044b\u0432\u043e\u0434\u0443, \u0447\u0442\u043e \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043b\u0438\u0448\u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445 \u043a\u043e\u043c\u043f\u0435\u043d\u0441\u0438\u0440\u0443\u044e\u0442 \u043d\u0435\u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u0432\u0435\u0437\u0434\u044b.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043b\u0433\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c, \u043f\u043e\u0434\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u041d\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0441\u044c.<\/p>\n<p>\u0412\u0441\u0435 \u0432\u0430\u0448\u0438 \u043f\u043e\u0436\u0435\u043b\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043d\u0435\u0433\u043e\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0430 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u043c\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0445, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043c\u043e\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f) <\/p>\n<p>\u0413\u043e\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/github.com\/LivelyPuer\/Astrologer\/tree\/master\" rel=\"noopener noreferrer nofollow\">gitHub<\/a><\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/589003\/\"> https:\/\/habr.com\/ru\/articles\/589003\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-398552","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/398552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=398552"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/398552\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=398552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=398552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=398552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}