Created
January 28, 2019 10:58
-
-
Save kouichi-c-nakamura/4c1355d5f9a47e8087220bb7409f5a63 to your computer and use it in GitHub Desktop.
MATLAB code of editing ROIs using Java Gateway. See Discussion here: https://www.openmicroscopy.org/community/viewtopic.php?f=4&t=8666
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% use Java Gateway from MATLAB | |
host = 'xxxxxxx.xxxx.xxxxx'; | |
userName = 'XXXXXXXX'; | |
password = inputdlg('password:'); | |
password = password{1}; | |
[gateway,user,cred] = loadOmeroGateway(userName, password, host) % https://gist.github.com/kouichi-c-nakamura/c8d335bfe45ee15e3bd86771a8578596 | |
%% Retrieve the list of ROIs attached to an image in a dataset | |
datasetId = 51; | |
import java.util.Arrays | |
% clazz = java.lang.Class.forName('omero.gateway.facility.BrowseFacility', ... | |
% false, gateway.getClass().getClassLoader()) | |
% | |
% browse = gateway.getFacility(clazz); | |
browse = getGatewayFacility(gateway,'BrowseFacility') | |
ctx = omero.gateway.SecurityContext(user.getGroupId()); | |
images = browse.getImagesForDatasets(ctx, Arrays.asList(int64(datasetId))) %NOTE int64() needed to pass long data | |
%ArrayList | |
thisImg = images.get(0); %omero.gateway.model.ImageData | |
roifac = getGatewayFacility(gateway,'ROIFacility') % https://gist.github.com/kouichi-c-nakamura/1fee6b8b33a227d47854224fa185bb94 | |
image = thisImg; | |
% Retrieve the ROIs linked to an image | |
roiresults = roifac.loadROIs(ctx, image.getId()); %ArrayList of omero.gateway.model.ROIResult | |
%% Edit the relevant two LineData ROIs | |
dm = getGatewayFacility(gateway,'DataManagerFacility'); | |
r = roiresults.iterator().next(); | |
if isempty(r) | |
return;%TODO | |
end | |
rois = r.getROIs(); | |
j = rois.iterator(); | |
k = 0; | |
ind = zeros(1,2); | |
while j.hasNext() | |
k = k + 1; | |
roi = j.next(); | |
alist = roi.getShapes(0,0); | |
% Do something | |
shape = alist.get(0); | |
if isa(shape,'omero.gateway.model.LineData') | |
% disp(methods(shape) ) | |
switch shape.getX1() | |
case 15000 | |
assert(shape.getX2() == 15000) | |
shape.setText('Bregma') % added Text to the LineData | |
disp(k) | |
ind(1) = k - 1; | |
case 20900 | |
assert(shape.getX2() == 20900) | |
shape.setText('Interaural') % added Text to the LineData | |
disp(k) | |
ind(2) = k - 1; | |
end | |
end | |
end | |
bregma = rois.get(ind(1)).getShapes(0,0).get(0); | |
interaural = rois.get(ind(2)).getShapes(0,0).get(0); | |
ss1 = bregma.getShapeSettings; | |
ss1.setStroke(java.awt.Color.YELLOW) % set new stroke color of the LineData | |
ss2 = interaural.getShapeSettings; | |
ss2.setStroke(java.awt.Color.YELLOW) % set new stroke color of the LineData | |
% now the editing is done | |
%% save the edited ROIs after reloading | |
newRoiList = java.util.ArrayList; | |
newRoiList.add(rois.get(ind(1))) | |
newRoiList.add(rois.get(ind(2))) | |
roifac.saveROIs(ctx,int64(image.getId),newRoiList) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment