cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Objects Counting

ptc-5743339
1-Visitor

Objects Counting

Hi!

Currently, I'm working in a people counting project.

As a start, I want to make a program where given this image of a group of coins:

coins.JPG

one can authomaticaly count how many coins are there in the image.

With some matrix manipulation, I've issolated the coin borders:

rgb1.bmp

And now I want to know if someone can help me in counting how many of these round blobs is there in my image. That is, the program that I want to create must tell me: "there is 10 objects in the image"

Any ideas?

thanks.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:ptc-5743339)

I remembered the function shape_features() which gives a lot of information about shapes in the pic, but either it isn't suitable for yourproblem or I am not able to use it correctly, anyway it will see all 10 blobs as a single shape.

Nevertheless with the help of the very helpful Image Processing E-book that comes with Mathcad I think I found a way to get filled blobs very easy and without trickery. Guess counting will be easier with those shapes.

17.03.png

View solution in original post

6 REPLIES 6
Werner_E
25-Diamond I
(To:ptc-5743339)

Pattern recognizion isn't so easy you could do it with just a few lines of code. Think you also do not want to reinvent the wheel, so why not study the appropriate, relevant literature to find some proven algorithms.

Or you may use a specialized software. This one is free but still in its alpha phase: http://vision2u.de/index_en.html

Werner_E
25-Diamond I
(To:ptc-5743339)

With some matrix manipulation, I've issolated the coin borders:

Isn't that something which Mathcads Image Processing Tools can do out of the box? There are quite a couple of different Edge detectors available to chose from. How to automatically chose appropriate parameters for pics with different intensity gradients may be the next question. I'm no expert in image processing but I could imagine that some of Mathcads analysis histogram functions could help in finding those values. Maybe it even makes sense applying levelmap() or equalize() before going to the edge detection so that there is a uniform transformation on intensity levels throughout. Just some thoughts, no expertise.

BTW, I guess that detecting and counting blobs could be easier if the shapes are fully filled.

One way I could image to count blobs could be to run through the pic (I assume filled blobs as at the bottom right) and when you arrive at a white pixel, you apply some kind of floodfill algorithm - without changing the pix, just to get the dimensions of the object (so you don't need a full fledged floodfill, just be sure to get width and height of the object). Collect the rectangles found that way in a list and go ahead scanning the pic. For every white pixel you check if the coordinates of the pixel are already inside one of the rectangles in the list, if not -> new rectangle found.

In case you didn't notice: In the bottom right pic I was cheating as I told Mathcads reg_grow() to color 10 regions, so i was using already the known number of coins 😉

17.03.png

Werner_E
25-Diamond I
(To:ptc-5743339)

I remembered the function shape_features() which gives a lot of information about shapes in the pic, but either it isn't suitable for yourproblem or I am not able to use it correctly, anyway it will see all 10 blobs as a single shape.

Nevertheless with the help of the very helpful Image Processing E-book that comes with Mathcad I think I found a way to get filled blobs very easy and without trickery. Guess counting will be easier with those shapes.

17.03.png

Thank you so much.

Obviously I'm not really familiar to this Image Processing tools.

My boss wants me to use only mathcad for such a problem as people counting, so I think that blob counting is a good start.

With the help that you had provide me, I think I will make it.

Thank you.

Werner_E
25-Diamond I
(To:ptc-5743339)

I don't think that Mathcad is the right tool for this job. The functions offered by Mathcads image processing are OK for image manipulation but there is nothing in terms of pattern recognition, shape matching, etc.

Even if you are willing and able to reinvent the wheel and implement suitable routines in Mathcad, they will perform very slow. Mathcad is in no way made for real time applications and routines written in Mathcad are interpreted, which of course is slow. You can help speeding up by creating user DLLs, coding vital routines in C++ and calling the compilaton from within mathcad.

Find attached a solution to your counting problem. I have implemented a simple (but at least non-recursive) floodfill algorithm and it performs really awfully slow. The object count routine will not only return the number of the objects counted but also an image matrix where the background is all zero, object 1 is all 2, etc. This can be used to mask the original picture, show just one selected object, etc. Just for fun I included a way where you can click on any of the coins in the original pic and only this coin is then shown in another pic. Not of use, just done because I could 😉

But be aware that you will run into problems if objects overlap (as they will do in people counting) or if you have to decide which object to count (the man with the hat) and which not (the dog, the car, the ballon flying by, Kingkong climbing on the Empire State, ...). So maybe it would be the better approach to work with the contours as a professional shape recognition would do and as you had started to do. That way you would have a chance to distinguish between overlapped objects and may also apply some property detection to be able to distinguish between wanted and unwanted objects. Sure not an easy task, especially doing it in Mathcad. And I guess the algorithms used for this are not so simple and straightforeward as the floodfill. Also you have to keep in mind that the creation of the object mask I have done will only work OK if the background is fairly even and in good contrast to the objects. This situation is not to be assumed to encounter in real life, I guess.

I'm not sure if you use Prime or Mathcad, in another post I guess you mentioned Prime. So I also attach a pdf print of the worksheet. It won't convert well to Prime because Prime does not allow the display of matrices as pictures like in Mathcad (15 and below). You can load a pic, manipulate the associated matrix in Prime, save the pic and display it with an extern viewer to judge the result - cumbersome!

But if you have a license for Prime you are also entitled to download Mathcad 15 and use it with the same license file. So you may give it a try.

If you have success and are allowed to do so, maybe you can post your work or parts of it here. Sure would be interesting.

18.03.png

Werner,

I have some of the following questions about your program:

1. In what units shows the result of calculating the area? Can we separately calculate the area of each specific circle element separately?

2. How to determine the distance between the centers of the detected circles (edges)?

Announcements

Top Tags