Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

VS 2012 Finding rectangles of solid color in an image.

$
0
0
I am trying to find a way to determine where rectangles of solid color are in an image. Below is a sample image.



I have searched Google but I assume I am not using the correct terms. I found a couple links that kind of accomplish what I am going for but not quite.

1. http://bobpowell.net/region_from_bitmap.aspx
I tried the example in that link. It works somewhat by giving me a region object that contains the specified color. But, the way it works makes it give too many small rectangles. For example, using the image above it gives 15 rectangles for the first red rectangle each with a size of (7, 1). I assume this is because it just reads the scan-line, though I am not sure.

2. http://www.xtremevbtalk.com/showthread.php?t=248539
This link is a flood-fill algorithm that will give me the fuller rectangles that I want, but since it's a flood-fill, it doesn't scan the entire image and seems to break if I try to scan the image myself.

In summation, I wish to create an algorithm that will find all complete rectangles of a specific color (i.e. all the red or blue rectangles from the above image). So, if I wanted to find all the red rectangles, I would get the following result:


(x, y, w, h)
0, 0, 7, 15
17, 10, 2, 2
22, 10, 2, 2
12, 12, 4, 9
17, 20, 14, 3
22, 23, 9, 4


The last two rectangles make up the bottom-right red rectangle. Let me know if I need to be clearer. I think I confused myself writing this.

Viewing all articles
Browse latest Browse all 27329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>