reclass | R Documentation |
This is look-up table reclassification: the destination value is found for each source value.
reclass(obj, dst = NULL, src = NULL, sparse = FALSE, ...)
obj |
Object of class |
dst |
Object of class |
src |
Numerical vector, but allowed using with numerical vector of |
sparse |
Logical. If image has a lot of |
... |
Other arguments are used for classification in the function |
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.
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.
There were no a lot of tests how GIS software reads "ENVI .hdr Labelled Raster" files with color tables without color values (only categories). At least, GDAL recognizes categories (gdalinfo
utility).
Nikita Platonov platonov@sevin.ru
The reclassification from interval source values to specific destination values is used in colorize
.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.