Children are very good at classifying objects and counting them. Computers seem to have more trouble. This is a simplified version of this problem. Can you write a small program that can classify and count objects in an image?
The problem: Given an image containing one or more circles and rectangles, return 2 integers with the count of circles and count of rectangles.
Rules
- The input image will be black figures on a white background in any bitmap format you choose.
- The image width and height will be between 100 and 1000 pixels.
- Figures will be fully contained within the image.
- Figures will have 1 pixel line width.
- Images will not use anti-aliasing. They will be black on white only.
- Figures may touch, intersect, or be inside another figure.
- Intersecting figures will have a maximum of 4 common pixels.
- Circles will have a diameter of 20 pixels or more.
- Rectangle sides will be 10 or more pixels long.
- You may not use any built-ins or libraries that recognize shapes, or any other function that makes this challenge trivial.
- Return or print 2 integers with the counts of circles and rectangles.
Example 1
Answer: 3 4
Example 2:
Answer: 4 13
This is a code golf challenge, so the shortest program or function in each language will win.