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

Home » Public Forums » archive » quickly reassign numbers in large array?
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
quickly reassign numbers in large array? [message #50102] Wed, 13 September 2006 16:41
vlk.astro is currently offline  vlk.astro
Messages: 11
Registered: March 2006
Junior Member
Hello,

I am faced with a need to speed up a program which takes parts of an
image and reassigns values to them. I have so far gotten away with a
for-loop. Here is an example to illustrate what I am trying to do:

; make up an image
img=shift(dist(512),255,255)
image = 10*(img lt 10) + 20*(img gt 20 and img lt 30) + 50*(img gt 50
and img lt 100)

; this image has these labels and this many distinct regions
labels = image[uniq(image,sort(image))] ; =[0,10,20,50]
nregions=n_elements(labels) ; =4

; now I want to make a new image with new labels
newimage=0*image
for i=0,nregions-1 do
idx=where(image eq label[i])
newimage[idx]=i ; now newimage will have labels [0,1,2,3]
endfor

There has to be a faster, if not cleverer, way to do this reassignment.
Those multiple where()'s and the for-loop are fine for readability,
but are a major drain on the cpu and user patience when you have large
images and thousands of segments.

Any ideas?

Thanks,
Vinay
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Java Bridge Question
Next Topic: Removing equal elements from an array

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

Current Time: Wed Oct 08 13:52:40 PDT 2025

Total time taken to generate the page: 0.00532 seconds