Page 1 of 1

managing ROIs

PostPosted: Fri Jul 12, 2013 1:17 pm
by yuriy_alexandrov
Hi All,

I try to use ROI schema from Matlab to place our image segmentation results in Omero, and have couple of, hopefully, very simple questions.

I succeeded to transfer bounding rectangles around each object - they are seen in Omero Web browser.
But the idea is, certainly, to transfer shapes (or "masks" - not sure which term is proper. blobs, anyway).

The code below uses the segmented image "segmmask" as source of "masks" and attaches ROI with corresponding "masks" to the Omero image:

Code: Select all
            stats = regionprops(segmmask,'PixelList');
            for k=1:numel(stats)
                    X = stats(k).PixelList(:,1);
                    Y = stats(k).PixelList(:,2);
                    %
                    x0 = min(X);
                    y0 = min(Y);
                    W = max(X) - x0 + 1;
                    H = max(Y) - y0 + 1;
                    %
                    m = zeros(W,H);
                    for j = 1 : numel(X),
                        x = X(j) - x0 + 1;
                        y = Y(j) - y0 + 1;
                        m(x,y) = 1;                       
                    end
                    %
                    mask = createMask(x0,y0,m);
                    setShapeCoordinates(mask, 0, 0, 0);
                    %
                    roi = omero.model.RoiI;                   
                    roi.addShape(mask);                                       
                    roi.setImage(omero.model.ImageI(image.getId.getValue, false));
                    roi = iUpdate.saveAndReturnObject(roi);
            end           

first, I'm not sure it is correct.

second, - imported ROIs and shapes are not visible in Omero-web.

third - I didn't find way how to retrieve these pixels back (which is the matter of significant interest..).

Using the example I found how to access the "mask" object if it is there:

Code: Select all
service = obj.session.getRoiService();
roiResult = service.findByImage(image.getId.getValue, []);
rois = roiResult.rois;
n = rois.size;
for thisROI  = 1:n
    roi = rois.get(thisROI-1);
    numShapes = roi.sizeOfShapes; % an ROI can have multiple shapes.
    for ns = 1:numShapes
        shape = roi.getShape(ns-1); % the shape
       
         if (isa(shape, 'omero.model.Mask'))

             shape
             % mmmmmmmmmmmm... WHAT TO DO NEXT?

         end                       
    end
end

So basically I would like to get some quick refs/usage examples for the functions managing access, visibility, and attributes of these blobs' pixels.

Best regards,
Y.

Re: managing ROIs

PostPosted: Fri Jul 12, 2013 3:10 pm
by yuriy_alexandrov
well, it looks like, I found how to get the masks back:

Code: Select all
         if (isa(shape, 'omero.model.Mask'))
            x0 = shape.getX().getValue;
            y0 = shape.getY().getValue;
            W = shape.getWidth().getValue;
            H = shape.getHeight().getValue;
            bytes = shape.getBytes();
            mask = reshape(bytes,[H,W]);
         end


but still not how to make them visible in Omero Web..
...

Re: managing ROIs

PostPosted: Fri Jul 12, 2013 8:41 pm
by wmoore
Hi,

Unfortunately we never got around to implementing mask display in the web viewer yet.
I remember at the time that I was still unsure about the specification for storing masks, and how to handle that in Python.
But now that someone's actually creating masks, we should certainly go ahead.

Re: managing ROIs

PostPosted: Mon Jul 15, 2013 10:11 am
by yuriy_alexandrov
many thanks Will,

and how does it work, say, with tracking applications or segmentations by CEll PRofiler/ImageJ/KNIME - are segmentation results stored in Omero as separate images or annotations?

displaying segmented ROIs - looks like very basic image visualization functionality.

one last question - how to set/get attributes of ROI, e.g. Description?

Re: managing ROIs

PostPosted: Tue Jul 16, 2013 9:39 am
by yuriy_alexandrov
..it looks like, text attribute is set by "setTextValue"

http://users.openmicroscopy.org.uk/~spl ... _Mask.html

Re: managing ROIs

PostPosted: Tue Jul 16, 2013 10:00 am
by sbesson
Hi Yuriy,

answering your first question, I know writing back results into OMERO has been mentioned in the projects you listed. I can't point you at any code that is concretely doing so at the moment.

regarding your second point, my experience is that people have two classical representation of masks. Either it is displayed an image with some transparency usually or the mask contours are computed and rendered as lines. As you said, there is nothing ground-breaking there, the biggest problem is as usual the amount of resources (people and time) required for its implementation.

Finally, here is a code example to set and retrieve the description of a ROI
Code: Select all
roi = omero.model.RoiI()
roi.setDescription(rstring('a roi description'));
description = char(roi.getDescription().getValue());


Sebastien

Re: managing ROIs

PostPosted: Tue Jul 16, 2013 10:03 am
by sbesson
Right. Here's another code examples to set/get text values on a Mask shape:

Code: Select all
shape = createMask(ones(512,512));
shape.setTextValue(rstring('a mask'));
value = char(shape.getTextValue().getValue());


Sebastien

Re: managing ROIs

PostPosted: Tue Jul 16, 2013 3:14 pm
by yuriy_alexandrov
many thanks Sebastien,

it looks OK now.

At least, when Segmentation Community solves the problem of working with lifetime-featured images + storing the ROIs in Omero, - we will be able to pick up these advanced segmentations.
For now we just managing ours.

Best,
Y.