RasterFairy icon indicating copy to clipboard operation
RasterFairy copied to clipboard

glitchy/blocky output

Open kylemcdonald opened this issue 6 years ago • 1 comments

i'm still working with this cloud-to-grid problem, and wanted to understand rasterfairy a little better because it's so fast for larger datasets. but i'm having trouble getting smooth output. i generated some toy data:

import numpy as np
side = 85
n = side * side
np.random.seed(0)
lhs = np.random.uniform(low=-1, high=+1, size=(n, 2))
lhs = np.cumsum(lhs, axis=0)
lhs -= lhs.min(axis=0)
lhs /= lhs.max(axis=0)
lhs *= (side - 1)

the output from rasterfairy looks like this:

download-4

while a linear assignment solver shows the optimum is:

download-2

is there any way to get a better result out of rasterfairy, or is this "blocky" solution part of the algorithm? with some linear assignment algorithms there are "approximation" knobs that let you tune the run time vs solution accuracy, and i was wondering if rasterfairy has something similar i could tweak.

kylemcdonald avatar Dec 24 '18 21:12 kylemcdonald

Yeah the blockiness is the result of the way Rasterfairy subdivides the cloud which is purely based on vertical and horizontal splits. This is fast but can lead to sub-optimal results depending on the shape of the cloud. Ideally the subdivision algorithm should be replaced with something more intelligent that takes the shape of the cloud into account, but at the moment I can only offer the warp routines that allow to pre-process the cloud.

I have added another demo notebook that shows how to use the coonswarp class: https://github.com/Quasimondo/RasterFairy/blob/master/examples/Raster%20Fairy%20Demo%202.ipynb

Not sure though if the results are any better, maybe you can compare it with your code

Quasimondo avatar Dec 25 '18 12:12 Quasimondo