Getting pixel neighbors without duplication
in
Programming Questions
•
9 months ago
I'm looking for suggestions on improving some code that currently runs
really slow (like 10 minutes or longer for a low-res image) - hopefully this description below makes sense! Full code is a bit long for the forum,
but posted here.
I'd like to start with "seed pixels" (hundreds to tens of thousands, depending on the image) and:
I've looked into Set and HashMap as alternatives to standard arrays, but I need to preserve the pixel's position and original color, making things a little tricker.
Ideas at this point:
Whew! All that to say: any ideas on optimization?
I'd like to start with "seed pixels" (hundreds to tens of thousands, depending on the image) and:
- Store all neighboring pixels in a list (up, right, down, and left)
- BUT, make sure that there are no duplicates in the resulting list of locations
- To further complicate, I'd like to do this iteratively, expanding out from a previously gathered set over and over. This also means not gathering pixels that were gathered in previous states of the system.
- !Arrays.asList(newPositions).contains(positionToCheck)
I've looked into Set and HashMap as alternatives to standard arrays, but I need to preserve the pixel's position and original color, making things a little tricker.
Ideas at this point:
- Store a boolean array of previously traversed pixels - check the new positions against that (if the check is what's slowing things down)?
- Some kind of image-mask applied to source - perhaps the underlying image-processing algorithms are optimized for this kind of 2d matrix?
Whew! All that to say: any ideas on optimization?
1