ROI coordinate format

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ROI coordinate format

Moo K. Chung
Hi all,

Anyone aware of ROI coordinate format? I am trying to read *.roi files
directly into MATLAB. Thanks.

--
Moo Chung
[hidden email]
http://www.stat.wisc.edu/~mchung
Associate Professor
Department of Biostatistics & Medical Informatics
Waisman Laboratory for Brain Imaging and Behavior
University of Wisconsin-Madison
Reply | Threaded
Open this post in threaded view
|

Re: ROI coordinate format

jmutterer
Moo, you can find a description of the ROI format in the RoiDecoder source
code available at :

http://rsb.info.nih.gov/ij/developer/source/ij/io/RoiDecoder.java.html

Jerome

On 10/20/07, Moo K. Chung <[hidden email]> wrote:

>
> Hi all,
>
> Anyone aware of ROI coordinate format? I am trying to read *.roi files
> directly into MATLAB. Thanks.
>
> --
> Moo Chung
> [hidden email]
> http://www.stat.wisc.edu/~mchung
> Associate Professor
> Department of Biostatistics & Medical Informatics
> Waisman Laboratory for Brain Imaging and Behavior
> University of Wisconsin-Madison
>
Reply | Threaded
Open this post in threaded view
|

Re: ROI coordinate format

Mika Wahlroos-2
In reply to this post by Moo K. Chung
Moo K. Chung wrote:
> Anyone aware of ROI coordinate format? I am trying to read *.roi files
> directly into MATLAB. Thanks.

There's some kind of a description in the comments of the
RoiDecoder.java file in the source code (specifically
ij/io/RoiDecoder.java, if my memory serves) distribution of ImageJ. It's
not very verbose but if you're familiar with binary file formats you can
probably figure it out. I don't know specifically about Matlab or how
you'd load such a file to it, though.

I also tried to search the web a little for an easy description of the
format but couldn't find anything with a quick search. Trying a web
search might also be useful, but you'll also need to remember that there
are probably also other formats that use the same extension.

Regards,
Mika

--
______________________________________________________________________
Mika Wahlroos | Software Engineer
Mobile:+358 46 851 3848 (FI) | [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: ROI coordinate format

pcloetens
In reply to this post by Moo K. Chung
Moo K. Chung wrote:
> Hi all,
>
> Anyone aware of ROI coordinate format? I am trying to read *.roi files
> directly into MATLAB. Thanks.
>

Hello,
I have written for Gnu Octave the simple function roiread that reads a
roi-file created by ImageJ. You can find it below. It reads only the
roitype and the xy coordinates of the roi.
Peter

roiread is the user-defined function defined from:
/usr/local/octave-esrf/m/imagej/roiread.m

## Copyright (C) 2006 Peter Cloetens
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

## roiread
## function [ ret ] = roiread (filename)
##      reads an ImageJ roi stored in filename
##      created for example in ImageJ: File/Save As/Selection...
##      default filename extension is .roi
##      ret.roitype contains the kind of selection (polygon, rectangle,
ellips, line, freehandline, segmentedline, noroi, freehand, traced,
angle, point)
##      ret.xycoords_lefttop contains X and Y coordinates of the
left/top corner (starting at 0, included in roi)
##      ret.xycoords_rightbottom contains X and Y coordinates of the
right/bottom corner (starting at 0, not included in roi !)
##      does not read other information from roi file

## Author: Peter Cloetens <[hidden email]>
##
## 2006-08-15 Peter Cloetens <[hidden email]>
## * Initial revision
## 2006-08-30 PC
## * correction for little endian machines
## * add roitypes noroi (?), traced and angle

function [ ret ] = roiread (filename)

     if !exist('filename','var')
         filename = [];
     endif
     if isempty(filename)
         help roiread
         return
     endif

     if isempty(findstr(filename,'.'))
         # we add .roi for lazy people
         filename = [filename '.roi'];
     endif

     fid = fopen(filename,'r','ieee-be');
     hd = fread(fid,8,'uint8');
     # check that this is an ImageJ roi
     if !isequal(hd(1:2),[73 111]')
         printf('%s does not contain a valid ImageJ roi\n',filename)
         ret = [];
     else
         switch hd(7)
             case 0
                 ret =
struct('roitype','polygon','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             case 1
                 ret =
struct('roitype','rectangle','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             case 2
                 ret =
struct('roitype','ellips','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             case 3
                 ret =
struct('roitype','line','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             case 4
                 ret =
struct('roitype','freehandline','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             case 5
                 ret =
struct('roitype','segmentedline','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             case 6
                 ret =
struct('roitype','noroi','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             case 7
                 ret =
struct('roitype','freehand','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             case 8
                 ret =
struct('roitype','traced','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             case 9
                 ret =
struct('roitype','angle','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             case 10
                 ret =
struct('roitype','point','xycoords_lefttop',[],'xycoords_rightbottom',[]);
             otherwise
                 ret =
struct('roitype','notyetimplemented','xycoords_lefttop',[],'xycoords_rightbottom',[]);
         endswitch
         coord = fread(fid,4,'int16');
         ret.xycoords_lefttop = [coord(2) coord(1)];
         ret.xycoords_rightbottom = [coord(4) coord(3)];
     endif

     fclose(fid);

endfunction