Peter
Peter

Reputation: 3495

Is there a way to get better antialiasing with scipy zoom

I'm making a mouse tracking script, and I just tried writing my own resampling since I want the output to merge all recorded resolutions, but I couldn't iron out some bugs so gave up and tried out scipy for it.

It almost works perfectly, but it looks bad at the same time, especially if making an image smaller. I thought this might be normal until I saw the result from PIL, which was pretty much perfect, just unfortunately by that time it's too late to merge the arrays.

For the record, new_data is in the format [[(x0, y0), (x1, y0)],[(x1, y0),.... Originally it's in a dictionary where each coordinate is a key (but I don't think that can be made into a numpy array).

Here's downscaling using scipy:

zoom_factor = (desired_resolution[0] / current_resolution[0],
               desired_resolution[1] / current_resolution[1])
numpy_image = zoom(np.array(new_data), zoom_factor, order=1)

enter image description here

Here's using PIL:

im = im.resize(desired_resolution, Image.ANTIALIAS)

enter image description here

As you can see, PIL is a lot smoother. The only suggestion I can think of currently is to use scipy to upscale to the largest resolution, then use PIL to downscale again, but it seems messy. If anyone has another idea please let me know.

Upvotes: 2

Views: 548

Answers (1)

Peter
Peter

Reputation: 3495

It turns out that upscaling with scipy, combining then converting to RGB, then downscaling with PIL, is exactly what was needed.

The upscaling was done to 4k, though it still looked almost the same (just slightly more jagged) at 1080p. From the list of 4k arrays, I could then combine the results by getting the maximum value and converting it to it's colour value. From that point it's as simple as feeding it into PIL and telling it to resize to something smaller.

Here is the result with a combined 2560x1440 and 800x600 tracks (saved at 720p): enter image description here

Obviously the size difference can't really be helped as I'm not storing vectors or anything, but it does demonstrate how it deals with multiple resolutions combined.

Upvotes: 1

Related Questions