I am sorry if I am reposting the question but search engine wouldn't let me search for any keyword that would help me.
Currently I am writing some Java code that I want to use to download OME-tiff images from the OMERO server using omero client Java APIs. I looked through some examples and I am just not sure what is the way (or the best way to try to do this). This is my example scenario. I've uploaded a number of images into OMERO server and put them all in one Project/Dataset. I did not do any modification to them in OMERO so they are as they were when I uploaded them. Now what I want to do is connect to the server, get the dataset using its OMERO ID and then iterate through the images contained in that dataset and save each of those images on my local file system. What I've done so far is I've created my session object
- Code: Select all
this.conn = new omero.client(this.hostname, this.port);
this.session = conn.createSession(username, password);
Then I used the example code provided in schoola documentation to retrieve a dataset using its ID and the get images contained within:
- Code: Select all
IContainerPrx proxy = this.session.getContainerService();
ParametersI param = new ParametersI();
param.leaves();
List<omero.model.IObject> results = proxy.loadContainerHierarchy(Dataset.class.getName(), Arrays.asList(datasetid), param);
if (results.size() == 0) return null;
DatasetData dataset = new DatasetData((Dataset) results.get(0));
Set<ImageData> images = dataset.getImages();
Iterator<ImageData> j = images.iterator();
And then for the last bit I just iterated over those images trying to download them. I used two different approaches:
- Code: Select all
ImageData image;
while (j.hasNext()) {
image = j.next();
File newfile = new File(tempdir.getAbsolutePath() + File.separator + image.getName());
this.conn.download(image.getId(), newfile);
}
This works and it does download "things" but this doesn't always give me the actual tiff file. It sometimes just gives me a metadata block, some script or some XML file.
Other approach I used was with the RawFileStorePrx object:
- Code: Select all
ImageData image;
while (j.hasNext()) {
image = j.next();
RawFileStorePrx filestore = this.session.createRawFileStore();
filestore.setFileId(image.getId());
byte[] imagebytes = new byte[(int) filestore.size()];
FileOutputStream fos = new FileOutputStream(tempdir.getAbsolutePath() + File.separator + image.getName());
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
imagebytes = filestore.read(0, (int) filestore.size());
dest.write(imagebytes.length);
}
But as it was the case with other example this just doesn't give me the actual content of the image and I just get odd metadata/script/XML file instead.
Once I have this working I will be attempting to use my code to upload ome-tiff files to OMERO server so if anyone can think of some pointers there it would be great. All I need is sample code or link to some part of OMERO documentation that would help me out with this and I will be set.
Any help with pointing me in the right direction would be appreciated,
Regards,
Slavisa