1

I tried to use the RImageJROI package from David C Sterratt to transfer multiple ROIs into R and convert them to Spatstat.

This is a minimal example of my R-code

library(RImageJROI)
ROI = read.ijzip("path/ROI.zip")
spat.ROI = ij2spatstat(ROI)

Reading the zip-file works well but when I run the converting command I get the following error:

Error in conv.fun(k, window = window, unitname = unitname, scale = scale, : object 'out' not found

Attached there is a file for creating a ROI.zip -file which causes the error after processing it in ImageJ with:

    run("Analyze Particles...", "add");
roiManager("Save", "Path\\Roi.zip");

Simple picture producing 2 ROIs

Is there a way to get RImageJROI working, am I missing something obvious, or does anyone know another solution for my project?

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
Maxi Kießler
  • 23
  • 1
  • 5
  • Does `summary(ROI)`, `plot(ROI)` etc. work after you have read in the zip file? What kind of regions do you have (i.e. output of `sapply(ROI, function(x) x$strType)`)? Can you make your example reproducible without the need for ImageJ? Maybe just a link to the zip file? – Ege Rubak Sep 12 '17 at 13:40
  • Have you tried using the [Renjin script language](http://imagej.net/Renjin_Scripting), available with Fiji? It seems there is [partial support for spatstat](http://packages.renjin.org/package/org.renjin.cran/spatstat/). This script language can be used with [script parameters](https://imagej.net/Script_Parameters). Another option to try would be [Bio7](https://imagej.net/Bio7), which provides some ImageJ/R integration features. – ctrueden Sep 14 '17 at 14:38

2 Answers2

0

You can use Bio7 for that with has special methods to transfer different ImageJ ROI's and image data to R.

Some methods where especially designed for spatstat after a great spatstat tutorial on the R conference in 2015.

Here a link to some ImageJ spatstat notes and simple scripts:

http://bio7.org/?p=2618

https://github.com/Bio7/Bio7_Workshop

Here some video tutorials to transfer ROI data:

3D Point Pattern: https://youtu.be/DmfSASgJa_g

Line Segments: https://youtu.be/EPan7kibYpo

Polygons: https://youtu.be/bS_2ejOt7Tg

Point Patterns: https://youtu.be/7t5V2o8jFJw

Particle Measurments: https://youtu.be/7t5V2o8jFJw

Georeferenced Polygons (which can be converted to spatstat objects):

https://youtu.be/P2NflfBB2Tg

Marcel
  • 502
  • 3
  • 11
0

I got the same error message. I found this to work after looking inside the ij2spatstat function.

library(RImageJROI)
library(spatstat)

roi <- read.ijroi("RoiSet/0071-0081.roi") # path to single ROI
poly <- list(x = roi$coords[,2], y = roi$coords[,1])
out <- owin(poly = poly)

plot(out)

You can put this inside a loop to transform every ROI in a directory.

Jeff Bezos
  • 1,929
  • 13
  • 23
  • Update: I'm getting the error message "Area of polygon is negative - maybe traversed in wrong direction?" for some ROIs. This can be fixed by switching the column indices in the coordinates... still figuring out a workaround – Jeff Bezos Mar 01 '20 at 22:58