0

I have some data about a set of coordinates, like {(x=1, y=2), (x=3, y=4), ...}. I projected these coordinates on the picture. Then I would like to count these point in different position. My idea is below

First, separate the picture from several pixel parts based on 10 pixels. Second, count the point inside the pixel box.

I am new in these area, and I use python a lot. I think this may be computer graphic problem.

I am not asking for a code solution. I just want to know which libraries or approaches that are related.

Anyone could give me a hint would be highly appreciated. Thanks.

Peter Tsung
  • 915
  • 2
  • 10
  • 20
  • If you already projected the points into an image (I assume white points on a black image) then you can just use [countNonZero](http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#countnonzero) function of opencv. If it is only counting, you may project the coordinates to an image plane, then and count how many are within the bounds of the image (width and height), then you can do it without any libraries.... – api55 Jul 11 '17 at 08:18
  • @api55 thanks. What I need to do is to project coordinate to an image and count. Which libraries are related to that procedure? – Peter Tsung Jul 11 '17 at 09:37
  • just opencv and python is ok (opencv needs numpy) – api55 Jul 11 '17 at 10:02
  • @api55 thanks. I naively thought that I only need to use `matplotlib` – Peter Tsung Jul 11 '17 at 10:04
  • you can also do it with python only, since it is basic math, if it is counting there is no need to put it in an image, but if it is needed then opencv, matplotlib or PIL to name a few are good for the task – api55 Jul 11 '17 at 10:06
  • @api55 hmmm. If I have a picture with grid, then I need to count the points number which are projected to an image and in specific area, then which python library could I use? – Peter Tsung Jul 11 '17 at 10:10
  • If you project a point to an image plane (defined as a grid), there is no need to draw them and count them, it is enough to loop through this points (which can be a python list with 2 numbers) and check if the are inside the image and area. I would say it is only needed the image if the points can fall in the same position as another point and this should count as only 1. Also you can do it with grid (list of list) or with numpy matrix or with any of the other libraries i mentioned before – api55 Jul 11 '17 at 10:17

1 Answers1

0

Sure, your approach seems fine. You simply want to count the number of pixels in different image regions that you placed, correct?

I answered a question recently (with Python) that was giving an indication if there was a black pixel inside an image region. It could be easily modified to count pixels instead of simply finding one. Check it out here and modify your question or post a new one if you have code problems working it out.

alkasm
  • 22,094
  • 5
  • 78
  • 94