Re: Faster than looping? [message #16973] |
Thu, 26 August 1999 00:00 |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
Richard Tyc wrote:
> Is there a faster way of doing the following for-loop code (it basically
> looks for yellow in an RGB image and turns it white with intensity 254 .
>
> img = bytarr(3,512,512)
>
> for j=0,511 do begin
> for k=0,511 do begin
> if (img[0,j,k] eq 255 and img[1,j,k] eq 255 and img[2,j,k] eq 0)
> then begin
> img[0,j,k] = 254
> img[1,j,k] = 254
> img[2,j,k] = 254
> endif
> endfor
> endfor
c0 = img[0, *, *]
c1 = img[1, *, *]
c2 = img[2, *, *]
index = where(c0 eq 255 and c1 eq 255 and c2 eq 0, count)
if count gt 0 then begin
c0[index] = 254
c1[index] = 254
c2[index] = 254
img[0, *, *] = temporary(c0)
img[1, *, *] = temporary(c1)
img[2, *, *] = temporary(c2)
endif
Cheers,
Liam.
--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
|
|
|