inverse gradient [message #63980] |
Wed, 26 November 2008 02:10  |
erano
Messages: 22 Registered: November 2008
|
Junior Member |
|
|
Hello all,
I'm looking for a IDL function doing inverse gradient for 2D array.
inputs should be :
2D array gradient for X
2D array gradient for Y
output: the inverse gradient array
Can anyone help me?
Eran
|
|
|
|
|
|
|
Re: inverse gradient [message #64030 is a reply to message #63980] |
Tue, 02 December 2008 07:45   |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
erano wrote:
> On Dec 2, 4:45�pm, Paolo <pgri...@gmail.com> wrote:
>> erano wrote:
>>
>>>> Oddly enough, that's the second time sparse arrays have come up in one
>>>> week!
>>
>>>> You want LINBCG, which takes as input asparsematrix created using
>>>> SPRSIN. The help pages on them are pretty decent - give them a read.
>>
>>>> -Jeremy.
>>
>>> YES, we are at the right direction.
>>> BUT my matrix iz M*N (where M=2*N). when I add zeros to make it M*M,
>>> and thrn use the SPRSIN to make it sparse, the solution from LINBCG is
>>> noot good.
>>
>> How much is M and N?
>>
>> Paolo
>>
>>
>
> For the large array: N is between 10,000 to 800,000 and M=N*2.
> (actually, N is dim_x * dim_y of an image)
My suggestion is to operate on each line of the array
separately and loop over lines and columns.
This way you only need to deal with dim_x by dim_y
arrays, a much simpler problem...
Ciao,
Paolo
>
> Thanks again
>
> Eran
|
|
|
Re: inverse gradient [message #64031 is a reply to message #63980] |
Tue, 02 December 2008 07:12   |
erano
Messages: 22 Registered: November 2008
|
Junior Member |
|
|
On Dec 2, 4:45 pm, Paolo <pgri...@gmail.com> wrote:
> erano wrote:
>
>>> Oddly enough, that's the second time sparse arrays have come up in one
>>> week!
>
>>> You want LINBCG, which takes as input asparsematrix created using
>>> SPRSIN. The help pages on them are pretty decent - give them a read.
>
>>> -Jeremy.
>
>> YES, we are at the right direction.
>> BUT my matrix iz M*N (where M=2*N). when I add zeros to make it M*M,
>> and thrn use the SPRSIN to make it sparse, the solution from LINBCG is
>> noot good.
>
> How much is M and N?
>
> Paolo
>
>
For the large array: N is between 10,000 to 800,000 and M=N*2.
(actually, N is dim_x * dim_y of an image)
Thanks again
Eran
|
|
|
|
|
Re: inverse gradient [message #64059 is a reply to message #63980] |
Fri, 28 November 2008 08:31   |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
Jeremy Bailin wrote:
> On Nov 27, 3:27�am, erano <eran.o...@gmail.com> wrote:
>>> "inverse" meaning what for a vector-field?
>>
>>> Paolo
>>
>> "inverse" is the opposite operation for gradient.
>> The inputs are 2D gradient images (dX and dY), where high values are
>> large changes in the "inverse gradient" image, and zeros are stable
>> (no changes) in the "inverse gradient".
>>
>> Eran
>
> I would never use this in production code, but here's a hack that will
> give you something to look at:
>
> scalarfield = total(dX, /cumulative, 1) + total(dY, /cumulative, 2)
From the standpoint of discrete operations, that's perfectly fine.
As an approximation for the real potential, that depends on
how the gradient was measured I gues...
Paolo
>
> The real solution is to replace those totals with actual integrals.
>
> -Jeremy.
|
|
|
|
Re: inverse gradient [message #64061 is a reply to message #63980] |
Fri, 28 November 2008 08:14   |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
If the original poster has a gradient image A and wants to compute
the image B whose gradient is A, then it seems odd to me that a
sparse approach would work.
Ciao,
Paolo
Jeremy Bailin wrote:
> On Nov 28, 4:31�am, erano <eran.o...@gmail.com> wrote:
>> On Nov 27, 5:24�pm, Jeremy Bailin <astroco...@gmail.com> wrote:
>>
>>
>>
>>> On Nov 27, 3:27�am, erano <eran.o...@gmail.com> wrote:
>>
>>>> > "inverse" meaning what for a vector-field?
>>
>>>> > Paolo
>>
>>>> "inverse" is the opposite operation for gradient.
>>>> The inputs are 2D gradient images (dX and dY), where high values are
>>>> large changes in the "inverse gradient" image, and zeros are stable
>>>> (no changes) in the "inverse gradient".
>>
>>>> Eran
>>
>>> I would never use this in production code, but here's a hack that will
>>> give you something to look at:
>>
>>> scalarfield = total(dX, /cumulative, 1) + total(dY, /cumulative, 2)
>>
>>> The real solution is to replace those totals with actual integrals.
>>
>>> -Jeremy.
>>
>> Thanks,
>>
>> It's the simplest way. it's basicly works but with errors.
>> I found few articlies about "inverse gradient" on the web, and the
>> problem is very complex and the simple MATLAB function (from matlab
>> exchange) is expensive (memory).
>> The main problem is to solve A*F=V where A is M*N matrix, V is vector
>> and we look for F.
>> I used �LA_LEAST_SQUARES (with all possible methods) for solve this
>> but it is slow and have memory problem. please note that most of A
>> matrix are zeros...
>>
>> Any ideas?
>
> Oddly enough, that's the second time sparse arrays have come up in one
> week!
>
> You want LINBCG, which takes as input a sparse matrix created using
> SPRSIN. The help pages on them are pretty decent - give them a read.
>
> -Jeremy.
|
|
|
Re: inverse gradient [message #64063 is a reply to message #63980] |
Fri, 28 November 2008 08:10   |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
erano wrote:
> On Nov 27, 5:24�pm, Jeremy Bailin <astroco...@gmail.com> wrote:
>> On Nov 27, 3:27�am, erano <eran.o...@gmail.com> wrote:
>>
>>>> "inverse" meaning what for a vector-field?
>>
>>>> Paolo
>>
>>> "inverse" is the opposite operation for gradient.
>>> The inputs are 2D gradient images (dX and dY), where high values are
>>> large changes in the "inverse gradient" image, and zeros are stable
>>> (no changes) in the "inverse gradient".
>>
>>> Eran
>>
>> I would never use this in production code, but here's a hack that will
>> give you something to look at:
>>
>> scalarfield = total(dX, /cumulative, 1) + total(dY, /cumulative, 2)
>>
>> The real solution is to replace those totals with actual integrals.
>>
>> -Jeremy.
>
>
> Thanks,
>
> It's the simplest way. it's basicly works but with errors.
> I found few articlies about "inverse gradient" on the web, and the
> problem is very complex and the simple MATLAB function (from matlab
> exchange) is expensive (memory).
> The main problem is to solve A*F=V where A is M*N matrix, V is vector
> and we look for F.
While that is true in general, the gradient operatiom (which is a
linear
and therefore can be represented as a matrix operation) is a matrix
that
consist only of diagonal and one-row above diagonal elements.
Therefore, there is no need to solve the full matrix equation, but one
can
use simpler methods (i.e. in IDL trisol).
Paolo
> I used LA_LEAST_SQUARES (with all possible methods) for solve this
> but it is slow and have memory problem. please note that most of A
> matrix are zeros...
>
> Any ideas?
|
|
|
Re: inverse gradient [message #64065 is a reply to message #63980] |
Fri, 28 November 2008 05:27   |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Nov 28, 4:31 am, erano <eran.o...@gmail.com> wrote:
> On Nov 27, 5:24 pm, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>
>
>> On Nov 27, 3:27 am, erano <eran.o...@gmail.com> wrote:
>
>>>> "inverse" meaning what for a vector-field?
>
>>>> Paolo
>
>>> "inverse" is the opposite operation for gradient.
>>> The inputs are 2D gradient images (dX and dY), where high values are
>>> large changes in the "inverse gradient" image, and zeros are stable
>>> (no changes) in the "inverse gradient".
>
>>> Eran
>
>> I would never use this in production code, but here's a hack that will
>> give you something to look at:
>
>> scalarfield = total(dX, /cumulative, 1) + total(dY, /cumulative, 2)
>
>> The real solution is to replace those totals with actual integrals.
>
>> -Jeremy.
>
> Thanks,
>
> It's the simplest way. it's basicly works but with errors.
> I found few articlies about "inverse gradient" on the web, and the
> problem is very complex and the simple MATLAB function (from matlab
> exchange) is expensive (memory).
> The main problem is to solve A*F=V where A is M*N matrix, V is vector
> and we look for F.
> I used LA_LEAST_SQUARES (with all possible methods) for solve this
> but it is slow and have memory problem. please note that most of A
> matrix are zeros...
>
> Any ideas?
Oddly enough, that's the second time sparse arrays have come up in one
week!
You want LINBCG, which takes as input a sparse matrix created using
SPRSIN. The help pages on them are pretty decent - give them a read.
-Jeremy.
|
|
|
Re: inverse gradient [message #64067 is a reply to message #63980] |
Fri, 28 November 2008 01:31   |
erano
Messages: 22 Registered: November 2008
|
Junior Member |
|
|
On Nov 27, 5:24 pm, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Nov 27, 3:27 am, erano <eran.o...@gmail.com> wrote:
>
>>> "inverse" meaning what for a vector-field?
>
>>> Paolo
>
>> "inverse" is the opposite operation for gradient.
>> The inputs are 2D gradient images (dX and dY), where high values are
>> large changes in the "inverse gradient" image, and zeros are stable
>> (no changes) in the "inverse gradient".
>
>> Eran
>
> I would never use this in production code, but here's a hack that will
> give you something to look at:
>
> scalarfield = total(dX, /cumulative, 1) + total(dY, /cumulative, 2)
>
> The real solution is to replace those totals with actual integrals.
>
> -Jeremy.
Thanks,
It's the simplest way. it's basicly works but with errors.
I found few articlies about "inverse gradient" on the web, and the
problem is very complex and the simple MATLAB function (from matlab
exchange) is expensive (memory).
The main problem is to solve A*F=V where A is M*N matrix, V is vector
and we look for F.
I used LA_LEAST_SQUARES (with all possible methods) for solve this
but it is slow and have memory problem. please note that most of A
matrix are zeros...
Any ideas?
|
|
|
Re: inverse gradient [message #64085 is a reply to message #63980] |
Thu, 27 November 2008 06:24   |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Nov 27, 3:27 am, erano <eran.o...@gmail.com> wrote:
>> "inverse" meaning what for a vector-field?
>
>> Paolo
>
> "inverse" is the opposite operation for gradient.
> The inputs are 2D gradient images (dX and dY), where high values are
> large changes in the "inverse gradient" image, and zeros are stable
> (no changes) in the "inverse gradient".
>
> Eran
I would never use this in production code, but here's a hack that will
give you something to look at:
scalarfield = total(dX, /cumulative, 1) + total(dY, /cumulative, 2)
The real solution is to replace those totals with actual integrals.
-Jeremy.
|
|
|
Re: inverse gradient [message #64167 is a reply to message #63980] |
Tue, 02 December 2008 14:44   |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
On Dec 2, 2:42 pm, erano <eran.o...@gmail.com> wrote:
> On Dec 2, 8:59 pm, Paolo <pgri...@gmail.com> wrote:
>
>
>
>> erano wrote:
>
>>>> But you haven't really described how you got dX and dY and
>>>> what is the potential....
>
>>> Well, dX and dY are based on other parameters gradient. I based on
>>> MATLAB code. In MATLAB, we can use "\" for doing Ax=Y: x=A\Y, where A
>>> is M*N matrix. I can attach the code.
>
>> My question was what are dX and dY? What is the potential?
>
>> In IDL you can do x=A#invert(Y) that I guess is similar
>> to what matlab does (modulo transposition of the arrays).
>
>> But if A is large and sparse, then use the sparse methods suggested.
>
>> Paolo
>
>>> Eran- Hide quoted text -
>
>> - Show quoted text -
>
> The potential ia not relevant. The dX and dY can be based on any 2D
> function.
I am still not convinced that total wouldn't work in that case...
maybe increasing the sampling by a factor 2 or 3 if memory allows...
again it depends what your final goal is, of which we haven't a clue.
> And yes, A is (very) large and sparse, but the sparse
> methods are only for N*N matrix...while A is M*N.
OK, you are totally right that IDL sparse-array
function are somewhat... sparse ;-)
I think you can buy an add-on for this kind of things,
but I never used it.
Maybe somebody out there has written an SVD program that
accept non-square, sparse arrays?
Ciao,
Paolo
>
> Eran
|
|
|
|
|
Re: inverse gradient [message #64455 is a reply to message #64183] |
Wed, 24 December 2008 01:55  |
erano
Messages: 22 Registered: November 2008
|
Junior Member |
|
|
On Dec 9, 10:36 am, erano <eran.o...@gmail.com> wrote:
> Just a short update :
> (I talked with IDL - ITT Technical Support)
> For solve A*x=b
> When I A is M*N array and i wish to make it sparse I must to add zeros
> to make it M*M (if M>N).
> If I wish to use LINBCG I must to have not zero values at diagonal.
> for all the new elements the diag shoult be set to 1.0, and I must to
> sort the old array rows (and the vector b as well) so the diag is
> full. It's working.
UPDATE: working only for small array, and not need to set to 1.0 the
diag
|
|
|