interpolation

Filling gaps in a numpy array

烂漫一生 提交于 2019-11-27 19:31:15
I just want to interpolate, in the simplest possible terms, a 3D dataset. Linear interpolation, nearest neighbour, all that would suffice (this is to start off some algorithm, so no accurate estimate is required). In new scipy versions, things like griddata would be useful, but currently I only have scipy 0.8. So I have a "cube" ( data[:,:,:] , (NixNjxNk)) array, and an array of flags ( flags[:,:,:,] , True or False ) of the same size. I want to interpolate my data for the elements of data where the corresponding element of flag is False, using eg the nearest valid datapoint in data, or some

Fast interpolation of grid data

◇◆丶佛笑我妖孽 提交于 2019-11-27 19:07:08
I have a large 3d np.ndarray of data that represents a physical variable sampled over a volume in a regular grid fashion (as in the value in array[0,0,0] represents the value at physical coords (0,0,0)). I would like to go to a finer grid spacing by interpolating the data in the rough grid. At the moment I'm using scipy griddata linear interpolation but it's pretty slow (~90secs for 20x20x20 array). It's a bit overengineered for my purposes, allowing random sampling of the volume data. Is there anything out there that can take advantage of my regularly spaced data and the fact that there is

How to scale images on a html5 canvas with better interpolation?

南笙酒味 提交于 2019-11-27 17:31:18
First of all: what am I trying to do? I have an application to view images. It uses the canvas element to render the image. You can zoom in, you can zoom out, and you can drag it around. This part works perfectly right now. But let's say I have an image with a lot of text. It has a resolution of 1200x1700, and my canvas has 1200x900. Initially, when zoomed out, this leads to a rendered resolution of ~560x800. My actual drawing looks like this: drawImage(src, srcOffsetX, srcOffsetY, sourceViewWidth, sourceViewHeight, destOffsetX, destOffsetY, destWidth, destHeight); Small text on this image

How to perform interpolation on a 2D array in MATLAB

懵懂的女人 提交于 2019-11-27 16:10:14
How can I make a function of 2 variables and given a 2D array, it would return an interpolated value? I have N x M array A . I need to interpolate it and somehow obtain the function of that surface so I could pick values on not-integer arguments. (I need to use that interpolation as a function of 2 variables) For example: A[N,M] //my array // here is the method I'm looking for. Returns function interpolatedA interpolatedA(3.14,344.1) //That function returns interpolated value For data on a regular grid, use interp2 . If your data is scattered, use griddata . You can create an anonymous

imresize - trying to understand the bicubic interpolation

不想你离开。 提交于 2019-11-27 14:13:35
I'm trying to understand the function: function [weights, indices] = contributions(in_length, out_length, ... scale, kernel, ... kernel_width, antialiasing) if (scale < 1) && (antialiasing) % Use a modified kernel to simultaneously interpolate and % antialias. h = @(x) scale * kernel(scale * x); kernel_width = kernel_width / scale; else % No antialiasing; use unmodified kernel. h = kernel; end I don't really understand what does this line means h = @(x) scale * kernel(scale * x); my scale is 0.5 kernel is cubic. But other than that what does it mean? I think it is like creating a function

Python 4D linear interpolation on a rectangular grid

戏子无情 提交于 2019-11-27 14:02:16
I need to interpolate temperature data linearly in 4 dimensions (latitude, longitude, altitude and time). The number of points is fairly high (360x720x50x8) and I need a fast method of computing the temperature at any point in space and time within the data bounds. I have tried using scipy.interpolate.LinearNDInterpolator but using Qhull for triangulation is inefficient on a rectangular grid and takes hours to complete. By reading this SciPy ticket , the solution seemed to be implementing a new nd interpolator using the standard interp1d to calculate a higher number of data points, and then

Scipy interpolation on a numpy array

≡放荡痞女 提交于 2019-11-27 14:01:51
问题 I have a lookup table that is defined the following way: | <1 2 3 4 5+ -------|---------------------------- <10000 | 3.6 6.5 9.1 11.5 13.8 20000 | 3.9 7.3 10.0 13.1 15.9 20000+ | 4.5 9.2 12.2 14.8 18.2 TR_ua1 = np.array([ [3.6, 6.5, 9.1, 11.5, 13.8], [3.9, 7.3, 10.0, 13.1, 15.9], [4.5, 9.2, 12.2, 14.8, 18.2] ]) The header row elements are (hh) < 1,2,3,4,5+ The header column (inc) elements are <10000, 20000, 20001+ The user will input a value example (1.3, 25,000), (0.2, 50,000), so on. scipy

Extending a Swift class with Objective C category

时光总嘲笑我的痴心妄想 提交于 2019-11-27 13:36:52
问题 Im in a situation where I need to use Objective C category to extend a Swift class. I've done something as follows: In "SomeClass.swift": class SomeClass: NSObject { } In "SomeClass+Extension.h": #import "Project-Swift.h" @interface SomeClass (Extension) -(void)someMethod(); @end This has worked well. And if I try to use the SomeClass extension in my Objective C code, it is fine. The problem is, if I want to use someMethod() in a another Swift class, I will need to put the SomeClass+Extension

How to interpolate hue values in HSV colour space?

本小妞迷上赌 提交于 2019-11-27 12:25:40
问题 I'm trying to interpolate between two colours in HSV colour space to produce a smooth colour gradient. I'm using a linear interpolation, eg: h = (1 - p) * h1 + p * h2 s = (1 - p) * s1 + p * s2 v = (1 - p) * v1 + p * v2 (where p is the percentage, and h1, h2, s1, s2, v1, v2 are the hue, saturation and value components of the two colours) This produces a good result for s and v but not for h. As the hue component is an angle, the calculation needs to work out the shortest distance between h1

Interpolate NA values in a data frame with na.approx

余生长醉 提交于 2019-11-27 12:10:05
I am trying to remove NA s from my data frame by interpolation with na.approx() but can't remove all of the NA s. My data frame is a 4096x4096 with 270.15 as flag for non valid value. I need data to be continous in all points to feed a meteorological model. Yesterday I asked, and obtained an answer, on how to replace values in a data frame based in another data frame. But after that I came to na.approx() and then decided to replace the 270.15 values with NA and try na.approx() to interpolate data. But the question is why na.approx() does not replace all NAs. This is what I am doing: Read the