Re: Manipulation using where [message #53099] |
Wed, 21 March 2007 08:52  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Vidhya writes:
> But the problem, I have the row which have an alternate values of zero
> and some integers.
>
> 0 25695 0 25966 0
> 27235 0 37145 0 94282
> 0........... something like this!
>
> So couldnt find with total of all the column elements.
>
> So I tried to specify as to where there are zero.
>
> Any suggestions?
Well, perhaps then it is all the row values in a particular
*column* that are zero. In that case, you would total
over the second dimension, rather than the first. The
principle is exactly the same.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Manipulation using where [message #53100 is a reply to message #53099] |
Wed, 21 March 2007 07:41   |
Vidhya
Messages: 6 Registered: October 2006
|
Junior Member |
|
|
Hi David,
But the problem, I have the row which have an alternate values of zero
and some integers.
0 25695 0 25966 0
27235 0 37145 0 94282
0........... something like this!
So couldnt find with total of all the column elements.
So I tried to specify as to where there are zero.
Any suggestions?
On 21 Mar, 15:19, David Fanning <n...@dfanning.com> wrote:
> Vidhya writes:
>> I have an image, SUBIMAGE LONG = Array[372, 374, 62] and I
>> would like to find all the values equal to zero (basically missing
>> lines/rows). Right, done using
>
>> z = where(subimage(*,*,*) EQ 0, count)
>
>> The result is one-dimensional array: LONG = Array[15457]
>
>> now I would like perform an operation trying to find which row there
>> are in, and find the averages of the rows above and below and
>> replacing them for those found zero values.
>
>> How do I go about this?
>
>> I tried using array_indices, but its bit confusing.
>
> I think you are going about this in the wrong way.
> If a row is missing, all the column values in that
> row are zero. Thus, if you totaled your array over
> the column dimension, you would find the locations
> where all the columns values were zero, since these
> would be zero.
>
> Consider a simple example.
>
> a = Indgen(4, 5, 3)
> a[*,2,1] = 0
> Print, a
> 0 1 2 3
> 4 5 6 7
> 8 9 10 11
> 12 13 14 15
> 16 17 18 19
>
> 20 21 22 23
> 24 25 26 27
> 0 0 0 0
> 32 33 34 35
> 36 37 38 39
>
> 40 41 42 43
> 44 45 46 47
> 48 49 50 51
> 52 53 54 55
> 56 57 58 59
>
> t = Total(a, 1) ; Total over columns
> Print, t
> 6.00000 22.0000 38.0000 54.0000 70.0000
> 86.0000 102.000 0.000000 134.000 150.000
> 166.000 182.000 198.000 214.000 230.000
>
> index = Where(t EQ 0)
> rowframe = Array_Indices(Size(t,/Dim), index, /Dim)
> row = rowframe[0] & frame = rowframe[1]
> Print, row, frame
> 2 1
>
> So, you know that all the column values in row 2, frame 1
> are zero. Now you can do whatever you like with that
> information. :-)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Manipulation using where [message #53101 is a reply to message #53100] |
Wed, 21 March 2007 08:19   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Vidhya writes:
> I have an image, SUBIMAGE LONG = Array[372, 374, 62] and I
> would like to find all the values equal to zero (basically missing
> lines/rows). Right, done using
>
>
> z = where(subimage(*,*,*) EQ 0, count)
>
> The result is one-dimensional array: LONG = Array[15457]
>
> now I would like perform an operation trying to find which row there
> are in, and find the averages of the rows above and below and
> replacing them for those found zero values.
>
> How do I go about this?
>
> I tried using array_indices, but its bit confusing.
I think you are going about this in the wrong way.
If a row is missing, all the column values in that
row are zero. Thus, if you totaled your array over
the column dimension, you would find the locations
where all the columns values were zero, since these
would be zero.
Consider a simple example.
a = Indgen(4, 5, 3)
a[*,2,1] = 0
Print, a
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
20 21 22 23
24 25 26 27
0 0 0 0
32 33 34 35
36 37 38 39
40 41 42 43
44 45 46 47
48 49 50 51
52 53 54 55
56 57 58 59
t = Total(a, 1) ; Total over columns
Print, t
6.00000 22.0000 38.0000 54.0000 70.0000
86.0000 102.000 0.000000 134.000 150.000
166.000 182.000 198.000 214.000 230.000
index = Where(t EQ 0)
rowframe = Array_Indices(Size(t,/Dim), index, /Dim)
row = rowframe[0] & frame = rowframe[1]
Print, row, frame
2 1
So, you know that all the column values in row 2, frame 1
are zero. Now you can do whatever you like with that
information. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Manipulation using where [message #53102 is a reply to message #53100] |
Wed, 21 March 2007 07:16   |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Mar 21, 8:25 am, "Vidhya" <vidh...@gmail.com> wrote:
> Hi all,
>
> I have an image, SUBIMAGE LONG = Array[372, 374, 62] and I
> would like to find all the values equal to zero (basically missing
> lines/rows). Right, done using
>
> z = where(subimage(*,*,*) EQ 0, count)
>
> The result is one-dimensional array: LONG = Array[15457]
>
> now I would like perform an operation trying to find which row there
> are in, and find the averages of the rows above and below and
> replacing them for those found zero values.
>
> How do I go about this?
>
> I tried using array_indices, but its bit confusing.
> Your help is appreciated.
>
> Thanks,
> Vidhya
z_x = z mod 372
z_y = z/372 mod 374
z_z = z/372/374 mod 62
Cheers
|
|
|
Re: Manipulation using where [message #53188 is a reply to message #53099] |
Thu, 22 March 2007 01:26  |
wxf
Messages: 6 Registered: March 2007
|
Junior Member |
|
|
Somebody above use "mod-method".That is correct.
I often use "array_indices" function to change the result of "where"
into two dimensional coordinates.It's ok,but I never tried 3-D case.
IDL> dat=dist(400,300) ; a data array
IDL> index=where (dat eq 100)
IDL> ind = array_indices(dat,index)
IDL> xarray=ind(0,*) ; get X
IDL> yarray=ind(1,*) ; get Y
IDL> tvscl, dat ; show image
IDL> plots, xarray, yarray, psym=2, color=150,/dev ;over plot the
points
If you want to change (x,y) into one dimensional coordinate('where()'-
result),you can use this formula.
;your image size-(m,n),any coordinates(x,y)
;position=mL*long(round(y))+long(round(x))
You see,it is not difficult.3-D's case and formula can be available
just do the same thing.
Good luck
wxf
|
|
|