Dear listers, I have a collection of tif images that I would like to convert, in R, to a matrix containing the values of the 8bit colour. Ideally, I would like a matrix for each of the colour channels (red, blue and green). I have 'googled' and searched the help list but have yet to find a solution and hope that someone can point me in the right direction. I currently use subscription software (Igor) for the conversion and would prefer to use R. Best wishes, Roger
This requires the rgdal and sp packages to be installed, and assumes a
3-bandfile called image.tif
## (untested)
library(rgdal)
x <- readGDAL("image.tif")
## first band
red <- as.image.SpatialGridDataFrame(x[1])$z
## second
green <- as.image.SpatialGridDataFrame(x[2])$z
## third
blue <- as.image.SpatialGridDataFrame(x[3])$z
The 1,2,3 indexing is syntax for "this SpatialGridDataFrame with just these
bands", so that sp:::image.SpatialGridDataFrame can convert simply to the
list x/y/z format for image().
HTH
On Tue, Oct 19, 2010 at 10:59 PM, Roger Gill
<roger.gill1979@yahoo.co.uk>wrote:
> Dear listers,
>
> I have a collection of tif images that I would like to convert, in R, to a
> matrix containing the values of the 8bit colour. Ideally, I would like a
> matrix
> for each of the colour channels (red, blue and green). I have
'googled' and
> searched the help list but have yet to find a solution and hope that
> someone can
> point me in the right direction.
>
> I currently use subscription software (Igor) for the conversion and would
> prefer
> to use R.
>
> Best wishes,
>
> Roger
>
>
>
>
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
--
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsumner@gmail.com
[[alternative HTML version deleted]]
Look at the EBImage package from bioconductor. -- 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 Roger Gill > Sent: Tuesday, October 19, 2010 6:00 AM > To: r-help at r-project.org > Subject: [R] Tif image to 8bit colour matrix. > > Dear listers, > > I have a collection of tif images that I would like to convert, in R, > to a > matrix containing the values of the 8bit colour. Ideally, I would like > a matrix > for each of the colour channels (red, blue and green). I have 'googled' > and > searched the help list but have yet to find a solution and hope that > someone can > point me in the right direction. > > I currently use subscription software (Igor) for the conversion and > would prefer > to use R. > > Best wishes, > > Roger > > > > > > ______________________________________________ > 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.