i have question regarding looping through table of data not storing data in table; instead, store location of piece of data in table.
what working table of pgm pixel values either defined number 0 black , 255 white. hoping table loop through , store location of pixel, row , column number, in array, if pixel displays value of 255.
i don't have pgm table me @ moment i'll provide 1 example. make simple please me log position of pixels display value of 15? answers appreciated :)
p2 # feep.pgm 24 7 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0 0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0 0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
you can this:
var locs = [], row, col, pixeldata = ..., nrows = ..., ncols = ...; (row = 0; row < nrows; ++row) { (col = 0; col < ncols; ++col) { if (pixeldata[row][col] == 15) { locs.push([row, col]); } } } // locs array has [row,col] locations of pixels value 15
in above, pixeldata
array of rows, each of array of pixel values:
var pixeldata = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, . . .], [0, 3, 3, 3, 3, 0, 0, 7, 7, . . .], . . . ];
at end, should expect locs
array of two-element arrays, if initialized with:
var locs = [ [1, 19], [1,20], [1,21], [1,22], [2, 19], [2,22], ... ];
Comments
Post a Comment