Image seg

this is a terribly inefficient loop.
We are looping through n^2 elements, to only process half of them.
How about try iterating through just the nonzero half.