Code covered by the BSD License

### Highlights from Inverse (integrated) gradient

4.71429
4.7 | 8 ratings Rate this file 32 Downloads (last 30 days) File Size: 12.4 KB File ID: #9734 Version: 1.1

### John D'Errico (view profile)

23 Jan 2006 (Updated )

Vectorized & fully sparse 1-d, 2-d, & 3-d integrated gradients

File Information
Description

The inverse of the gradient function. I've provided versions that work on 1-d vectors, or 2-d or 3-d arrays. In the 1-d case I offer 5 different methods, from cumtrapz, and an integrated cubic spline, plus several finite difference methods.

In higher dimensions, only a finite difference/linear algebra solution is provided, but it is fully vectorized and fully sparse in its approach. In 2-d and 3-d, if the gradients are inconsistent, then a least squares solution is generated.

(I'll enhance the 2-d and 3d tools if there is any interest. Currently they are set to be 2nd order methods on uniform grids.)

Please notify me of any bugs.

Acknowledgements

This file inspired Piv Mat 4.00.

MATLAB release MATLAB 7.0.1 (R14SP1)
05 Jun 2016 jiang

### jiang (view profile)

Your code is very great,and thank you for your share! However I met a problem. Lately I'm dealing with circular domain and I met the same problem which has been solved by Alessia, the upstairs. But I did not know how to do the transformation as my sensor is in cartesian coordinate system. Can you give me some advice? Thank you!

08 Jul 2015 Alessia

### Alessia (view profile)

Hi, I just realized that I was wrong: your function can be used anyway even if my domain is circular.
I just need first to transform everything in polar coordinates and then still using your function.
Thanks a lot for that!

Comment only
04 Jul 2015 Alessia

### Alessia (view profile)

I personally find your function really great! It is useful, clean and simple to understand also for me that I'm not fully familiar in developing numerical methods.
I used it for free surface reconstruction from gradient map (see Moisy publication in EIF in which you are cited!)
Lately I'm dealing with circular domain and I'm wondering if at your knowledge someone (or you) implemented already the integration in cylindrical coordinates!
Indeed I have meaning data only in a circular region while around it is masked(being meaningless... Can be whatever value for me...), which means that the border of the circular region are affected by meaningless data around due to the integration scheme.
In your opinion, is it challenging to try to implement this integration in cylindrical coordinates or it exists a simpler solution?
Thanks and Regards!

04 Jul 2015 John D'Errico

### John D'Errico (view profile)

I'm sorry, but It cannot handle NaNs, nor will I make it do so. You should fill them in FIRST using an interpolation scheme, and THEN use these tools.

Since there are multiple ways to fill in NaN elements in arrays, I see no reason to add that feature to an existing clean code, thus making it considerably more complex. Certainly if I chose one method to do the fill-in, then you would probably complain that I did not give you the way you preferred to see done. And if I offered every possible way I knew to fill in the NaN elements (I can quickly think of at least three methods) then the interface will get too complex.

The code does exactly what it is designed to do, and it does that very well. If you don't like it because it does not solve problems it was never designed to handle, then feel free not to use it, or feel free to write your own code, if you think you can do the job better.

Comment only
03 Jul 2015 HiFolks

### HiFolks (view profile)

Of Course, the integrated surface will have NaN points on the same places as the gradient since there's no gradient information there.

And the case of leading and forward edges fully equal to NaN for both x and y should also be considered.

03 Jul 2015 HiFolks

### HiFolks (view profile)

Hi, your file is great, but here is something to make it perfect : managing NaN's in the gradient arrays' !

Especially for intgrad2 : I would like to generate a surface from a 2-arrays gradient where some point are set to NaN (same points in both arrays). I Imagine the function should then only solve the Least Square Problem on non-NaN points ?

Is it possible to have an update ? I wasn't able to make intgrad2 solve correctly the Least Square Problem skipping NaN's without generating big deviations on the rest of the surface. I would be glad to have some help ! I would put five stars for that :)

Thanks

04 Mar 2015 hamideh F

### hamideh F (view profile)

1

Comment only
15 May 2013 Martyn

### Martyn (view profile)

There is a bug in intgrad3 where the parameter checks in lines 84 to 96 check nargin against values that are -1 of the correct value, ie on line 84 (nargin<3) should be (nargin<4), etc.

Comment only
01 Jan 2013 garima

### garima (view profile)

I have tried your tool but it perhaps fails in case of functions with singularities..like (x+iy)...plz chek and update...

17 Mar 2007 Uland Wong
07 Jul 2006 F Moisy

Thank you for this excellent tool. Should be included in Matlab.

27 Jan 2006 John D'Errico

Sergei,
I caught the bug in the example usage for the release I submitted this morning. Good point too about author and creation dates. I'll add them to all my files. Thanks, John

Comment only
27 Jan 2006 Sergei Koptenko

Rating =1 must be substantiated according to the ?Guidelines for Reviewing a Submission?- (provide specific information on what you like and dislike about the submission, use examples to illustrate your point... etc..). I would suggest to File Review Team to remove all ratings=1 that do not have specific critique as irrelevant and misleading.

Now, the specific critique :-)
1) help files are good, however they lack information about author and creation date.