|
Extracting pixels coordinates from a bitmap |
Paul whoknows
Member #5,081
September 2004
|
From time to time I find myself drawing trajectories in MS Paint and then writting down every pixel coordinates in the code of my games, doing this by hand really pisses me off, so before I start to write a little tool to automatize this task I wanted to know if someone knows if there is an application already written which I could use for this purpose, or some advice to write my own. For example, the program should read the yellow pixels and write a text file with points coordinates, this points should be sorted (from left to right, or top to bottom). {"name":"599509","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/0\/103020fea8dfc5b24ec9fc4bb55c0e73.png","w":500,"h":296,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/0\/103020fea8dfc5b24ec9fc4bb55c0e73"} I am sure there must be some application already written for things like these!!! I don't want to reinvent it! ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
verthex
Member #11,340
September 2009
|
This is the approach I would take assuming there is no software for it, basically you can extrapolate all the yellow points that are the same color, within a given area of pixels (tolerance). So the steps would be, 1) import image into allegro 4) you created a vector that has the points extrapolated and you go into GNUplot and fit the thing with a polynomial. But you can just Google for a gnuplot polynomial fit and you'll find the formula.
|
Thomas Fjellstrom
Member #476
June 2000
|
Paul whoknows said: For example, the program should read the yellow pixels and write a text file with points coordinates, this points should be sorted (from left to right, or top to bottom). That would be pretty simple to whip up if all you want is all pixels with a given color. Though taking a look at your example image, you probably want to flatten that line a bit I personally don't know of any pre made tools to do this. Though if one existed, and could actually create a "path" of the lines found in the image, that would be better than just the pixel coordinates. Shape/Line extraction tends to hurt my brain, so I haven't managed to code it fully yet. -- |
verthex
Member #11,340
September 2009
|
I used The Gimp to make the image I attached, its a gif. and save as somename.gif This should make it easier to extrapolate the coordinates cause now you should have a transparent gif. EDIT: You need to find ImageMagick and download it, you can convert the gif I uploaded into a jpeg and follow these instructions 1Here is an example:
2
3#create heart shaped image:
4convert -font WebDings -pointsize 24 label:Y \
5+trim +repage -negate -bordercolor black -border 10 heart_mask.gif
6
7
8#create binary edge
9convert heart_mask.gif -edge 1 -threshold 0 heart_mask_edge.gif
10
11
12# list coordinates of only white edge pixels
13convert heart_mask_edge.gif txt:- | sed -n 's/^\(.*\):.*white$/\1/p'
1413,10
1514,10
1615,10
1722,10
1823,10
1924,10
2011,11
2112,11
2213,11
2314,11
2415,11
2516,11
2617,11
2720,11
2821,11
2922,11
3023,11
3124,11
3225,11
3326,11
3411,12
3512,12
3616,12
3717,12
3818,12
3920,12
4021,12
4125,12
4226,12
4310,13
4411,13
4517,13
4618,13
4719,13
4820,13
4926,13
5027,13
5110,14
5211,14
5326,14
5427,14
5510,15
5611,15
5726,15
5827,15
5910,16
6011,16
6126,16
6227,16
6311,17
6412,17
6525,17
6626,17
6711,18
6812,18
6913,18
7024,18
7125,18
7226,18
7312,19
7413,19
7514,19
7623,19
7724,19
7825,19
7913,20
8014,20
8115,20
8222,20
8323,20
8424,20
8514,21
8615,21
8721,21
8822,21
8923,21
9015,22
9116,22
9220,22
9321,22
9422,22
9515,23
9616,23
9718,23
9819,23
9920,23
10021,23
10115,24
10216,24
10317,24
10418,24
10519,24
10615,25
10716,25
10817,25
10918,25
11015,26
11116,26
|
Paul whoknows
Member #5,081
September 2004
|
Thanks verthex, that application is really useful, however, I just found this ImageJ application which has a Save XY coordinates, exactly what I have been looking for, just in case here is the site: ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
|