<p>Here is a brute force algorithm. This requires some temporary storage (another image, an array, etc.) to record the visited pixels.</p>

<ol>
<li>Start at the first pixel and continue iterating over the image until you find a green pixel. Mark each read pixel as "visited".</li>
<li>Extract the set of green neighbor pixels and record them. Also tag them as "visited". The idea is to find all the green pixels connected to the one found in [1].</li>
<li>If any pixels in the source image are left, go back to [1].</li>
</ol>

<p>This will give you a set of contiguous green pixel regions where each pixel appears 1 or 0 times.</p>

CC BY-SA 3.0
2017-11-06T15:07:57.027Z
2017-11-06T15:07:57.027Z
bernie
<p>Given a png image with an unknown number of green colored <em>(rgba=0, 65535, 0, 65535)</em> regions <a href="https://i.sstatic.net/0nynM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0nynM.png" alt=""></a></p>

<p><strong>1- How can I find and put the border points of only the separate green boxes to an array like:</strong></p>

<pre><code>[0] = []point{...} // the first box's points
[1] = []point{...} // the second box's points
[...] = []point{...} // 
[7] = []point{...} // the last box's points
</code></pre>

<p><strong>2- Which algorithm(s) should I use?</strong></p>

<p><em>I tried canny edge detector and my own custom ones (like flood-fill) but the canny algorithm finds all the regions not only the green ones</em>.</p>

CC BY-SA 3.0
2017-11-07T03:21:39.920Z
Are these guaranteed to be the exact color you've shown above, or might they vary a bit from region to region?
user1118321
CC BY-SA 3.0
2017-11-07T08:53:22.393Z
@user1118321 Let’s assume they’re exact for now.
Inanc Gumus
<image-processing><color>
Extracting the green-screen region borders
Inanc Gumus
# Extracting the green-screen region borders

(Asked by: username_0 on 2017-11-06)

Given a png image with an unknown number of green colored *(rgba=0, 65535, 0, 65535)* regions [![](https://i.sstatic.net/0nynM.png)](https://i.sstatic.net/0nynM.png)

**1- How can I find and put the border points of only the separate green boxes to an array like:**

```
[0] = []point{...} // the first box's points
[1] = []point{...} // the second box's points
[...] = []point{...} // 
[7] = []point{...} // the last box's points

```

**2- Which algorithm(s) should I use?**

*I tried canny edge detector and my own custom ones (like flood-fill) but the canny algorithm finds all the regions not only the green ones*.

**Tags:** image-processing, color

> **Comments:**
> **username_1**: Are these guaranteed to be the exact color you've shown above, or might they vary a bit from region to region?  
> **username_0**: @username_1 Let’s assume they’re exact for now.  

---

## 1 answers

### Answer by username_2 on 2017-11-06. Score: 1

Here is a brute force algorithm. This requires some temporary storage (another image, an array, etc.) to record the visited pixels.

1. Start at the first pixel and continue iterating over the image until you find a green pixel. Mark each read pixel as "visited".
2. Extract the set of green neighbor pixels and record them. Also tag them as "visited". The idea is to find all the green pixels connected to the one found in [1].
3. If any pixels in the source image are left, go back to [1].

This will give you a set of contiguous green pixel regions where each pixel appears 1 or 0 times.


---

