interpolation

Color interpolation between 3 colors

亡梦爱人 提交于 2019-11-30 10:20:14
I use the following equation to get a nice color gradient from colorA to colorB, but I have no idea how to do the same for 3 colors, so the gradient goes from colorA to colorB to colorC colorT = colorA * p + colorB * (1.0 - p); where "p" is the a percentage from 0.0 to 1.0 Thanks Well, for 3 colors, you can just to the same with p = 0.0 to 2.0: if p <= 1.0 colorT = colorA * p + colorB * (1.0 - p); else colorT = colorB * (p - 1.0) + colorC * (2.0 - p); Or scale it so you can still use p = 0.0 to 1.0: if p <= 0.5 colorT = colorA * p * 2.0 + colorB * (0.5 - p) * 2.0; else colorT = colorB * (p - 0

Array interpolation

懵懂的女人 提交于 2019-11-30 10:02:11
Before I start, please accept my apologies that I'm not a mathematician and don't really know the proper names for what I'm trying to do... ;) Pointers to any plain-English explanations that might help would be most appreciated (as I'm purely Googling at the moment based upon what I think the solution might be). If have a multi-dimensionsal array of source values and wanted to upscale that array by a factor of n , I think that what I'd need to use is Bicubic Interpolation Certainly the image top right on that page is representative of what I'm aiming for - creating a graduated flow of values

interpolate missing values 2d python

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 09:36:25
I have a 2d array(or matrix if you prefer) with some missing values represented as NaN . The missing values are typically in a strip along one axis, eg: 1 2 3 NaN 5 2 3 4 Nan 6 3 4 Nan Nan 7 4 5 Nan Nan 8 5 6 7 8 9 where I would like to replace the NaN 's by somewhat sensible numbers. I looked into delaunay triangulation, but found very little documentation. I tried using astropy 's convolve as it supports use of 2d arrays, and is quite straightforward. The problem with this is that convolution is not interpolation, it moves all values towards the average (which could be mitigated by using a

Bilinear interpolation with non-aligned input points

萝らか妹 提交于 2019-11-30 09:07:29
I have a non-grid-aligned set of input values associated with grid-aligned output values. Given a new input value I want to find the output: (These are X,Y coordinates, calibrating an imprecise not-square eye-tracking input device to exact locations on screen.) This looks like Bilinear Interpolation , but my input values are not grid-aligned. Given an input, how can I figure out a reasonable output value? Answer : In this case where I have sets of input and output points, what is actually needed is to perform inverse bilinear interpolation to find the U,V coordinates of the input point within

Scipy interpolation how to resize/resample 3x3 matrix to 5x5?

时间秒杀一切 提交于 2019-11-30 08:59:40
EDIT: Paul has solved this one below. Thanks! I'm trying to resample (upscale) a 3x3 matrix to 5x5, filling in the intermediate points with either interpolate.interp2d or interpolate.RectBivariateSpline (or whatever works). If there's a simple, existing function to do this, I'd like to use it, but I haven't found it yet. For example, a function that would work like: # upscale 2x2 to 4x4 matrixSmall = ([[-1,8],[3,5]]) matrixBig = matrixSmall.resample(4,4,cubic) So, if I start with a 3x3 matrix / array: 0,-2,0 -2,11,-2 0,-2,0 I want to compute a new 5x5 matrix ("I" meaning interpolated value): 0

Algorithm: how calculate INVERSE of bilinear interpolation? INVERSE of mapping on to an arbitrary quadrilateral?

无人久伴 提交于 2019-11-30 08:50:20
问题 UPDATE: My terminology below is wrong. The "forward" algorithm I describe in "Lerp2D" (which I need inverse-of) takes 4 arbitrary corners. It is linear along each edge, but all 4 edges can independently stretch; it is not bilinear . I've left bilinear in the title - if you come here looking for "inverse of bilinear", e.g. independent stretching in x and y , see Spektre's answer. If you need a more general case (stretching defined by an arbitrary quadrilateral), then see the accepted answer.

Create array in loop from number of arguments

微笑、不失礼 提交于 2019-11-30 08:24:29
#!/bin/bash COUNTER=$# until [ $COUNTER -eq 0 ]; do args[$COUNTER]=\$$COUNTER let COUNTER-=1 done echo ${args[@]} When i run this, I get the following results user@host:~/sandbox# ./script.sh first second third $1 $2 $3 and i'm expecting it to echo out what $1, $2, and $3 are not a text value of "$1" I'm trying to write a script in bash that will create an array that is the size of the number of arguments I give it. I'm expecting user@host:~/sandbox# ./script.sh alpha bravo charlie alpha bravo charlie or user@host:~/sandbox# ./script.sh 23425 jasson orange green verb noun coffee 23425 jasson

Interpolate (or extrapolate) only small gaps in pandas dataframe

久未见 提交于 2019-11-30 07:36:26
I have a pandas DataFrame with time as index (1 min Freq) and several columns worth of data. Sometimes the data contains NaN. If so, I want to interpolate only if the gap is not longer than 5 Minutes. In this case this would be a maximum of 5 consecutive NaNs. The data may look like this (several test cases, which show the problems): import numpy as np import pandas as pd from datetime import datetime start = datetime(2014,2,21,14,50) data = pd.DataFrame(index=[start + timedelta(minutes=1*x) for x in range(0, 8)], data={'a': [123.5, np.NaN, 136.3, 164.3, 213.0, 164.3, 213.0, 221.1], 'b': [433

opencv find concave hull

两盒软妹~` 提交于 2019-11-30 07:31:59
问题 I have a set of discrete points shown in an image, like the following I want to reconstruct or up sampling (I'm not sure what's the correct way to describe it) the image, so that the result image would be like the following . It doesn't need to be exactly the same as the example image, but the main idea is to fill up the original one. I have an initial idea about how to do it. But I don't know how to do it after the first step. My idea is to first separate image using kmeans and find out the

spline interpolation coefficients of a line curve in 3d space

梦想的初衷 提交于 2019-11-30 07:08:26
I am new to python. I have a line curve in the 3D space defined by a set of given points. Can anyone suggest how I can use the interpolate with spline functions of the scipy package to get the spline coefficients of the curve just like the spline.coeff function in MATLAB? Thank you! EDIT: I have used the tck = interpolate.SmoothBivariateSpline(pts2[:,0], pts2[:,1], pts2[:,2]) test_pts = pts2[:,2]-tck.ev(pts2[:,0], pts2[:,1]) print test_pts but this is for surfaces apparently and not for line curves pts2 is a Nx3 numpy array containing the coordinates of the points ok I figured out what I was