Gough Lauren
2009-Dec-04 09:10 UTC
[R] Dividing a pixel image into factors - (cut.im(), cut.default())
Hi, I have a numeric pixel image which I would like to divide into factors for analysis in Spatstat. I have found that I can use cut.im() function to divide the range of pixel values into a series of equal length intervals (e.g. if my pixels values range from 0 to 60, cut.im(X.im,breaks=2) will produce two factors one containing pixel values 0-30 and one containing pixel values of 30 - 60, or thereabouts). However, I would like to specify the pixel value at which the factors are created - e.g. create one factor containing pixel values of 0-5 and another factor containing all other pixel values. I have been struggling to work out how to do this using either cut.im() or cut.default(). Can anyone help? Many thanks, Lauren This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation. [[alternative HTML version deleted]]
Glen Sargeant
2009-Dec-04 16:27 UTC
[R] Dividing a pixel image into factors - (cut.im(), cut.default())
Lauren, I think (?) you mean to say that you wish to create a factor and control the range of values assigned to each level. The "breaks" argument can specify either the number of intervals you desire OR the values you wish to use to define levels of your factor. See '?cut' and the following example:> #A numeric vector > x <- 1:10 > > #Assign equal number of values > #2 each of 2 automatically > #determined intervals > levels1 <- cut(x,breaks=2) > > #User-specified intervals > levels2 <- cut(x,breaks=c(0,3,Inf)) > > data.frame(x,levels1,levels2)x levels1 levels2 1 1 (0.991,5.5] (0,3] 2 2 (0.991,5.5] (0,3] 3 3 (0.991,5.5] (0,3] 4 4 (0.991,5.5] (3,Inf] 5 5 (0.991,5.5] (3,Inf] 6 6 (5.5,10] (3,Inf] 7 7 (5.5,10] (3,Inf] 8 8 (5.5,10] (3,Inf] 9 9 (5.5,10] (3,Inf] 10 10 (5.5,10] (3,Inf] 'Inf' is an easy way to create an interval that contains all values larger than some cutoff. Good luck with your analysis, Glen Gough Lauren wrote:> > I have a numeric pixel image which I would like to divide into factors > for analysis in Spatstat. I have found that I can use cut.im() function > to divide the range of pixel values into a series of equal length > intervals (e.g. if my pixels values range from 0 to 60, > cut.im(X.im,breaks=2) will produce two factors one containing pixel > values 0-30 and one containing pixel values of 30 - 60, or thereabouts). > > However, I would like to specify the pixel value at which the factors > are created - e.g. create one factor containing pixel values of 0-5 and > another factor containing all other pixel values. I have been > struggling to work out how to do this using either cut.im() or > cut.default(). Can anyone help? >----- Glen Sargeant Research Wildlife Biologist -- View this message in context: http://n4.nabble.com/Dividing-a-pixel-image-into-factors-cut-im-cut-default-tp948346p948676.html Sent from the R help mailing list archive at Nabble.com.
Rolf Turner
2009-Dec-06 21:01 UTC
[R] Dividing a pixel image into factors - (cut.im(), cut.default())
On 4/12/2009, at 10:10 PM, Gough Lauren wrote:> Hi, > > > > I have a numeric pixel image which I would like to divide into factors > for analysis in Spatstat. I have found that I can use cut.im() > function > to divide the range of pixel values into a series of equal length > intervals (e.g. if my pixels values range from 0 to 60, > cut.im(X.im,breaks=2) will produce two factors one containing pixel > values 0-30 and one containing pixel values of 30 - 60, or > thereabouts). > > > > > However, I would like to specify the pixel value at which the factors > are created - e.g. create one factor containing pixel values of 0-5 > and > another factor containing all other pixel values.I think you mean a factor with two ***levels***, one encompassing values from 0 to 5, the other encompassing values from 5 to 60.> I have been > struggling to work out how to do this using either cut.im() or > cut.default(). Can anyone help?Unless I'm terribly confused, the obvious solution to your question is: cut.im(X.im,breaks=c(0,5,60)) Uhhh, why was this difficult? cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
Maybe Matching Threads
- Quantreg - 'could not find function"rq"'
- Fitting weibull, exponential and lognormal distributions to left-truncated data.
- Spatstat - K2 index
- Spatstat help - quadratcount query
- Issues with Ubuntu 22.04 and Installing the Latest Version of R (R 4.4.1) to Docker Image