Last active
February 20, 2016 00:53
-
-
Save ps/d47d9eeba18b56cd3fba to your computer and use it in GitHub Desktop.
Get x,y coordinates in order of left to right occurance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place: "fprintf('[%i, %i],',round((maxr+minr)/2), round((maxc + minc)/2));" in Matlab for image test1.bmp or test2.bmp | |
# put the output into test1/test2 var as below | |
# script prints out centers of figures on image in order (left to right then top to bottom) | |
def gen_data(a,mod): | |
a_by_rows = [] | |
temp_row = [] | |
i=1 | |
for x,y in a: | |
temp_row.append([y,x]) | |
if i % mod == 0: | |
temp_row.sort() | |
#temp_row_back = [] | |
#for y_org, x_org in temp_row: | |
# temp_row_back.append([x_org,y_org]) | |
#a_by_rows.append(temp_row_back) | |
a_by_rows.append(temp_row) | |
temp_row = [] | |
i +=1 | |
for i in range(len(a_by_rows)): | |
string = "" | |
for x,y in a_by_rows[i]: | |
string += "%i %i;" % (x,y) | |
print "%s" % string; | |
test1 = [[35, 34],[181, 34],[700, 36],[255, 31],[102, 32],[338, 36],[483, 35],[406, 36],[562, 37],[632, 36],[706, 111],[31, 109],[100, 112],[186, 115],[330, 119],[406, 116],[630, 116],[563, 116],[254, 118],[482, 122],[102, 181],[334, 191],[35, 185],[705, 193],[631, 189],[183, 191],[256, 190],[480, 192],[565, 193],[407, 193],[704, 261],[332, 268],[260, 259],[482, 257],[102, 260],[182, 265],[631, 264],[36, 266],[407, 266],[561, 268],[257, 329],[330, 337],[704, 339],[32, 335],[629, 337],[178, 338],[480, 334],[559, 338],[101, 337],[405, 338],[331, 408],[255, 406],[631, 408],[482, 406],[707, 412],[34, 411],[102, 409],[558, 410],[183, 415],[400, 416],[709, 486],[184, 485],[252, 482],[333, 484],[482, 487],[631, 489],[33, 491],[407, 487],[104, 486],[559, 491]] | |
test2 = [[939, 36],[1047, 35],[659, 41],[853, 37],[541, 41],[750, 43],[314, 45],[80, 46],[211, 45],[432, 43],[434, 101],[537, 109],[939, 106],[1052, 106],[655, 111],[315, 119],[849, 115],[748, 121],[207, 129],[83, 135],[939, 204],[1048, 206],[850, 208],[531, 215],[425, 211],[311, 222],[652, 221],[741, 222],[208, 226],[81, 233],[1050, 302],[426, 298],[940, 306],[531, 302],[209, 309],[314, 311],[648, 311],[743, 312],[846, 314],[85, 320],[530, 423],[420, 412],[1050, 424],[315, 423],[651, 425],[738, 424],[844, 425],[941, 429],[207, 428],[86, 439],[946, 507],[1051, 513],[845, 519],[739, 525],[650, 533],[418, 529],[308, 540],[206, 543],[527, 541],[84, 550],[1052, 598],[946, 613],[847, 618],[421, 615],[650, 626],[740, 623],[531, 632],[201, 629],[308, 635],[84, 639],[427, 706],[1049, 707],[203, 710],[852, 712],[307, 721],[741, 716],[949, 715],[83, 720],[534, 729],[652, 730]]; | |
# test1 | |
test1.sort() | |
gen_data(test1,7) | |
# test2 | |
test2.sort() | |
gen_data(test2,8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment