图像中颜色的分类器

问题描述 投票:1回答:2

我有这个形象。

enter image description here

我想对所有像素进行分类。此图像中像素的颜色如下:

  1. 蓝色:水
  2. 红色:屋顶
  3. 白:道
  4. 黄色:浅
  5. 浅绿色:草
  6. 深绿色:树
  7. 黑色:背景

如何对所有像素进行分类。例如,如果2'column和1'row的像素是蓝色,则将(1,2)分类为水类,依此类推。

python image classification
2个回答
2
投票

我可以告诉你如何做到这一点以及你将得到什么结果,并希望你可以适应它 - 如果你愿意的话。我选择的武器是ImageMagick,它安装在大多数Linux发行版上,可以在macOS和Windows上免费使用。


步骤1

首先,我使用“颜色滴管”工具(在Mac上称为“数字颜色计”),然后查看已识别的7种颜色中的每种颜色的区域并获得其RGB坐标,并制作一个简单的“Look-通过在终端中键入以下内容来获取这些值的表:

# First make a LUT of our 7 colours
convert xc:"rgb(59,79,162)"   \
        xc:"rgb(230,30,35)"   \
        xc:"rgb(240,240,240)" \
        xc:"rgb(230,230,97)"  \
        xc:"rgb(103,180,65)"  \
        xc:"rgb(47,140,87)"   \
        xc:black +append LUT.png

那个文件(LUT.png)看起来像这样 - 只有更小 - 我把它放大到下面所以你可以看到它。实际上,它只有7x1像素:

enter image description here


第2步

现在,我将查找表应用于图像,没有抖动,因此图像中的每种颜色都被强制为表中最接近的颜色:

convert image.png +dither -map LUT.png result.png

enter image description here

图像现在真正只有我们选择的7种颜色,而不是原始图像中的8,002种颜色!


第3步

现在,我们浏览图像并实际对其进行分类,将所有蓝色像素替换为1,将所有红色像素替换为2,将所有白色像素替换为3,依此类推:

convert result.png            \
        -fill "gray(1)" -opaque "rgb(59,79,162)"   \
        -fill "gray(2)" -opaque "rgb(230,30,35)"   \
        -fill "gray(3)" -opaque "rgb(240,240,240)" \
        -fill "gray(4)" -opaque "rgb(230,230,97)"  \
        -fill "gray(5)" -opaque "rgb(103,180,65)"  \
        -fill "gray(6)" -opaque "rgb(47,140,87)"   \
        -fill "gray(7)" -opaque black final.png

这给了我们这个非常暗的图像,因为在0-255的范围内所有像素都是7或更低:

enter image description here

因此,我们使用标准化将灰色颜色拉伸到整个范围:

convert final.png -normalize final.png

enter image description here


我猜测下一件事将是确定每种封面类型的百分比。我们先来看看水。如果我们把所有水变成白色像素,而不是水变成黑色像素的东西,我们只需通过查看图像平均值就可以计算水覆盖的百分比:

convert final.png -fill white -opaque "rgb(1,1,1)" -fill black +opaque white -format "%[fx:int(mean*100)]" info:
12

所以有12%的水覆盖率。要获取实际图像,请将上面的计算替换为输出文件名:

convert final.png -fill white -opaque "rgb(1,1,1)" -fill black +opaque white water.png

enter image description here

让我们接下来尝试一下树木......同样的程序,让树上的一切都变白,一切都不是树黑:

convert final.png -fill white -opaque "rgb(6,6,6)" -fill black +opaque white -format "%[fx:int(mean*100)]" info:
26

因此,26%的树木覆盖率。我们来看看它们:

convert final.png -fill white -opaque "rgb(6,6,6)" -fill black +opaque white trees.png

enter image description here


蟒蛇

那么,Python会发生什么?

步骤1意味着您使用7种颜色中的每种颜色分配列表或数组(或任何Python调用它们)。列表中的每个条目都有一个红色,绿色和蓝色组件。

步骤2.您遍历图像中的每个像素(按行和列)获取其红色,绿色和蓝色组件。然后计算从当前像素到每种7种LUT颜色的颜色距离,并获取具有最小结果的颜色距离,即最近的距离。你用它来计算距离

