[R-sig-Geo] clustering multi band images

Dylan Beaudette dylan.beaudette at gmail.com
Thu Jun 12 16:56:22 CEST 2008


If you are interested in a (supervised) imagery classification routine
that takes spatial arrangement into consideration, check out the
i.smap command in GRASS GIS.

Cheers,

Dylan

On Thu, Jun 12, 2008 at 4:57 AM, Laura Poggio <laura.poggio at gmail.com> wrote:
> thank you. It seems now solved!
>
> Laura
>
> 2008/6/12 Agustin Lobo <Agustin.Lobo at ija.csic.es>:
>
>>
>>
>> Laura Poggio escribió:
>> .../...
>>
>>>
>>> 2008/6/12 Agustin Lobo <Agustin.Lobo at ija.csic.es <mailto:
>>> Agustin.Lobo at ija.csic.es>>:
>>>
>>> May I just ask you if you have easily available an example of code to
>>> transform the image in a multivariate table pixels x bands? This would be
>>> helpful to avoid many trial and errors (especially the second one). Sorry
>>> for that but at my institution I am the only one dealing with R...
>>>
>>> Thank you again
>>>
>>> Laura
>>>
>>
>> You already did it in:
>> kl <- kmeans(as(img, "data.frame"), 5)
>>
>> Perhaps you want to do it in 2 steps:
>>
>> imgtabla <- as(img, "data.frame")
>> kl <- kmeans(imgtabla, 5)
>>
>> You can look at the first rows of imgtabla with
>>
>> imgtabla[1:5,]
>> or
>> head(imgtabla)
>> and then
>> dim(imgtabla)
>> summary(imgtabla)
>>
>> If img were your complete Landsat image, the same steps
>> would yield an imgtabla with 262144 x 6 (as I assume you are not
>> using the thermal band). In that case, you probably want
>> to run PCA and use only the first 3 PCs for classification, as they
>> typically
>> account for >95% of the total variance and you cam always apply
>> the inverse transform to the centroids to recover the original
>> metric.
>>
>> As a matter of fact, I think it's more practical
>> here to convert imgtabla from data.frame to matrix, as all values are
>> numerical here.
>>
>> Agus
>>
>>
>>>
>>>
>>>    Agus
>>>
>>>
>>>        I will investigate some of the points raised and in case I will
>>>        come back with more clear ideas and questions.
>>>
>>>        Thank you very much to everybody for the support.
>>>
>>>        Laura
>>>
>>>
>>>
>>>        2008/6/12 Agustin Lobo <Agustin.Lobo at ija.csic.es
>>>        <mailto:Agustin.Lobo at ija.csic.es>
>>>        <mailto:Agustin.Lobo at ija.csic.es
>>>        <mailto:Agustin.Lobo at ija.csic.es>>>:
>>>
>>>
>>>           If your images are large (and images typically are large because
>>>           pixel size
>>>           has to be small compared to the extent of the image for the
>>>        image to
>>>           be of acceptable quality for our vision system), I do not
>>>        advice you
>>>           to get them into R for processing as R has severe memory limits
>>>           and many classification techniques are not precisely
>>>        memory-efficient
>>>           (but see clara() in package cluster, actually read
>>>           http://cran.r-project.org/web/views/Cluster.html).
>>>
>>>           I think that you should sample your image in a RS/GIS
>>> environment
>>>           making sure you cover all
>>>           the radiometric space and import only a table pixels x bands
>>>        into R,
>>>           the actual nb. of pixels depending on your HW/SW
>>>        configuration (but
>>>           10000 would be a good start). Then use the numerous R
>>>        classification
>>>           tools to define the centroids and once you have them use
>>>        again your
>>>           RS/GIS program to actually assign each pixel in the image to a
>>>           centroid according to a given rule (i.e. maximum likelihood).
>>>        There
>>>           might be
>>>           ways of writing an efficient assignation step within R itself
>>>        also,
>>>           I think that mclust package does it.
>>>
>>>           Another way of reducing the number of individuals to classify is
>>>           performing a segmentation of the image first and then
>>>        classify segments
>>>           instead of pixels (i.e.
>>>           # Lobo, A. 1997.  Image segmentation and discriminant
>>>        analysis for
>>>           the identification of land cover units in Ecology. IEEE
>>>        Transactions
>>>           on Geoscience and Remote Sensing, 35(5): 1- 11.
>>>           http://wija.ija.csic.es/gt/obster/ABSTRACTS/alobo_ieee97.pdf
>>>           perhaps other articles in
>>>           http://wija.ija.csic.es/gt/obster/alobo_publis.html
>>>           might be of help)
>>>
>>>           In any case, note that img in your code should be converted into
>>>           a multivariate table pixels x bands for most classification
>>>           functions in R to work. Note that this fact makes obvious
>>>           that classification approaches to image processing do not make
>>>           use of the spatial information of the image, which is actually
>>>           a fundamental part of the information of any image.
>>>
>>>           Agus
>>>
>>>           Laura Poggio escribió:
>>>
>>>               Dear list,
>>>               I am trying to do some clustering on images. And I have
>>>        two main
>>>               problems:
>>>
>>>               1) Clustering multiband images.
>>>               I managed to be successful with a single band image, but
>>> when
>>>               trying to
>>>               apply to a 3 band I get the following warning message:
>>>               In as.matrix.SpatialGridDataFrame(x) :
>>>                as.matrix.SpatialPixelsDataFrame uses first column;
>>>                pass subset or [] for other columns
>>>
>>>
>>>               2) saving clustering results as grid or image.
>>>               I get a vector of clusters, but without both coordinates.
>>>        How it
>>>               is possible
>>>               to transform it in a grid?
>>>
>>>               Here the code I use to read the image itself and to do the
>>>               clustering:
>>>
>>>               library(rgdal)
>>>               fld <- system.file("E:/data/IMG/fr/", package="rgdal")
>>>               img <- readGDAL("123_rawR.tif")
>>>
>>>               kl <- kmeans(img, 5)
>>>
>>>               I am quite new to image processing, especially within R,
>>>        and any
>>>               help is
>>>               greatly appreciated.
>>>
>>>               Thank you in advance
>>>
>>>               LP
>>>
>>>                      [[alternative HTML version deleted]]
>>>
>>>               _______________________________________________
>>>               R-sig-Geo mailing list
>>>               R-sig-Geo at stat.math.ethz.ch
>>>        <mailto:R-sig-Geo at stat.math.ethz.ch>
>>>        <mailto:R-sig-Geo at stat.math.ethz.ch
>>>        <mailto:R-sig-Geo at stat.math.ethz.ch>>
>>>
>>>               https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>>
>>>           --    Dr. Agustin Lobo
>>>           Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
>>>           LLuis Sole Sabaris s/n
>>>           08028 Barcelona
>>>           Spain
>>>           Tel. 34 934095410
>>>           Fax. 34 934110012
>>>           email: Agustin.Lobo at ija.csic.es
>>>        <mailto:Agustin.Lobo at ija.csic.es>
>>>        <mailto:Agustin.Lobo at ija.csic.es <mailto:Agustin.Lobo at ija.csic.es
>>> >>
>>>
>>>           http://www.ija.csic.es/gt/obster
>>>
>>>
>>>
>>>    --    Dr. Agustin Lobo
>>>    Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
>>>    LLuis Sole Sabaris s/n
>>>    08028 Barcelona
>>>    Spain
>>>    Tel. 34 934095410
>>>    Fax. 34 934110012
>>>    email: Agustin.Lobo at ija.csic.es <mailto:Agustin.Lobo at ija.csic.es>
>>>    http://www.ija.csic.es/gt/obster
>>>
>>>
>>>
>> --
>> Dr. Agustin Lobo
>> Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
>> LLuis Sole Sabaris s/n
>> 08028 Barcelona
>> Spain
>> Tel. 34 934095410
>> Fax. 34 934110012
>> email: Agustin.Lobo at ija.csic.es
>> http://www.ija.csic.es/gt/obster
>>
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>




More information about the R-sig-Geo mailing list