Dear all, I have been trying to speed up a process we have been done in ArcGIS. We have to read a single layer TIFF (monochrome image) in . For this, I have used the "rtiff" package. After reading the TIFF file, I compared the raw values for each pixel that I have in ArcGIS to the ones obtained in R. In ArcGIS I have discrete values in the range 0..255, while in R I have continuous values between 0..1. This, in itself might not be a problem if the values obtained in R, times 255 would show the values obtained in ArcGIS, but this is not the case. The images are very different. I tried to settle matters using Photoshop, and the values there are completely different from the other two (using RGB, the K value (in CMYK) or the B value (in HSB))!!! Can somebody help me with this problem? Can I trust "rtiff"? Should I stick to a very slow process in ArcGIS? Why PS, which should be the perfect measuring stick, is showing another set of values? Thanks in advance. Regards. Julio
Unless you can provide a small reproducible example (say a very small tiff including the values you got from the non-R software) 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 process we have been done in ArcGIS. We have to read a single layer TIFF (monochrome image) in . For this, I have used the "rtiff" package. After reading the TIFF file, I compared the raw values for each pixel that I have in ArcGIS to the ones obtained in R. In ArcGIS I have discrete values in the range 0..255, while in R I have continuous values between 0..1. This, in itself might not be a problem if the values obtained in R, times 255 would show the values obtained in ArcGIS, but this is not the case. The images are very different. I tried to settle matters using Photoshop, and the values there are completely different from the other two (using RGB, the K value (in CMYK) or the B value (in HSB))!!! > > Can somebody help me with this problem? Can I trust "rtiff"? Should I stick to a very slow process in ArcGIS? Why PS, which should be the perfect measuring stick, is showing another set of values? > > Thanks in advance. Regards. > > Julio > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
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> escribi?:> 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 software) > 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 process we > have been done in ArcGIS. We have to read a single layer > TIFF (monochrome image) in . For this, I have used the > "rtiff" package. After reading the TIFF file, I compared the > raw values for each pixel that I have in ArcGIS to the ones > obtained in R. In ArcGIS I have discrete values in the range > 0..255, while in R I have continuous values between 0..1. > This, in itself might not be a problem if the values > obtained in R, times 255 would show the values obtained in > ArcGIS, but this is not the case. The images are very > different. I tried to settle matters using Photoshop, and > the values there are completely different from the other two > (using RGB, the K value (in CMYK) or the B value (in > HSB))!!! > > > > Can somebody help me with this problem? Can I trust > "rtiff"? Should I stick to a very slow process in ArcGIS? > Why PS, which should be the perfect measuring stick, is > showing another set of values? > > > > Thanks in advance. Regards. > > > > Julio > > > > ______________________________________________ > > R-help at r-project.org > mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, > reproducible code. >
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> escribi?: > >> 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 software) >> 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 process we >> have been done in ArcGIS. We have to read a single layer >> TIFF (monochrome image) in . For this, I have used the >> "rtiff" package. After reading the TIFF file, I compared the >> raw values for each pixel that I have in ArcGIS to the ones >> obtained in R. In ArcGIS I have discrete values in the range >> 0..255, while in R I have continuous values between 0..1. >> This, in itself might not be a problem if the values >> obtained in R, times 255 would show the values obtained in >> ArcGIS, but this is not the case. The images are very >> different. I tried to settle matters using Photoshop, and >> the values there are completely different from the other two >> (using RGB, the K value (in CMYK) or the B value (in >> HSB))!!! >>> >>> Can somebody help me with this problem? Can I trust >> "rtiff"? Should I stick to a very slow process in ArcGIS? >> Why PS, which should be the perfect measuring stick, is >> showing another set of values? >>> >>> Thanks in advance. Regards. >>> >>> Julio >>> >>> ______________________________________________ >>> R-help at r-project.org >> mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, >> reproducible code. >>