Hi All, I have a greyscale image that I am reading in through RGDAL and placing in a pixmap object. As an example use the logo.jpg file that comes with the RGDAL package: #Read the file logo <- system.file("pictures/logo.jpg", package="rgdal")[1] x <- new("GDALReadOnlyDataset", logo) #Create the pixmap object xGrey <- getPixmapGDAL(x) Now I would like to read individual pixel values and store them in a separate vector. However I have not found a straight-forward way to do this. I thought that something like: x <- xGrey[1,1] would return the pixel value, but it seems to return a pixmap object with dimension 1x1 (i.e. only one pixel in size) xGrey[1,1] Pixmap image Type : pixmapGrey Size : 1x1 Resolution : 1x1 Bounding box : 1 0 2 1 Any ideas on how to get the actual pixel value from a pixmap? (Note I could output to an ascii file and then read the file back in as text - but not nice!) Thanks in advance Tony ****************************************** Tony Gill - PhD Candidate Centre for Remote Sensing & Spatial Information Science School of Geography, Planning & Architecture University of Queensland Brisbane, Queensland, AUSTRALIA, 4072 Ph: 61-7-3365-7027 email: t.gill1@uq.edu.au [[alternative HTML version deleted]]
On Thu, 4 Aug 2005, Tony Gill wrote:> Hi All, > > I have a greyscale image that I am reading in through RGDAL and placing in a > pixmap object. > > As an example use the logo.jpg file that comes with the RGDAL package: > > #Read the file > logo <- system.file("pictures/logo.jpg", package="rgdal")[1] > x <- new("GDALReadOnlyDataset", logo) > > #Create the pixmap object > xGrey <- getPixmapGDAL(x) > > Now I would like to read individual pixel values and store them in a > separate vector. However I have not found a straight-forward way to do this. > > I thought that something like: > > x <- xGrey[1,1] > > would return the pixel value, but it seems to return a pixmap object with > dimension 1x1 (i.e. only one pixel in size) > > xGrey[1,1] > Pixmap image > Type : pixmapGrey > Size : 1x1 > Resolution : 1x1 > Bounding box : 1 0 2 1 > > Any ideas on how to get the actual pixel value from a pixmap? (Note I could > output to an ascii file and then read the file back in as text - but not > nice!) >There are lots of ideas in the S4 Classes and Methods useR! 04 keynote talk given by pixmap maintainer Friedrich Leisch at: http://www.ci.tuwien.ac.at/Conferences/useR-2004/Keynotes/Leisch.pdf but the easiest one is:> setAs("pixmapGrey", "matrix", function(from, to) {from at grey}) > xPixmap image Type : pixmapGrey Size : 1x1 Resolution : 1x1 Bounding box : 0 0 1 1> as(x, "matrix")[,1] [1,] 1 unless you use a hammer and chisel:> str(x)Formal class 'pixmapGrey' [package "pixmap"] with 6 slots ..@ grey : num [1, 1] 1 ..@ channels: chr "grey" ..@ size : int [1:2] 1 1 ..@ cellres : num [1:2] 1 1 ..@ bbox : num [1:4] 0 0 1 1 ..@ bbcent : logi FALSE> x at grey[,1] [1,] 1> Thanks in advance > > Tony > > ****************************************** > Tony Gill - PhD Candidate > Centre for Remote Sensing & Spatial Information Science > School of Geography, Planning & Architecture > University of Queensland > Brisbane, Queensland, AUSTRALIA, 4072 > Ph: 61-7-3365-7027 > email: t.gill1 at uq.edu.au > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
Friedrich.Leisch@tuwien.ac.at
2005-Aug-04 12:06 UTC
[R] how to read individual values from a pixmap object
>>>>> On Thu, 4 Aug 2005 18:02:55 +1000, >>>>> Tony Gill (TG) wrote:[...] > Now I would like to read individual pixel values and store them in a > separate vector. However I have not found a straight-forward way to do this. > I thought that something like: > x <- xGrey[1,1] > would return the pixel value, but it seems to return a pixmap object with > dimension 1x1 (i.e. only one pixel in size) > xGrey[1,1] > Pixmap image > Type : pixmapGrey > Size : 1x1 > Resolution : 1x1 > Bounding box : 1 0 2 1 > Any ideas on how to get the actual pixel value from a pixmap? (Note I could > output to an ascii file and then read the file back in as text - but not > nice!) getChannels(xGrey) will get you the matrix of pixel values. HTH, -- ------------------------------------------------------------------- Friedrich Leisch Institut f??r Statistik Tel: (+43 1) 58801 10715 Technische Universit??t Wien Fax: (+43 1) 58801 10798 Wiedner Hauptstra??e 8-10/1071 A-1040 Wien, Austria http://www.ci.tuwien.ac.at/~leisch
Tony Gill <t.gill1 <at> uq.edu.au> writes:> > Hi All, > > I have a greyscale image that I am reading in through RGDAL and placing in a > pixmap object. >>library(pixmap) x <- read.pnm("graypic.pnm") str(x) x at grey[1,1]