(thispixel.Red-LUT[n].Red)^2 + (thispixel.Green-LUT[n].Green)^2 + (thispixel.Blue-LUT[n].Blue)^2 

其中n将贯穿LUT的7个指数。

步骤3.将输出像素设置为LUT中最接近颜色的索引。


2
投票

马克有一个很好的答案。从他的6色图像开始,这是一种略有不同的方法。使用Imagemagick的连接组件标记来编码具有id号的每个隔离区域。 (使用连接组件,您甚至可以将小的隔离区域合并到它们周围的颜色中。但我不会在这里这样做)。

convert V5s4L.png \
-define connected-components:verbose=true \
-connected-components 4 \
result1.png

Objects (id: bounding-box centroid area mean-color):
  1: 121x114+0+0 61.3,58.8 6759 srgb(0,0,0)
  0: 62x37+0+0 27.0,17.4 1670 srgb(59,79,162)
  71: 82x40+4+36 52.0,49.1 893 srgb(47,140,87)
  30: 67x79+47+28 79.4,65.7 800 srgb(47,140,87)
  123: 50x61+68+53 96.4,92.1 567 srgb(47,140,87)
  122: 47x61+60+53 81.8,84.8 519 srgb(47,140,87)
  8: 25x37+96+0 110.6,12.5 222 srgb(47,140,87)
  3: 19x23+49+0 59.2,6.8 213 srgb(103,180,65)
  119: 13x21+41+52 47.0,62.4 206 srgb(230,30,35)
  126: 8x34+113+63 116.9,80.6 181 srgb(47,140,87)
  130: 17x26+33+84 42.1,93.0 178 srgb(47,140,87)
  129: 29x33+64+81 79.3,97.8 170 srgb(0,0,0)
  125: 10x16+0+58 4.7,65.8 150 srgb(230,30,35)
  141: 17x12+99+91 106.7,96.7 143 srgb(230,30,35)
  124: 11x19+20+57 23.8,67.4 141 srgb(230,30,35)
  131: 16x13+23+85 29.2,92.3 119 srgb(230,30,35)
  145: 18x10+16+101 23.3,105.6 108 srgb(230,30,35)
  132: 9x12+0+88 4.4,94.3 70 srgb(230,30,35)
  87: 14x13+107+38 113.2,43.1 61 srgb(240,240,240)
  6: 6x17+68+0 70.0,6.3 48 srgb(103,180,65)
  35: 22x4+60+31 70.5,33.2 44 srgb(230,230,97)
  28: 5x11+116+19 117.8,23.6 40 srgb(47,140,87)
  118: 3x14+13+52 14.0,58.5 38 srgb(47,140,87)
  48: 16x5+29+33 37.7,35.8 36 srgb(230,230,97)
  128: 4x10+117+76 118.9,80.6 28 srgb(0,0,0)
  144: 7x6+0+100 2.5,102.4 28 srgb(47,140,87)
  149: 6x5+47+109 49.7,111.5 24 srgb(47,140,87)
  156: 11x3+89+111 93.7,112.4 24 srgb(230,30,35)
  64: 17x1+60+35 68.0,35.0 17 srgb(103,180,65)
  13: 1x15+65+6 65.0,13.0 15 srgb(47,140,87)
  44: 15x1+62+32 69.0,32.0 15 srgb(103,180,65)
  38: 6x5+34+32 37.3,34.1 15 srgb(0,0,0)
  16: 2x12+67+7 67.1,12.8 13 srgb(47,140,87)
  154: 4x4+117+110 119.0,112.0 10 srgb(47,140,87)
  66: 4x3+19+36 20.7,36.8 9 srgb(230,230,97)
  146: 3x4+0+108 0.8,109.9 9 srgb(230,30,35)
  152: 4x4+83+110 84.9,111.9 9 srgb(230,230,97)
  134: 5x4+98+88 100.2,89.7 9 srgb(230,230,97)
  4: 2x7+67+0 67.9,3.1 8 srgb(47,140,87)
  110: 4x2+0+48 1.7,48.6 7 srgb(47,140,87)
  29: 3x3+62+21 63.2,22.3 6 srgb(47,140,87)
  33: 2x4+0+30 0.6,31.6 5 srgb(47,140,87)
  7: 1x5+74+0 74.0,2.0 5 srgb(47,140,87)
  52: 4x1+17+34 18.5,34.0 4 srgb(0,0,0)
  82: 4x1+33+38 34.5,38.0 4 srgb(103,180,65)
  83: 4x1+37+38 38.5,38.0 4 srgb(47,140,87)
  34: 4x1+77+31 78.5,31.0 4 srgb(103,180,65)
  2: 2x3+48+0 48.2,1.2 4 srgb(47,140,87)
  127: 4x1+0+66 1.5,66.0 4 srgb(0,0,0)
  55: 3x2+29+34 30.2,34.2 4 srgb(103,180,65)
  5: 1x4+69+0 69.0,1.5 4 srgb(0,0,0)
  21: 1x3+55+11 55.0,12.0 3 srgb(47,140,87)
  10: 1x3+51+4 51.0,5.0 3 srgb(47,140,87)
  22: 3x1+56+14 57.0,14.0 3 srgb(47,140,87)
  56: 2x2+44+34 44.7,34.3 3 srgb(47,140,87)
  43: 2x1+60+32 60.5,32.0 2 srgb(47,140,87)
  147: 1x2+87+108 87.0,108.5 2 srgb(103,180,65)
  97: 2x1+107+42 107.5,42.0 2 srgb(47,140,87)
  133: 2x1+100+88 100.5,88.0 2 srgb(103,180,65)
  143: 2x1+98+92 98.5,92.0 2 srgb(103,180,65)
  100: 2x1+116+42 116.5,42.0 2 srgb(103,180,65)
  32: 1x2+0+30 0.0,30.5 2 srgb(103,180,65)
  135: 1x2+103+88 103.0,88.5 2 srgb(103,180,65)
  148: 1x2+88+108 88.0,108.5 2 srgb(47,140,87)
  121: 1x2+120+52 120.0,52.5 2 srgb(240,240,240)
  120: 1x2+119+52 119.0,52.5 2 srgb(47,140,87)
  59: 1x2+18+35 18.0,35.5 2 srgb(47,140,87)
  89: 2x1+20+39 20.5,39.0 2 srgb(103,180,65)
  105: 1x1+107+45 107.0,45.0 1 srgb(47,140,87)
  106: 1x1+108+46 108.0,46.0 1 srgb(59,79,162)
  107: 1x1+114+46 114.0,46.0 1 srgb(103,180,65)
  108: 1x1+112+47 112.0,47.0 1 srgb(47,140,87)
  109: 1x1+115+47 115.0,47.0 1 srgb(103,180,65)
  111: 1x1+113+48 113.0,48.0 1 srgb(103,180,65)
  112: 1x1+116+48 116.0,48.0 1 srgb(103,180,65)
  113: 1x1+114+49 114.0,49.0 1 srgb(103,180,65)
  114: 1x1+117+49 117.0,49.0 1 srgb(47,140,87)
  115: 1x1+115+50 115.0,50.0 1 srgb(103,180,65)
  116: 1x1+116+51 116.0,51.0 1 srgb(47,140,87)
  117: 1x1+120+51 120.0,51.0 1 srgb(103,180,65)
  136: 1x1+99+89 99.0,89.0 1 srgb(103,180,65)
  137: 1x1+98+90 98.0,90.0 1 srgb(103,180,65)
  138: 1x1+102+90 102.0,90.0 1 srgb(103,180,65)
  139: 1x1+97+91 97.0,91.0 1 srgb(103,180,65)
  140: 1x1+100+91 100.0,91.0 1 srgb(103,180,65)
  142: 1x1+97+92 97.0,92.0 1 srgb(47,140,87)
  150: 1x1+86+109 86.0,109.0 1 srgb(47,140,87)
  151: 1x1+85+110 85.0,110.0 1 srgb(103,180,65)
  153: 1x1+87+110 87.0,110.0 1 srgb(47,140,87)
  155: 1x1+84+111 84.0,111.0 1 srgb(103,180,65)
  157: 1x1+83+112 83.0,112.0 1 srgb(103,180,65)
  158: 1x1+82+113 82.0,113.0 1 srgb(47,140,87)
  159: 1x1+86+113 86.0,113.0 1 srgb(103,180,65)
  9: 1x1+50+3 50.0,3.0 1 srgb(47,140,87)
  11: 1x1+66+5 66.0,5.0 1 srgb(47,140,87)
  12: 1x1+73+5 73.0,5.0 1 srgb(47,140,87)
  14: 1x1+72+6 72.0,6.0 1 srgb(47,140,87)
  15: 1x1+52+7 52.0,7.0 1 srgb(47,140,87)
  17: 1x1+71+7 71.0,7.0 1 srgb(47,140,87)
  18: 1x1+70+8 70.0,8.0 1 srgb(47,140,87)
  19: 1x1+53+9 53.0,9.0 1 srgb(47,140,87)
  20: 1x1+54+10 54.0,10.0 1 srgb(47,140,87)
  23: 1x1+59+15 59.0,15.0 1 srgb(47,140,87)
  24: 1x1+60+16 60.0,16.0 1 srgb(47,140,87)
  25: 1x1+69+16 69.0,16.0 1 srgb(47,140,87)
  26: 1x1+61+17 61.0,17.0 1 srgb(47,140,87)
  27: 1x1+62+18 62.0,18.0 1 srgb(47,140,87)
  31: 1x1+0+29 0.0,29.0 1 srgb(47,140,87)
  36: 1x1+82+31 82.0,31.0 1 srgb(59,79,162)
  37: 1x1+28+32 28.0,32.0 1 srgb(47,140,87)
  39: 1x1+40+32 40.0,32.0 1 srgb(47,140,87)
  40: 1x1+41+32 41.0,32.0 1 srgb(103,180,65)
  41: 1x1+42+32 42.0,32.0 1 srgb(47,140,87)
  42: 1x1+43+32 43.0,32.0 1 srgb(0,0,0)
  45: 1x1+82+32 82.0,32.0 1 srgb(103,180,65)
  46: 1x1+28+33 28.0,33.0 1 srgb(0,0,0)
  47: 1x1+29+33 29.0,33.0 1 srgb(47,140,87)
  49: 1x1+41+33 41.0,33.0 1 srgb(240,240,240)
  50: 1x1+43+33 43.0,33.0 1 srgb(47,140,87)
  51: 1x1+81+33 81.0,33.0 1 srgb(103,180,65)
  53: 1x1+21+34 21.0,34.0 1 srgb(47,140,87)
  54: 1x1+28+34 28.0,34.0 1 srgb(47,140,87)
  57: 1x1+77+34 77.0,34.0 1 srgb(103,180,65)
  58: 1x1+79+34 79.0,34.0 1 srgb(47,140,87)
  60: 1x1+19+35 19.0,35.0 1 srgb(59,79,162)
  61: 1x1+20+35 20.0,35.0 1 srgb(47,140,87)
  62: 1x1+28+35 28.0,35.0 1 srgb(103,180,65)
  63: 1x1+39+35 39.0,35.0 1 srgb(103,180,65)
  65: 1x1+16+36 16.0,36.0 1 srgb(47,140,87)
  67: 1x1+28+36 28.0,36.0 1 srgb(47,140,87)
  68: 1x1+33+36 33.0,36.0 1 srgb(103,180,65)
  69: 1x1+38+36 38.0,36.0 1 srgb(103,180,65)
  70: 1x1+45+36 45.0,36.0 1 srgb(103,180,65)
  72: 1x1+19+37 19.0,37.0 1 srgb(47,140,87)
  73: 1x1+29+37 29.0,37.0 1 srgb(47,140,87)
  74: 1x1+43+37 43.0,37.0 1 srgb(47,140,87)
  75: 1x1+115+37 115.0,37.0 1 srgb(47,140,87)
  76: 1x1+116+37 116.0,37.0 1 srgb(230,230,97)
  77: 1x1+0+38 0.0,38.0 1 srgb(47,140,87)
  78: 1x1+22+38 22.0,38.0 1 srgb(103,180,65)
  79: 1x1+30+38 30.0,38.0 1 srgb(47,140,87)
  80: 1x1+31+38 31.0,38.0 1 srgb(103,180,65)
  81: 1x1+32+38 32.0,38.0 1 srgb(47,140,87)
  84: 1x1+41+38 41.0,38.0 1 srgb(103,180,65)
  85: 1x1+42+38 42.0,38.0 1 srgb(47,140,87)
  86: 1x1+114+38 114.0,38.0 1 srgb(47,140,87)
  88: 1x1+117+38 117.0,38.0 1 srgb(230,230,97)
  90: 1x1+113+39 113.0,39.0 1 srgb(47,140,87)
  91: 1x1+118+39 118.0,39.0 1 srgb(230,230,97)
  92: 1x1+119+39 119.0,39.0 1 srgb(47,140,87)
  93: 1x1+112+40 112.0,40.0 1 srgb(47,140,87)
  94: 1x1+119+40 119.0,40.0 1 srgb(230,230,97)
  95: 1x1+110+41 110.0,41.0 1 srgb(103,180,65)
  96: 1x1+111+41 111.0,41.0 1 srgb(230,230,97)
  98: 1x1+109+42 109.0,42.0 1 srgb(103,180,65)
  99: 1x1+115+42 115.0,42.0 1 srgb(230,230,97)
  101: 1x1+120+42 120.0,42.0 1 srgb(103,180,65)
  102: 1x1+114+43 114.0,43.0 1 srgb(47,140,87)
  103: 1x1+118+43 118.0,43.0 1 srgb(47,140,87)
  104: 1x1+120+44 120.0,44.0 1 srgb(47,140,87)

