PyDev Editor: https://marketplace.eclipse.org/content/pydev-python-ide-eclipse
A very powerful Python editor which can be used to execute Bio7 Jython and Python scripts instead of the Bio7 default editor. In addition Bio7 can use the PyDev editor to execute scripts running on the Bio7 Java classpath. If you open Jython/Python scripts with the PyDev editor the default Bio7 action will be visible to execute the scripts on the Bio7 classpath.
I created a new Bio7 example which demonstrates how to classify an image with Bio7, ImageJ and R.
For the classification I used the “randomForest” R package and an image example of ImageJ so you can reproduce the example quite easily. I made the example script as easy as possible and trained the classifier with 64 trees by default (see literature below). Not shown in the video is the procedure to control the prediction of the trained classifier with test data. You can find a simple script in the repository, too, which uses a method of the powerful ‘caret’ package.
If you have some recommendations of how to effectively use a decent classifier for image classification (e.g., which classifier is well suited for images, which tuning parameters are useful in this context, which additional signatures could be used, etc.) I would be happy to hear.
Fernández-Delgado, M., Cernadas, E., Barro, S. & Amorim, D. Do we Need Hundreds of Classifiers to Solve Real World Classification Problems? Journal of Machine Learning Research15, 3133–3181 (2014).
Oshiro, T. M., Perez, P. S. & Baranauskas, J. A. in Machine Learning and Data Mining in Pattern Recognition (ed. Perner, P.) 154–168 (Springer Berlin Heidelberg, 2012).
Latinne, P., Latinne, P., Debeir, O. & Decaestecker, C. Limiting the Number of Trees in Random Forests. IN PROCEEDINGS OF MCS 2001, LNCS 2096, 2001.
In the current release of Bio7 2.3 two new plot preferences are available to automatically plot data with the size of the visible display (as an image) or with the size of available ImageSizeX and ImageSizeY R workspace variables.
The second option is handy if you transfer images from ImageJ to the R workspace (the variables ImageSizeX and ImageSizeY will be autmatically created, too). You can then create an R image plot (e.g. from a classification) in the same size as an overlay of the original image (in turn plotted and overlayed in ImageJ).
Improvements of the R editor for the upcoming Bio7 2.4 release
For the upcoming release of Bio7 I also add new features to the Bio7 R editor.
Among other things until now I improved the code completion. If you now type a a left parenthesis you get a help tooltip if the function is known (if you load frequent used R packages with the Bio7 GUI interface the package function context will be added to the code completion, tooltip interface).
Screenshot 1: Improved tooltip when a left parenthesis is typed.
Figure 2: Code completion (Keys: CTRL+Space) now preselects the right context (e.g. functions with ‘.’ char)
In addition I added a function to set right parentheses, braces, etc. automatically when left parentheses, etc. are typed in the R editor.
Finally I was able to find the CSS error in the toolbar layout which resulted in a visible gap when, e.g., the Flow editor was active. Now everything looks much better (see the red arrows!) especially when you install Eclipse plugins which make contributions to the main toolbar.
You can also add this corrections easily to a current Bio7 2.3 installation. Just add the following lines to the default Bio7 CSS (Path: Bio7/plugins/com.eco.bio7.themes_18.104.22.168508261732/css/e4_default_yourOperatingSystem.css):
Here I present a summary of a small spatstat workshop I created. I also explain in several videos how to transfer and convert 2d and 3D ImageJ measurements to a spatial point pattern with Bio7. The example datasets and code samples used here were taken from the spatstat help and from spatstat scripts cited at the end of the summary. The github repository with spatstat scripts, image scripts, documentation and more can be found here. I hope that this material is useful for others and helps in the creation of a spatial point pattern analysis with the fantastic spatstat package.
From the spatstat website:
‘spatstat is a package for analyzing spatial point pattern data. Its functionality includes exploratory data analysis, model-fitting, and simulation.’ (1)
The package supports:
creation, manipulation and plotting of point patterns
exploratory data analysis
simulation of point process models
hypothesis tests and model diagnostic
Classes in spatstat
To handle point pattern datasets and related data, the spatstat package supports the following classes of objects:
ppp: planar point pattern
owin: spatial region (‘observation window’)
im: pixel image
psp: pattern of line segments
pp3: three-dimensional point pattern
ppx: point pattern in any number of dimensions
lpp: point pattern on a linear network
Creation of a point pattern object
A point pattern object can be created easily from x and y coordinates.
# some arbitrary coordinates in [0,1]
x <- runif(20)
y <- runif(20)
# the following are equivalent
X <- ppp(x, y, c(0,1), c(0,1))
X <- ppp(x, y)
X <- ppp(x, y, window=owin(c(0,1),c(0,1)))
# specify that the coordinates are given in metres
X <- ppp(x, y, c(0,1), c(0,1), unitname=c("metre","metres"))
Study region (window)
Many commands in spatstat require us to specify a window, study region or domain!
An object of class “owin” (‘observation window’) represents a region or window (rectangular, polygonal with holes, irregular) in two dimensional space.
w <- owin(c(0,1), c(0,1))
# the unit square
w <- owin(c(10,20), c(10,30), unitname=c("foot","feet"))
# a rectangle of dimensions 10 x 20 feet
# with lower left corner at (10,10)
# polygon (diamond shape)
w <- owin(poly=list(x=c(0.5,1,0.5,0),y=c(0,1,2,1)))
w <- owin(c(0,1), c(0,2), poly=list(x=c(0.5,1,0.5,0),y=c(0,1,2,1)))
# polygon with hole
ho <- owin(poly=list(list(x=c(0,1,1,0), y=c(0,0,1,1)),
Task 1: Create a point pattern object from x,y data.
Task 2: Create a point pattern object within a specified window object.
Summary statistics of the dataset
## Planar point pattern: 71 points
## Average intensity 0.007395833 points per square unit (one unit = 0.1
## Coordinates are integers
## i.e. rounded to the nearest unit (one unit = 0.1 metres)
## Window: rectangle = [0, 96] x [0, 100] units
## Window area = 9600 square units
## Unit of length: 0.1 metres
Computes the distance from each point to its nearest neighbour in a point pattern.
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.236 5.541 8.246 7.908 10.050 15.650
Finds the nearest neighbour of each point in a point pattern.
Video: Create a spatstat point pattern with a polygonal window (study region)
Task 1: Create a polygonal point pattern object from the image ‘Cell_Colony.jpeg’.
Marked point patterns
Points in a spatial point pattern may carry additional information called a ‘mark’. A mark can represent additional information like height, diameter, species, etc. It is important to know that marks are not covariates (the points are not a result of the mark values!).
#from the spatstat help:
m <- sample(1:2, 20, replace=TRUE)
m <- factor(m, levels=1:2)
X <- ppp(x, y, c(0,1), c(0,1), marks=m)
With Bio7 and ImageJ marked point patterns can be created with the ‘Selection’ action which can transfer a SpatialPointDataFrame which again can be converted to a marked point pattern.
Select points and transfer the selections to the ROI Manager
Measure the selections and transfer the ImageJ Results Table to R with the Image-Methods view ‘IJ RT’ action
Transfer the points of the ROI Manager as a SpatialPointsDataFrame (Enable the ‘Add selected data frame’ option and select the dataframe in the combobox)
Convert the SpatialPointsDataFrame to a spatstat point pattern object with the results table as marks
#print a summary!
## Marked planar point pattern: 8 points
## Average intensity 0.0002494232 points per square unit
## Coordinates are integers
## i.e. rounded to the nearest unit
## Mark variables: Area, Mean, Min, Max, X, Y
## Area Mean Min Max X
## Min. :0 Min. :160 Min. :160 Min. :160 Min. : 75.0
## 1st Qu.:0 1st Qu.:190 1st Qu.:190 1st Qu.:190 1st Qu.:124.9
## Median :0 Median :220 Median :220 Median :220 Median :198.5
## Mean :0 Mean :209 Mean :209 Mean :209 Mean :173.1
## 3rd Qu.:0 3rd Qu.:232 3rd Qu.:232 3rd Qu.:232 3rd Qu.:221.0
## Max. :0 Max. :248 Max. :248 Max. :248 Max. :233.5
## Min. : 27.50
## 1st Qu.: 63.25
## Median :119.25
## Mean :129.06
## 3rd Qu.:204.38
## Max. :230.00
## Window: rectangle = [75, 233] x [27, 230] units
## Window area = 32074 square units
You can also transfer a dataframe from the Table view of Bio7 (rows must be equal to the number of points!) and assign it to the point pattern.
Video: Create a spatstat marked point pattern:
Task 1: Create a marked point pattern from the image ‘Cell_Colony.jpg’.
Task 2: Create a marked point pattern from spreadsheet data in Bio7.
Tropical rainforest point pattern dataset bei. We want to find out if trees prefer a steep or flat terrain. The data consists of extra covariate data in ‘bei.extra’, which contains a pixel image of terrain elevation and a pixel image of terrain slope.
The plot below is an estimate of the intensity p(z) as a function of terrain slope z. It indicates that the Beilschmiedia trees are relatively unlikely to be found on flat terrain (where the slope is less than 0.05) compared to steeper slopes.
The study region is divided into rectangles (quadrats) of equal size, and the number of points in each rectangle is counted.
Fit a point process model to an observed point pattern.
# fit the stationary Poisson process
# to point pattern 'nztrees'
## Extracting model information...Evaluating trend...done.
## Checking arguments..determining simulation windows...
plot(modelFitted, main="Fitted Model")
Used for this script:
(1) A. Baddeley and R. Turner. Spatstat: an R package for analyzing spatial point patterns Journal of Statistical Software 12: 6 (2005) 1-42. www.jstatsoft.org ISSN: 1548-7660
(2) A. Baddeley and R. Turner. Modelling spatial point patterns in R. Chapter 2, pages 23-74 in In Case Studies in Spatial Point Pattern Modelling (eds. A. Baddeley, P. Gregori, J. Mateu, R. Stoica and D. Stoyan) Lecture Notes in Statistics 185. New York: Springer-Verlag 2006. ISBN: 0-387-28311-0
(3) A. Baddeley. Analysing Spatial Point Patterns in R. Workshop Notes, December 2010. Published online by CSIRO, Australia. Download here (232 pages, pdf, 12.2Mb)