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
|