emani Posted May 11, 2014 Report Share Posted May 11, 2014 (edited) Does the value of digital number change after linear stretching? And is it fine to obtain vegetation indices from linerly stretched images? Thanks Emani Edited May 12, 2014 by emani Quote Link to comment Share on other sites More sharing options...
30000 Posted May 12, 2014 Report Share Posted May 12, 2014 Histogram stretching does not change the DNs of an image, merely how the image is displayed. Vegetation indices will be calculated from the DN values of the bands themselves, not how it is displayed, so it is fine to use NDVI or any other vegetation index while using linear stretching. You can confirm this for yourself by inquiring a certain pixel, then changing the histogram to various stretches. The file pixel values for each band will stay the same, while the look up table values will changed based on the stretching. Quote Link to comment Share on other sites More sharing options...
emani Posted May 13, 2014 Author Report Share Posted May 13, 2014 Histogram stretching does not change the DNs of an image, merely how the image is displayed. Vegetation indices will be calculated from the DN values of the bands themselves, not how it is displayed, so it is fine to use NDVI or any other vegetation index while using linear stretching. You can confirm this for yourself by inquiring a certain pixel, then changing the histogram to various stretches. The file pixel values for each band will stay the same, while the look up table values will changed based on the stretching. Hi, Thanks for the reply....I actually stretched the image in R using this code which was given to me by my friend and now I see that my DN values have changed as I checked them on ERDAS. As digital number should be an Integer but all the values I got after running this code were fractions. I am posting the code which I used below. rm(list=ls(all=TRUE)) require(rgdal) require(rgl) require(maptools) StartPath <- getwd() #Defining the root directory Root <- "E:/Programming/Emani" Path_in <- paste(Root, "/Input",sep="") Path_out <- paste(Root, "/Output",sep="") dir.create(Path_out,showWarnings=FALSE, recursive=TRUE) hist.strecth <- function(x) { n <- dim(x)[2] for(k in 1:n) { data <- x[,k] cur.lim <- quantile(data,c(0.025,0.975),na.rm=TRUE) data <- pmax(cur.lim[1],pmin(cur.lim[2],data)) data <- floor(255*(data-cur.lim[1])/(cur.lim[2]-cur.lim[1])) data[is.na(data)]<-0 x[,k] <- data } return(x) } #====================================================================================== # Read image #====================================================================================== image.fn <- "LAUW_20130327" A <- readGDAL(paste(Path_in,"/",image.fn,".tif",sep="")) Nb <- dim(A@data)[2] #summary(A@data) # Read vector file, for subsetting vector.fn <- "extent" V <- readOGR(paste(Path_in,"/",vector.fn, sep=""), layer=vector.fn) i<-1 j<-1 polxy <- coordinates(V@polygons[[i]]@Polygons[[j]]) xy <- coordinates(A) tmp <- point.in.polygon(xy[,1],xy[,2],polxy[,1],polxy[,2]) ind <- which(tmp==1) indout<- which(tmp!=1) minDN <- array(0,Nb) maxDN <- array(0,Nb) for(k in 1:Nb) { x <- A@data[ind,] minDN[k] <- min(x[,k]) data <- x[,k] maxDN[k] <- quantile(data,0.99,na.rm=TRUE) } Acalibrated <- A for(k in 1:Nb) { x <- A@data[ind,k] x <- x-minDN[k] x <- x*255/(maxDN[k]-minDN[k]) x[x<0] <- 0 x[x>255]<-255 Acalibrated@data[ind,k] <- x } Acalibrated@data[indout,] <- 0 hist(Acalibrated@data$band4) # output MRF solution to a .tif file OUT <- Acalibrated setwd(Path_out) imagefn.out <- paste(image.fn,"_calibrated.tif",sep="") OUT.tif<-create2GDAL(OUT,drivername="GTiff",type="Float32",mvFlag=-1) saveDataset(OUT.tif,imagefn.out) GDAL.close(OUT.tif) setwd(StartPath) # The End thanks emani Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.