reclass: Reclassify specific values of image

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

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

Usage

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

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.

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.

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.

Note

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).

Author(s)

Nikita Platonov platonov@sevin.ru

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)

ursa documentation built on May 23, 2021, 1:06 a.m.