1
votes

I have this image.

enter image description here

I want to classify all of pixels. The color of the pixels in this image is as follows:

  1. Blue: Water
  2. Red: Roof
  3. White: Road
  4. Yellow: Shallow
  5. Light Green: Grass
  6. Dark Green: Tree
  7. Black: Background

How can I classify all pixels. For example if pixel of 2'column and 1'row is blue then classify (1,2) into water's class and so on.

2
Not sure if you are aware that your image has 8,002 colours? Are expecting to end up with a very dark greyscale image containing only the intensities 1,2,3,4? What about yellow pixels too? - Mark Setchell
I edit the question, and image is RGB colors - Saeed
Are there only 7 different RGB values in the image? Or do you want to "group" the different values, meaning there could be different shades of blue for example (with different RGB values) that you'd like to gorup together? - ec2604
I want to group the different values and i have different shades of blue, red, white and other. - Saeed
I think you need to transform RGB into HSL (or similar, really you need only H). So after you have the hue, you can define the intervals - Giacomo Catenazzi

2 Answers

2
votes

I can show you how to do it and what results you will get, and hopefully you can adapt it to Python - if you want to. My weapon of choice is ImageMagick which is installed on most Linux distros and is available for free on macOS and Windows.


Step 1

First, I use a "colour dropper" tool (on a Mac it is called "Digital Color Meter") and I look at areas of each of the 7 colours you have identified and get their RGB coordinates, and make a simple "Look-Up Table" of those values by typing the following into Terminal:

# 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

That file (LUT.png) looks like this - only smaller - I have enlarged it below so you can see it. In reality, it is only 7x1 pixels:

enter image description here


Step 2

Now I apply that Look-Up Table to the image, without dithering, so that each colour in the image is forced to the nearest colour in the table:

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

enter image description here

The image now truly has only the 7 colours we chose, instead of the 8,002 colours in your original image!


Step 3

Now, we go through the image and actually classify it, replacing all the blue pixels with 1, all the red pixels with 2, all the white pixels with 3 and so on:

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

Which gives us this very dark image because all the pixels are 7 or below on range of 0-255:

enter image description here

So we stretch the grey colours out to the full range using normalisation:

convert final.png -normalize final.png

enter image description here


I am guessing the next thing will be to determine the percentages of each of the cover types. Let's look at water first. If we make everything that is water into white pixels and everything that is not water into black pixels, we can calculate the percentage of water coverage simply by looking at the image mean:

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

So there is 12% water coverage. To get the actual image, replace the calculation above with an output filename:

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

enter image description here

Let's try trees next... same procedure, make everything that is trees white, everything that is not trees black:

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

So, 26% trees coverage. Let's look at them:

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

enter image description here


Python

So, what happens in Python?

Step 1 means you allocate a list or array (or whatever Python calls them) with each of the 7 colours. Each entry in the list will have a Red, Green and Blue component.

Step 2. You iterate through each pixel (by row and column) in the image getting its Red, Green and Blue component. You then calculate the colour distance from the current pixel to each of your 7 LUT colours and take the one with the smallest result, i.e. the nearest distance. You calculate the distance with

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

where n will run through the 7 indices of the LUT.

Step 3. You set the output pixel to the index of whichever colour in your LUT was closest.

2
votes

Mark has a good answer. Here is a slightly different approach starting with his 6 color image. Use Imagemagick's connected components labelling to encode each isolated region with an id number. (With -connected-components, you can even merge small isolated regions into their surrounding color. But I will not do that here).

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

In this case, the image will be dark since there are only about 160 ids out of a possible 65535. So for better viewing we can stretch the image to full dynamic range.

convert result1.png -auto-level result2.png

enter image description here

Or we can keep the original colors in the outputs:

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

One can do what Mark did to extract each color as a separate image.

Alternately, we can replace the whole process with my bash Unix shell script calling ImageMagick to do a kmeans classification of the original image and separate the resulting colors into separate layers or images. See http://www.fmwconcepts.com/imagemagick/index.php.

One provides the list of 6 colors as seeds (or alternately, just the number of desired colors) to the script. So I will use Mark's colors. Kmeans iteratively converges the various colors to their cluster means. See 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