enter image description here

在这种情况下,图像将是暗的,因为在可能的65535中只有大约160个。因此为了更好地观看,我们可以将图像拉伸到完整的动态范围。

convert result1.png -auto-level result2.png

enter image description here

或者我们可以保留输出中的原始颜色:

convert V5s4L.png \
-define connected-components:verbose=true \
-define connected-components:mean-color=true \
-connected-components 4 \
result3.png

Objects (id: bounding-box centroid area mean-color):
  1: 121x114+0+0 61.3,58.8 6759 srgb(0,0,0)
  0: 62x37+0+0 27.0,17.4 1670 srgb(59,79,162)
  71: 82x40+4+36 52.0,49.1 893 srgb(47,140,87)
  30: 67x79+47+28 79.4,65.7 800 srgb(47,140,87)
  123: 50x61+68+53 96.4,92.1 567 srgb(47,140,87)
  122: 47x61+60+53 81.8,84.8 519 srgb(47,140,87)
  8: 25x37+96+0 110.6,12.5 222 srgb(47,140,87)
  3: 19x23+49+0 59.2,6.8 213 srgb(103,180,65)
  119: 13x21+41+52 47.0,62.4 206 srgb(230,30,35)
  126: 8x34+113+63 116.9,80.6 181 srgb(47,140,87)
  130: 17x26+33+84 42.1,93.0 178 srgb(47,140,87)
  129: 29x33+64+81 79.3,97.8 170 srgb(0,0,0)
  125: 10x16+0+58 4.7,65.8 150 srgb(230,30,35)
  141: 17x12+99+91 106.7,96.7 143 srgb(230,30,35)
  124: 11x19+20+57 23.8,67.4 141 srgb(230,30,35)
  131: 16x13+23+85 29.2,92.3 119 srgb(230,30,35)
  145: 18x10+16+101 23.3,105.6 108 srgb(230,30,35)
  132: 9x12+0+88 4.4,94.3 70 srgb(230,30,35)
  87: 14x13+107+38 113.2,43.1 61 srgb(240,240,240)
  6: 6x17+68+0 70.0,6.3 48 srgb(103,180,65)
  35: 22x4+60+31 70.5,33.2 44 srgb(230,230,97)
  28: 5x11+116+19 117.8,23.6 40 srgb(47,140,87)
  118: 3x14+13+52 14.0,58.5 38 srgb(47,140,87)
  48: 16x5+29+33 37.7,35.8 36 srgb(230,230,97)
  128: 4x10+117+76 118.9,80.6 28 srgb(0,0,0)
  144: 7x6+0+100 2.5,102.4 28 srgb(47,140,87)
  149: 6x5+47+109 49.7,111.5 24 srgb(47,140,87)
  156: 11x3+89+111 93.7,112.4 24 srgb(230,30,35)
  64: 17x1+60+35 68.0,35.0 17 srgb(103,180,65)
  13: 1x15+65+6 65.0,13.0 15 srgb(47,140,87)
  44: 15x1+62+32 69.0,32.0 15 srgb(103,180,65)
  38: 6x5+34+32 37.3,34.1 15 srgb(0,0,0)
  16: 2x12+67+7 67.1,12.8 13 srgb(47,140,87)
  154: 4x4+117+110 119.0,112.0 10 srgb(47,140,87)
  66: 4x3+19+36 20.7,36.8 9 srgb(230,230,97)
  146: 3x4+0+108 0.8,109.9 9 srgb(230,30,35)
  152: 4x4+83+110 84.9,111.9 9 srgb(230,230,97)
  134: 5x4+98+88 100.2,89.7 9 srgb(230,230,97)
  4: 2x7+67+0 67.9,3.1 8 srgb(47,140,87)
  110: 4x2+0+48 1.7,48.6 7 srgb(47,140,87)
  29: 3x3+62+21 63.2,22.3 6 srgb(47,140,87)
  33: 2x4+0+30 0.6,31.6 5 srgb(47,140,87)
  7: 1x5+74+0 74.0,2.0 5 srgb(47,140,87)
  52: 4x1+17+34 18.5,34.0 4 srgb(0,0,0)
  82: 4x1+33+38 34.5,38.0 4 srgb(103,180,65)
  83: 4x1+37+38 38.5,38.0 4 srgb(47,140,87)
  34: 4x1+77+31 78.5,31.0 4 srgb(103,180,65)
  2: 2x3+48+0 48.2,1.2 4 srgb(47,140,87)
  127: 4x1+0+66 1.5,66.0 4 srgb(0,0,0)
  55: 3x2+29+34 30.2,34.2 4 srgb(103,180,65)
  5: 1x4+69+0 69.0,1.5 4 srgb(0,0,0)
  21: 1x3+55+11 55.0,12.0 3 srgb(47,140,87)
  10: 1x3+51+4 51.0,5.0 3 srgb(47,140,87)
  22: 3x1+56+14 57.0,14.0 3 srgb(47,140,87)
  56: 2x2+44+34 44.7,34.3 3 srgb(47,140,87)
  43: 2x1+60+32 60.5,32.0 2 srgb(47,140,87)
  147: 1x2+87+108 87.0,108.5 2 srgb(103,180,65)
  97: 2x1+107+42 107.5,42.0 2 srgb(47,140,87)
  133: 2x1+100+88 100.5,88.0 2 srgb(103,180,65)
  143: 2x1+98+92 98.5,92.0 2 srgb(103,180,65)
  100: 2x1+116+42 116.5,42.0 2 srgb(103,180,65)
  32: 1x2+0+30 0.0,30.5 2 srgb(103,180,65)
  135: 1x2+103+88 103.0,88.5 2 srgb(103,180,65)
  148: 1x2+88+108 88.0,108.5 2 srgb(47,140,87)
  121: 1x2+120+52 120.0,52.5 2 srgb(240,240,240)
  120: 1x2+119+52 119.0,52.5 2 srgb(47,140,87)
  59: 1x2+18+35 18.0,35.5 2 srgb(47,140,87)
  89: 2x1+20+39 20.5,39.0 2 srgb(103,180,65)
  105: 1x1+107+45 107.0,45.0 1 srgb(47,140,87)
  106: 1x1+108+46 108.0,46.0 1 srgb(59,79,162)
  107: 1x1+114+46 114.0,46.0 1 srgb(103,180,65)
  108: 1x1+112+47 112.0,47.0 1 srgb(47,140,87)
  109: 1x1+115+47 115.0,47.0 1 srgb(103,180,65)
  111: 1x1+113+48 113.0,48.0 1 srgb(103,180,65)
  112: 1x1+116+48 116.0,48.0 1 srgb(103,180,65)
  113: 1x1+114+49 114.0,49.0 1 srgb(103,180,65)
  114: 1x1+117+49 117.0,49.0 1 srgb(47,140,87)
  115: 1x1+115+50 115.0,50.0 1 srgb(103,180,65)
  116: 1x1+116+51 116.0,51.0 1 srgb(47,140,87)
  117: 1x1+120+51 120.0,51.0 1 srgb(103,180,65)
  136: 1x1+99+89 99.0,89.0 1 srgb(103,180,65)
  137: 1x1+98+90 98.0,90.0 1 srgb(103,180,65)
  138: 1x1+102+90 102.0,90.0 1 srgb(103,180,65)
  139: 1x1+97+91 97.0,91.0 1 srgb(103,180,65)
  140: 1x1+100+91 100.0,91.0 1 srgb(103,180,65)
  142: 1x1+97+92 97.0,92.0 1 srgb(47,140,87)
  150: 1x1+86+109 86.0,109.0 1 srgb(47,140,87)
  151: 1x1+85+110 85.0,110.0 1 srgb(103,180,65)
  153: 1x1+87+110 87.0,110.0 1 srgb(47,140,87)
  155: 1x1+84+111 84.0,111.0 1 srgb(103,180,65)
  157: 1x1+83+112 83.0,112.0 1 srgb(103,180,65)
  158: 1x1+82+113 82.0,113.0 1 srgb(47,140,87)
  159: 1x1+86+113 86.0,113.0 1 srgb(103,180,65)
  9: 1x1+50+3 50.0,3.0 1 srgb(47,140,87)
  11: 1x1+66+5 66.0,5.0 1 srgb(47,140,87)
  12: 1x1+73+5 73.0,5.0 1 srgb(47,140,87)
  14: 1x1+72+6 72.0,6.0 1 srgb(47,140,87)
  15: 1x1+52+7 52.0,7.0 1 srgb(47,140,87)
  17: 1x1+71+7 71.0,7.0 1 srgb(47,140,87)
  18: 1x1+70+8 70.0,8.0 1 srgb(47,140,87)
  19: 1x1+53+9 53.0,9.0 1 srgb(47,140,87)
  20: 1x1+54+10 54.0,10.0 1 srgb(47,140,87)
  23: 1x1+59+15 59.0,15.0 1 srgb(47,140,87)
  24: 1x1+60+16 60.0,16.0 1 srgb(47,140,87)
  25: 1x1+69+16 69.0,16.0 1 srgb(47,140,87)
  26: 1x1+61+17 61.0,17.0 1 srgb(47,140,87)
  27: 1x1+62+18 62.0,18.0 1 srgb(47,140,87)
  31: 1x1+0+29 0.0,29.0 1 srgb(47,140,87)
  36: 1x1+82+31 82.0,31.0 1 srgb(59,79,162)
  37: 1x1+28+32 28.0,32.0 1 srgb(47,140,87)
  39: 1x1+40+32 40.0,32.0 1 srgb(47,140,87)
  40: 1x1+41+32 41.0,32.0 1 srgb(103,180,65)
  41: 1x1+42+32 42.0,32.0 1 srgb(47,140,87)
  42: 1x1+43+32 43.0,32.0 1 srgb(0,0,0)
  45: 1x1+82+32 82.0,32.0 1 srgb(103,180,65)
  46: 1x1+28+33 28.0,33.0 1 srgb(0,0,0)
  47: 1x1+29+33 29.0,33.0 1 srgb(47,140,87)
  49: 1x1+41+33 41.0,33.0 1 srgb(240,240,240)
  50: 1x1+43+33 43.0,33.0 1 srgb(47,140,87)
  51: 1x1+81+33 81.0,33.0 1 srgb(103,180,65)
  53: 1x1+21+34 21.0,34.0 1 srgb(47,140,87)
  54: 1x1+28+34 28.0,34.0 1 srgb(47,140,87)
  57: 1x1+77+34 77.0,34.0 1 srgb(103,180,65)
  58: 1x1+79+34 79.0,34.0 1 srgb(47,140,87)
  60: 1x1+19+35 19.0,35.0 1 srgb(59,79,162)
  61: 1x1+20+35 20.0,35.0 1 srgb(47,140,87)
  62: 1x1+28+35 28.0,35.0 1 srgb(103,180,65)
  63: 1x1+39+35 39.0,35.0 1 srgb(103,180,65)
  65: 1x1+16+36 16.0,36.0 1 srgb(47,140,87)
  67: 1x1+28+36 28.0,36.0 1 srgb(47,140,87)
  68: 1x1+33+36 33.0,36.0 1 srgb(103,180,65)
  69: 1x1+38+36 38.0,36.0 1 srgb(103,180,65)
  70: 1x1+45+36 45.0,36.0 1 srgb(103,180,65)
  72: 1x1+19+37 19.0,37.0 1 srgb(47,140,87)
  73: 1x1+29+37 29.0,37.0 1 srgb(47,140,87)
  74: 1x1+43+37 43.0,37.0 1 srgb(47,140,87)
  75: 1x1+115+37 115.0,37.0 1 srgb(47,140,87)
  76: 1x1+116+37 116.0,37.0 1 srgb(230,230,97)
  77: 1x1+0+38 0.0,38.0 1 srgb(47,140,87)
  78: 1x1+22+38 22.0,38.0 1 srgb(103,180,65)
  79: 1x1+30+38 30.0,38.0 1 srgb(47,140,87)
  80: 1x1+31+38 31.0,38.0 1 srgb(103,180,65)
  81: 1x1+32+38 32.0,38.0 1 srgb(47,140,87)
  84: 1x1+41+38 41.0,38.0 1 srgb(103,180,65)
  85: 1x1+42+38 42.0,38.0 1 srgb(47,140,87)
  86: 1x1+114+38 114.0,38.0 1 srgb(47,140,87)
  88: 1x1+117+38 117.0,38.0 1 srgb(230,230,97)
  90: 1x1+113+39 113.0,39.0 1 srgb(47,140,87)
  91: 1x1+118+39 118.0,39.0 1 srgb(230,230,97)
  92: 1x1+119+39 119.0,39.0 1 srgb(47,140,87)
  93: 1x1+112+40 112.0,40.0 1 srgb(47,140,87)
  94: 1x1+119+40 119.0,40.0 1 srgb(230,230,97)
  95: 1x1+110+41 110.0,41.0 1 srgb(103,180,65)
  96: 1x1+111+41 111.0,41.0 1 srgb(230,230,97)
  98: 1x1+109+42 109.0,42.0 1 srgb(103,180,65)
  99: 1x1+115+42 115.0,42.0 1 srgb(230,230,97)
  101: 1x1+120+42 120.0,42.0 1 srgb(103,180,65)
  102: 1x1+114+43 114.0,43.0 1 srgb(47,140,87)
  103: 1x1+118+43 118.0,43.0 1 srgb(47,140,87)
  104: 1x1+120+44 120.0,44.0 1 srgb(47,140,87)

enter image description here

人们可以做Mark所做的将每种颜色提取为单独的图像。

或者,我们可以使用调用ImageMagick的bash Unix shell脚本替换整个过程,对原始图像进行kmeans分类,并将生成的颜色分离为单独的图层或图像。见http://www.fmwconcepts.com/imagemagick/index.php

一个提供了6种颜色的列表作为种子(或者,只是所需颜色的数量)到脚本。所以我会用Mark的颜色。 Kmeans迭代地将各种颜色聚合到它们的聚类装置上。见https://en.wikipedia.org/wiki/K-means_clustering

kmeans -s "rgb(59,79,162) rgb(230,30,35) rgb(240,240,240) rgb(230,230,97) rgb(103,180,65) rgb(47,140,87)" -t layered 4htJX.png result_%d.png

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.