Learn R Programming

ursa (version 3.10.4)

reclass: Reclassify specific values of image

Description

This is look-up table reclassification: the destination value is found for each source value.

Usage

reclass(obj, dst = NULL, src = NULL, sparse = FALSE, ...)

Value

If obj is object of class ursaColorTable then numeric vector of categories' centers.

If dst is numeric, then object of class ursaRaster without color table.

If dst is ursaColorTable then object of class ursaRaster (NA values) in color table.

If dst is NULL then object of class ursaRaster with empty color names (NA values) in color table.

Arguments

obj

Object of class ursaRaster or ursaColorTable.

dst

Object of class ursaRaster, or object of class ursaColorTable, or numeric vector. If numeric, then the desired destination set of values, else reference object for reclassification; this object should have numerical values of categories.

src

Numerical vector, but allowed using with numerical vector of dst and length(src)==length(dst). Source set of values.

sparse

Logical. If image has a lot of NA values then sparse=TRUE may speed up transformation. Default is FALSE.

...

Other arguments are used for classification in the function colorize.

Author

Nikita Platonov platonov@sevin.ru

Details

If dst is numeric vector, then the source value have to be specific, without any ranges. It is required the equality lengths of src and dst. If image has color table then function tries reconstruct dst from names of categories.

This function can be used for data compression for storage, e.g. for distribution or interchange.

See Also

The reclassification from interval source values to specific destination values is used in colorize.

Examples

Run this code
session_grid(NULL)
# example no.1 manual classification
a <- as.ursa(round(matrix(runif(100,min=0.5,max=3.5),ncol=10)))
print(as.table(a))
b <- reclass(a,src=c(3,1,2),dst=round(runif(3),2))
print(as.table(b))
print(c(src=a,dst=b))

# example no.2 -- similarity to other object
session_grid(NULL)
a <- ursa_dummy(nband=2,min=-1,max=1)
print(a)
b1 <- colorize(a[1],value=seq(-1,1,length=21),pal.rich=240,pal.rotate=0)
b2 <- reclass(a[2],b1)
b3 <- reclass(a[2],ursa_colortable(b2))
b <- c(b1,b2,b3)
print(reclass(b))

# example no.3 -- compression with data lost
a <- pixelsize(NULL)
b <- reclass(a,byte=TRUE,tail=0) ## try 'byte=FALSE'
a2 <- reclass(b)
res <- c(source=a,as_category=a2,difference=a-a2)
print(res)
message(paste("RMS error: ",format(sqrt(band_sum(res[3]^2)/band_n(res[3])))))
prefix <- names(res)[1:2]
fname <- file.path(tempdir(),paste0(prefix,".envi"))
s <- data.frame(object.size=sapply(list(a,b),object.size))
rownames(s) <- prefix
print(s)
write_envi(a,fname[1])
write_envi(b,fname[2])
f <- file.info(dir(path=tempdir()
                  ,pattern=paste0("(",prefix,")\\.(envi|hdr)",sep="|")
                  ,full.names=TRUE))[,"size",drop=FALSE]
colnames(f) <- "file.size"
print(f)
envi_remove(fname)

Run the code above in your browser using DataLab