%create the JAVA object
omero = omeroconnect.Main;

%connect to the server as user X
omero.initConnectionDetails('cmpdartsvr1.cmp.uea.ac.uk', 'avondoj', 'avondo');

%get the whole database belonging to this user
omerodatabase = omero.getDatabase();

%print it to screen
omero.printDatabase(omerodatabase);

%get the Image at id 1
imgscr = omero.getImage(1);

%make a copy of this image on the server
imgdst = omero.copyImage(imgscr);

%now iterate over all the planes
%and do some image processing.
figure(1);
for z=1:omero.getZ(imgscr),
    for t=1:omero.getT(imgscr),
        for c=1:omero.getC(imgscr),
            
            %get the source image plane
            plane = double(omero.getPlane(imgscr, z-1, c-1, t-1));
            
            %and convert it to a matlab friendly image
            plane = reshape(plane, omero.getX(imgscr), omero.getY(imgscr));
            
            %do an sobel edge detector on it
            plane = edge(plane, 'sobel');
            
            %scale the binary result (0->1) back to (0->255)
            plane = plane(:,:) * 255;
            
            %lets show our output as we go along.
            figure(1);
            imshow(plane);
            drawnow;
            
            %and save this processed plane in our destination image
            omero.setPlane(imgdst, plane, z-1, c-1, t-1);
        end
    end
end

%now close the connection
omero.closeConnection();