Jump to content

About digital number, linear stretching and vegetation indices


emani

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.

Disable-Adblock.png

 

If you enjoy our contents, support us by Disable ads Blocker or add GIS-area to your ads blocker whitelist