[R-sig-Geo] generate alpha band and add it to multispectral image

Mayeul KAUFFMANN mayeul.kauffmann at jrc.ec.europa.eu
Thu May 5 10:11:16 CEST 2011


Hi,
I have a 3 bands (RGB) image and want to add to it an alpha band based
on the value of the other bands (the darker, the less transparent).
Input is: ENVI/ENVI .hdr Labelled.
QuantumGIS does not recognize the alpha band (alpha tag is not set).
When the alpha band is selected manually in Arcgis, the image gets
rendered with spaced hachures/zebra lines; trying to export/print the
map fails (it takes ages while using 5% op one core; I ultimately closed
the process).
Here is my R session:

origin<-brick("my_envi_3_bands_file")
class(origin)
str(origin)
nlayers(origin)
grey<-subset(origin,1)+subset(origin,2)+subset(origin,3)
projection(grey)<-projection(origin) #not sure it is usefull
alpha<-grey
#if gray level was between 200 and 255 , assign (linearly) an alpha
between 0 and 255
alpha[grey <200*3] <- 0 # *3 because we have 3 bands
alpha[grey >=200*3] <- round( ((grey[grey >=200*3]-200*3)*255/55) /3) 
origin_with_alpha<-brick(subset(origin,1),subset(origin,2),subset(origin,3), alpha)
writeRaster(x=origin_with_alpha, filename="output_with_alpha.tif",
format="GTiff")
#######
# I also tried the reverse (assign "255-alpha")
alpha[grey <200*3] <- 255 # *3 because we have 3 bands
alpha[grey >=200*3] <- 255-round( ((grey[grey
>=200*3]-200*3)*255/55) /3) 

The band is correctif in R; I have good results if I do this:
plot(alpha)
hist(alpha)
How can I produce an alpha band that will get correctly interpreted by
GIS software?
Thanks for any hint!
Mayeul


-- 
Dr. Mayeul KAUFFMANN, Conflict Specialist
European Commission, Joint Research Centre (JRC)
Institute for the Protection and Security of the Citizen (IPSC)
Global Security and Crisis Management - ISFEREA
Via E. Fermi 2749 - I-21027 Ispra (VA), ITALY
Phone: (+39) 033278 5071
http://isferea.jrc.ec.europa.eu/Staff/Pages/Kauffmann-Mayeul.aspx

(Office: building 26b, 1st floor, room 140. TP: 267)



More information about the R-sig-Geo mailing list