An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110519/0a88851b/attachment.pl>
Converting the graphics window to a data matrix
5 messages · Barry Rowlingson, Michael Sumner, Beutel, Terry S +1 more
On Thu, May 19, 2011 at 5:19 AM, Beutel, Terry S
<Terry.Beutel at deedi.qld.gov.au> wrote:
I'm wondering if anyone is aware of a way to take what is visible in the R graphics window, pixelate it, and express that pixellation in a numeric matrix. For example, I am using the following command to create a ?black (present) and white (absent) spatial simulation of grass tussock distribution.
symbols(x=runif(100,-.5,1.5),y=runif(100,-.5,1.5),circles=runif(100)/30, inches=F,bg=1,xlim=c(0,1),ylim=c(0,1)) What I would like to end up with is a 2 dimensional matrix that indicates presence/absence of grass in any given pixel as per the image generated from the above graphics plot.
Instead of drawing to the screen, you can use the 'png' function to create a graphics device that "draws" to an image file. Then you can read that image file into R and get it as a matrix. You probably also want to set some of the margin and axis parameters so the plotting region fills the whole device, and you dont have the axes and tick marks etc confusing the matrix. That's some pointers for starters. I've not had breakfast yet... Barry
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110519/a18a1b91/attachment.pl>
Thanks Barry. I have now got as far as creating the png (or gif or tiff) images (as per your suggestions). But I am unable to work out how to convert each to a 2 dimensionional numeric matrix showing the spatial distribution of occupied/unoccupied pixels in R. Any suggestions anybody? Thanks Terry -----Original Message----- From: b.rowlingson at googlemail.com [mailto:b.rowlingson at googlemail.com] On Behalf Of Barry Rowlingson Sent: Thursday, 19 May 2011 4:19 PM To: Beutel, Terry S Cc: r-help at r-project.org Subject: Re: [R] Converting the graphics window to a data matrix
On Thu, May 19, 2011 at 5:19 AM, Beutel, Terry S <Terry.Beutel at deedi.qld.gov.au> wrote:
I'm wondering if anyone is aware of a way to take what is visible in the R graphics window, pixelate it, and express that pixellation in a numeric matrix. For example, I am using the following command to create a ?black (present) and white (absent) spatial simulation of grass tussock distribution.
symbols(x=runif(100,-.5,1.5),y=runif(100,-.5,1.5),circles=runif(100)/3 0, inches=F,bg=1,xlim=c(0,1),ylim=c(0,1)) What I would like to end up with is a 2 dimensional matrix that indicates presence/absence of grass in any given pixel as per the image generated from the above graphics plot.
Instead of drawing to the screen, you can use the 'png' function to create a graphics device that "draws" to an image file. Then you can read that image file into R and get it as a matrix. You probably also want to set some of the margin and axis parameters so the plotting region fills the whole device, and you dont have the axes and tick marks etc confusing the matrix. That's some pointers for starters. I've not had breakfast yet... Barry ********************************DISCLAIMER**************************** The information contained in the above e-mail message or messages (which includes any attachments) is confidential and may be legally privileged. It is intended only for the use of the person or entity to which it is addressed. If you are not the addressee any form of disclosure, copying, modification, distribution or any action taken or omitted in reliance on the information is unauthorised. Opinions contained in the message(s) do not necessarily reflect the opinions of the Queensland Government and its authorities. If you received this communication in error, please notify the sender immediately and delete it from your computer system network.
The EBImage package from bioconductor will read image files (png and others), the object read has a slot called .Data that is a 3 dimensional array with one dimension being the color (red,green,blue), so you could just grab one of those 3 layers and it would probably be what you want (or some function of that layer, or combination of the 3 layers).
Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111 > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Beutel, Terry S > Sent: Thursday, May 19, 2011 10:02 PM > To: Barry Rowlingson > Cc: r-help at r-project.org > Subject: Re: [R] Converting the graphics window to a data matrix > > Thanks Barry. I have now got as far as creating the png (or gif or > tiff) images (as per your suggestions). But I am unable to work out how > to convert each to a 2 dimensionional numeric matrix showing the > spatial distribution of occupied/unoccupied pixels in R. Any > suggestions anybody? > Thanks > > Terry > > -----Original Message----- > From: b.rowlingson at googlemail.com [mailto:b.rowlingson at googlemail.com] > On Behalf Of Barry Rowlingson > Sent: Thursday, 19 May 2011 4:19 PM > To: Beutel, Terry S > Cc: r-help at r-project.org > Subject: Re: [R] Converting the graphics window to a data matrix > > On Thu, May 19, 2011 at 5:19 AM, Beutel, Terry S > <Terry.Beutel at deedi.qld.gov.au> wrote: > > I'm wondering if anyone is aware of a way to take what is visible in > > the R graphics window, pixelate it, and express that pixellation in a > > numeric matrix. For example, I am using the following command to > > create a ?black (present) and white (absent) spatial simulation of > > grass tussock distribution. > > > >> > > symbols(x=runif(100,-.5,1.5),y=runif(100,- > .5,1.5),circles=runif(100)/3 > > 0, > > inches=F,bg=1,xlim=c(0,1),ylim=c(0,1)) > > > > What I would like to end up with is a 2 dimensional matrix that > > indicates presence/absence of grass in any given pixel as per the > > image generated from the above graphics plot. > > Instead of drawing to the screen, you can use the 'png' function to > create a graphics device that "draws" to an image file. Then you can > read that image file into R and get it as a matrix. > > You probably also want to set some of the margin and axis parameters > so the plotting region fills the whole device, and you dont have the > axes and tick marks etc confusing the matrix. > > That's some pointers for starters. I've not had breakfast yet... > > Barry > > > ********************************DISCLAIMER**************************** > The information contained in the above e-mail message or messages > (which includes any attachments) is confidential and may be legally > privileged. It is intended only for the use of the person or entity > to which it is addressed. If you are not the addressee any form of > disclosure, copying, modification, distribution or any action taken > or omitted in reliance on the information is unauthorised. Opinions > contained in the message(s) do not necessarily reflect the opinions > of the Queensland Government and its authorities. If you received > this communication in error, please notify the sender immediately > and delete it from your computer system network. > > > ______________________________________________ > 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.