De: Uwe Ligges <ligges at statistik.tu-dortmund.de>
Asunto: Re: [R] Reading a TIFF file
A: "Julio Rojas" <jcredberry at ymail.com>
Cc: r-help at r-project.org
Fecha: viernes, 22 de abril de 2011, 03:54 pm
Fine, looking at the code shows that
readTiff read the image with using libtiff which should be
fine. Afterwards, a pixmap obnject is generated via?
pixmapRGB() which includes the following lines:
? ? datamax <- max(data)
? ? datamin <- min(data)
? ? data <- as.numeric(data)
? ? if (datamax > 1 || datamin < 0)
? ? ? ? data <- (data -
datamin)/(datamax - datamin)
That means the data is perfectly fitted into the [0,1]
interval.
That means we have not only rescaled but also another 0
now.
What I did is:
pic <- readTiff("test1_layer1.tif")
pic <- pic at red
ARC <- read.csv2("test1_arcgis.csv", header=TRUE)
ARC <- matrix(ARC[,2], nrow=nrow(pic), byrow=TRUE)
plot(pic)
plot(ARC)# looks *very* similar
plot(as.vector(pic) ~ as.vector(ARC))
# all on one line
summary(lm(as.vector(pic) ~ as.vector(ARC)))
# resuiduals < 10^(-14)
So the formula use to get from the ARC to the pixmap data
is
pixmapdata = -0.82278 * 0.01266 ARCdata
if you want to get the original data, you can adapt the
readTiff function for your own use for greyscales (and save
memory that way) as in:
myReadTiff <- function (fn, page = 0)
{
? w <- .C("TiffGetWidth", as.character(fn), w =
as.integer(0),
? ? PACKAGE = "rtiff")$w
? h <- .C("TiffGetHeight", as.character(fn), h =
as.integer(0),
? ? PACKAGE = "rtiff")$h
? nw <- ceiling((1 - reduce) * w)
? nh <- ceiling((1 - reduce) * h)
? if (w > 0 && h > 0) {
? ? tiff <- .C("TiffReadTIFFRGBA",
as.character(fn),
? ? ? page = as.integer(page),
? ? ? r = integer(w * h), g = integer(w *
h), b = integer(w * h),
? ? ? PACKAGE = "rtiff")
? ? tiff <- tiff$r / 255
? ? tiff <- pixmapGrey(data = tiff, nrow = nh,
ncol = nw)
? ? return(tiff)
? }
? stop("Could not open", fn, ".? File corrupted
or missing.\n")
}
pic2 <- myReadTiff("test1_layer1.tif")
Now pic2 at grey will be exactly the same as ARC/255 from
above.
Uwe Ligges
On 22.04.2011 15:10, Julio Rojas wrote:
Dear Uwe, find attached an small portion of the file
I'm working with. ArcGIS values for this file are in the CSV
file. They are a vector of all rows put together.
Thanks and regards.
--- El vie, 4/22/11, Uwe Ligges<ligges at statistik.tu-dortmund.de>?
De: Uwe Ligges<ligges at statistik.tu-dortmund.de>
Asunto: Re: [R] Reading a TIFF file
A: "Julio Rojas"<jcredberry at ymail.com>
Cc: r-help at r-project.org
Fecha: viernes, 22 de abril de 2011, 12:37 pm
Unless you can provide a small
reproducible example (say a very small
tiff including the values you got from the non-R
it will be
hard to tell what is going on.
Uwe Ligges
On 22.04.2011 11:23, Julio Rojas wrote:
Dear all, I have been trying to speed up a
have been done in ArcGIS. We have to read a single
TIFF (monochrome image) in . For this, I have used
"rtiff" package. After reading the TIFF file, I
raw values for each pixel that I have in ArcGIS to
obtained in R. In ArcGIS I have discrete values in
0..255, while in R I have continuous values
This, in itself might not be a problem if the
obtained in R, times 255 would show the values
ArcGIS, but this is not the case. The images are
different. I tried to settle matters using
the values there are completely different from the
(using RGB, the K value (in CMYK) or the B value
Can somebody help me with this problem? Can I
"rtiff"? Should I stick to a very slow process in
Why PS, which should be the perfect measuring
showing another set of values?
Thanks in advance. Regards.
Julio