[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: findng array[3] in array[3,n]
> 3. Use a Euclidean distance to find the color table entry with the
> smallest distance from you target value [rtarg, gtarg, btarg]. You
> should convert R G and B to vectors of type LONG to prevent
> overflow:
>
> dist = (r-rtarg)^2 + (g-gtarg)^2 + (b-btarg)^2
> wh = where(dist EQ min(dist))
>
> This will be the most robust to small variations in the color table
> (ie, if an exact match doesn't exist).
Good Lord man! You're a genius!!!!
I'm learnig alot here. Your solution worked brilliantly for what I was
trying
to do. So... I went further and tried this.
Suppose I have an image that I got with tvrd(/true). This means it's a
[3,m,n]
image with the 1st dimension specifying r,g,b. Now, I wanna map this to an
IDLgrImage with transparency, so I wanna make it a [4,m,n] so' I can have me
and alpha channel. Say I want all black ([0,0,0]) to have an opacity of 0.
So I...
;say mapImage is [3,m,n] with lots of black background
sz = size(mapImage)
rgbaImage=bytarr(sz[1]+1,sz[2],sz[3]) ; make it [4,m,n]; r,g,b,alpha
rgbaImage[0:2,*,*] = mapImage
;start w/ all opaque (255)
rgbaImage[3,*,*] = 255
; this color will be transparent
xparentcolor = [000,000,000]
;get rgb channels, which are 2D
r = long(rgbaImage[0,*,*]) & g = long(rgbaImage[1,*,*]) & b =
long(rgbaImage[2,*,*])
;do Craig's magic
eucDist = (r-xparentcolor[0])^2 + (g-xparentcolor[1])^2 +
(b-xparentcolor[2])^2
colorIndex = where(eucDist EQ min(eucDist), count)
;set the alpha channel indices = 0 where theres black
rgbaImage[3,colorIndex] = 0
;now it's readt for my IDLgrImage
sState.oMapImage->setProperty, DATA=rgbaImage, HIDE=0
Problem is is that my black is still opaque. I still can't see my objects
behind it. Is it my misunderstanding of bringing this to 3D that's illing
me?
Looks like it should work.
Thanks to all who responded.
Oh, and yes David, I was gonna use your code if I couldn't find a way to
save a function call. Thanks.