comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » linear interpolation to form a deformation field
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
linear interpolation to form a deformation field [message #88419] Wed, 23 April 2014 13:26 Go to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Hi

I am trying to perform linear interpolation but I am getting an error. I had the following data:

I insert the ARRAY CSV file into IDL. Then I had create the BX as shown below

ARRAY STRING = Array[384, 384]
DX INT = Array[4, 4]

I use the INTERPOL() function: result=INTERPOL(Dx,array)
I got the following error:

IDL> example
FINDGEN: Variable is undefined: X.
Error occurred at: INTERPOL 146 C:\Program Files (x86)\ITT\IDL64\lib\interpol.pro

I didn't defined the variable X nowhere in my code so I didn't see why I got this error. Does anyone know why I got this error?

With Thanks
G.
Re: linear interpolation to form a deformation field [message #88422 is a reply to message #88419] Wed, 23 April 2014 13:57 Go to previous messageGo to next message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
On Wednesday, April 23, 2014 3:26:02 PM UTC-5, g.na...@gmail.com wrote:

>
> I didn't defined the variable X nowhere in my code so I didn't see why I got this error. Does anyone know why I got this error?
>
>
>
> With Thanks
>
> G.

Well, this error tells you the problem is "inside" interpol, so it doesn't matter if you've defined x or not - it's "inside" Interpol.

But, looking closely at your code, I see array is of type string.

From http://exelisvis.com/docs/INTERPOL.html:

An input vector of any type except string.

You need to change the string array to a numeric.
Re: linear interpolation to form a deformation field [message #88427 is a reply to message #88419] Thu, 24 April 2014 02:14 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
How shall I change the string array to a numeric?

I have an image and I want to use cspline, or spline (any kind of interpolation) to form a deformation field.

I get my data from the image: STRING = Array[384, 384]

I create the following:

Dx= [[1,2,1,1],[2,1,3,1],[5,8,1,2],[3,8,2,1]] - deformation field (x-coordinates)

Dy= [[1,2,3,1],[2,5,4,1],[6,8,1,3],[5,7,2,9]] - deformation field (y-coordinates)

I want to use interpolation to find the displacement in x and y direction respectively. I assume I will end up with two matrices one says the displacement in x direction and the other in the y direction.

I had a look on syntax of cspline() and spline() functions: Result = SPLINE( X, Y, T [, Sigma] [, /DOUBLE] ). It says that X and T must be monotonically increasing. I made the assumption that X is mine Dx (it might be wrong) and in my case Dx is not monotonically increasing so I don't know how to use these functions based on my data.
Re: linear interpolation to form a deformation field [message #88431 is a reply to message #88427] Thu, 24 April 2014 07:26 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Thursday, April 24, 2014 11:14:13 AM UTC+2, g.na...@gmail.com wrote:
> How shall I change the string array to a numeric?
>
>
>
> I have an image and I want to use cspline, or spline (any kind of interpolation) to form a deformation field.
>
>
>
> I get my data from the image: STRING = Array[384, 384]
>
>
>
> I create the following:
>
>
>
> Dx= [[1,2,1,1],[2,1,3,1],[5,8,1,2],[3,8,2,1]] - deformation field (x-coordinates)
>
>
>
> Dy= [[1,2,3,1],[2,5,4,1],[6,8,1,3],[5,7,2,9]] - deformation field (y-coordinates)
>
>
>
> I want to use interpolation to find the displacement in x and y direction respectively. I assume I will end up with two matrices one says the displacement in x direction and the other in the y direction.
>
>
>
> I had a look on syntax of cspline() and spline() functions: Result = SPLINE( X, Y, T [, Sigma] [, /DOUBLE] ). It says that X and T must be monotonically increasing. I made the assumption that X is mine Dx (it might be wrong) and in my case Dx is not monotonically increasing so I don't know how to use these functions based on my data.


To convert a string to numeric you can use float(array), or double(array) for double precision.

As far as I understand it, the spline will help you with 1d data, not 2d. It will work, but give you the wrong answers.
x = findgen(5,5)
y = (x-3)^2
tvscl, rebin(y,50,50), 0
t = FINDGEN(5,5)+0.5
tvscl, rebin(spline(x,y,t),50,50), 1

as you can see, the two squares don't really have anything to do with one another.

So, you need something else, and I think that what you need is interpolate() (http://www.exelisvis.com/docs/INTERPOLATE.html):

x = findgen(5,5)
y = (x-3)^2
tvscl, rebin(y,50,50), 0
dx = FINDGEN(5)+0.5
dy = FINDGEN(5)+0.5
tvscl, rebin(interpolate(y,dx,dy,/grid),50,50), 1

Check out the keywords for interpolate. Cubic=-0.5 is almost always a good one.

Cheers
Re: linear interpolation to form a deformation field [message #88435 is a reply to message #88431] Thu, 24 April 2014 12:06 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
Dear G,
I'll answer you email here to keep what started in the forum in the forum.

Your Email:
You understand well I am working on 2D. My data (from the image) are on csv form. I insert my data and then I create the two deformation fields Dx and Dy. I had a look on the code you send me but I don't know how to use my data on the INTRPOLATE() function. I have to use the tvscl? I didn't know this procedure before. I followed your code and I tried the following but I got error:


Dx= [[1,2,1,1],[2,1,3,1],[5,8,1,2],[3,8,2,1]]


Dy= [[1,2,3,1],[2,5,4,1],[6,8,1,3],[5,7,2,9]]



tvscl, rebin(array,50,50), 0 ;(array=data from the image)



ERRORS:
REBIN: String expression not allowed in this context: ARRAY.


I need to convert the string to numeric first?


My Answer:
Yes, you need to convert a string to numerical before you can interpolate or do any sort of mathematical operation.
Given an array named array, you obtain the numerical variable with:

numArray = float(array)

then given two arrays that define the new x and y coordinates, you could proceed this way:

new_x_coords= [0.5,0.7,1.9,2.3,7.1]
new_y_coords= [2.5,3.2,4.1,5.3,9.1]

If I define my array as:
x = findgen(10,10)
numArray = (x-3)^2

print, interpolate(numArray,new_x_coords,new_y_coords, /grid)

This will give you the values of the function (x-3)^2 in (0.5,2.5) in the first coordinate point of the result [0,0] in the array. And so on for the other points.

I'm not sure that what you need is interpolation... do *you* know what you need?

cheers
Re: linear interpolation to form a deformation field [message #88479 is a reply to message #88419] Thu, 01 May 2014 08:26 Go to previous message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Yes,what I need is interpolation.

In the INTERPOLATE() function how did you know how to specify the X and Y (locations for which interpolates desired). In your example you defined these as dx = FINDGEN(5)+0.5 and dy = FINDGEN(5)+0.5 respectively.

In my case my input data is a [384,384] my deformation field is [4,4] and I want to end up with [384,384].

My question is how can I defined the locations for which interpolates desired?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: xprinter
Next Topic: Re: Error detected while calling MPFIT_FDJAC2

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:39:49 PDT 2025

Total time taken to generate the page: 0.00615 seconds