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

Home » Public Forums » archive » Why Index array containing same index multiple time results only one arithmetic operation
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
Why Index array containing same index multiple time results only one arithmetic operation [message #71298] Tue, 08 June 2010 21:52
AKJ is currently offline  AKJ
Messages: 1
Registered: June 2010
Junior Member
Hi,
I am trying to compute texture of an image with following code

img=[[0,0,1,1],[0,0,1,1],[0,2,2,2],[2,2,3,3L]]
texture_map=LONARR(4,4)
dim=size(img, /DIMENSION)
for i=0,dim[0]-1-1 do begin
tex_idx_c=img[i,*]
tex_idx_r=im[i+1,*]
texture_map[tex_idx_c,tex_idx_r]+=1
endfor
print,img
print,texture_map

Output
Img=
0 0 1 1
0 0 1 1
0 2 2 2
2 2 3 3
texture_map=
1 0 0 0
1 1 0 0
1 0 3 0
0 0 1 1

Here texture_map[tex_idx_c,tex_idx_r]+=1 is incrementing only once for
the first iteration even though pair(0,0)
occurs twice. Same is the case with pair(0,1) in second iteration and
(1,1) in third iteration. It there a way to force the idx to increment
twice if the pair(idc,idr) occurs more than 1 in each iteration.

So Actual output is


img=
0 0 1 1
0 0 1 1
0 2 2 2
2 2 3 3
texture=
2 0 0 0
2 2 0 0
1 0 3 0
0 0 1 1

This can be achieved by the following code.
pro compute_texture,
img=[[0,0,1,1],[0,0,1,1],[0,2,2,2],[2,2,3,3]]
texture_map=LONARR(4,4)
dim=size(img, /DIMENSION)
for i=0,dim[0]-1-1 do begin
for j=0,dim[1]-1 do begin
tex_idx_c=img[i,j]
tex_idx_r=img[i+1,j]
texture_map[tex_idx_c,tex_idx_r]+=1
endfor
endfor
print, img
print, texture_map

Thanks
AKJ
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Simple hack to get $1000 to your home.
Next Topic: Re: Why Index array containing same index multiple time results only one arithmetic operation

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

Current Time: Wed Oct 08 15:12:02 PDT 2025

Total time taken to generate the page: 0.00498 seconds