0

I have a region, created with threshold on the H channel of a image. Now i have a new Region, and reduced its domain to have a new image.

On this new image, I need to count the holes. By holes I mean areas where there are no pixels.

For example, if I have a red board with blue squares on it, and select the reds, I would get a new image filled with square holes where the blue squares were.

How can I get the number of those holes?

I have done it like this, but there must be a better way:

threshold(ImageHGreenReduced, RegionHGreenReduced, 0 ,255)
connect_and_holes(RegionHGreenReduced, NumConnected, NumberCrateWindows)
sharkyenergy
  • 3,842
  • 10
  • 46
  • 97

2 Answers2

3

The way you are doing it looks pretty simple to me. Here is a slight variation. Given the input image:

enter image description here

read_image(Image, './red_board_blue_squares.png')

access_channel(Image, ImageRed, 1)

threshold(ImageRed, ImageRedRegion, 0, 100)

connection(ImageRedRegion, ImageRedConnectedRegions)

count_obj(ImageRedConnectedRegions, NumberOfHoles)

Message := 'Found ' + NumberOfHoles$'d' + ' holes'
dev_disp_text (Message, 'window', 12, 12, \
               'black', [], [])

The following output is produced with the number of holes in the variable "NumberOfHoles"

enter image description here

Jake Chittle
  • 316
  • 1
  • 2
  • 4
0

You could extract the 'holes_num' feature of the red region using:

connect_and_holes(myRegion, numConnected, numHoles) 

As a bonus, you could inspect numConnected to test for condition of a hole that divides the red region.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Jim
  • 56
  • 4