Add contrast weighted option and fix resample for constrast #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request includes two changes:
It add a new smoothing algorithm "contrast weighted". This is just Lloyd smoothing using the image gradient as a weight function. However, because we need to iterate over the pixels of the image, this new method is slower than the others. But it gives really nice results if your goal is to capture edges in the image as part of the triangulation. Also, it gives interesting pictures in "Circles" mode where the dots get lined up along the edges.
I reworked the "resample by contrast" slider since it had a bug and wasn't really doing what I expected previously. Now the resampling slider works on a scale from 1-100%, is a lot faster and can cause a little more density in near the edges that we saw previously.
There still seems to be some kind of bug where the Delaunay triangulation fails. I think this is a known robustness issue in the d3 code (see here), but unfortunately, it seems to be more common using contrast weighted smoothing and a large number of points, presumably since in that setting we get some lower quality cells and lots points sort of in a line. But I don't know of a good solution beyond getting deep into the d3 code or writing a new triangulator.