[ome-devel] set pixels size Java API

Dominik Lindner (Staff) d.lindner at dundee.ac.uk
Wed Feb 6 10:29:55 GMT 2019


Hi Thomas,

that looks like a bug in the PixelsData class. It seems the getPixelSize methods
create a new Length object instead of returning the existing one, so subsequent
save operations won't save it. I'll have to find out why.
For now a workaround would be to get the omero.model.Pixels and set the pixel
sizes directly there, circumventing the PixelData methods.

PixelsData pixels = imageData.getDefaultPixels();
Pixels ipixels = pixels.asPixels();
ipixels.getPhysicalSizeX().setValue(1);
ipixels.getPhysicalSizeX().setUnit(UnitsLength.MICROMETER);
gateway.getUpdateService(securityContext).saveObject(ipixels);

Regards,
Dominik

> On 5 Feb 2019, at 23:28, Thomas Boudier <boudier.t at wehi.edu.au> wrote:
>
> Dear OMERO developers,
>
> I would like to update the pixels sizes for some images, I tried to
> convert in Java the code posted here
> https://www.openmicroscopy.org/community/viewtopic.php?f=6&t=7616&p=16966&hilit=pixel+size#p16966
>
> but it does not seem to work, there is no error, but the pixels sizes of
> the image is not updated in OMERO :
>
> public boolean setResolutionImageUM(ImageData imageData, double resXY,
> double resZ) {
>         try {
>             // get the pixels
>             RawDataFacility rdf =
> gateway.getFacility(RawDataFacility.class);
>             PixelsData pixels = imageData.getDefaultPixels();
>             // change their properties
>             Length pixelsX = pixels.getPixelSizeX(UnitsLength.MICROMETER);
>             pixelsX.setValue(resXY);
>             pixelsX.setUnit(UnitsLength.MICROMETER);
>             Length pixelsY = pixels.getPixelSizeY(UnitsLength.MICROMETER);
>             pixelsY.setValue(resXY);
>             pixelsY.setUnit(UnitsLength.MICROMETER);
>             Length pixelsZ = pixels.getPixelSizeZ(UnitsLength.MICROMETER);
>             pixelsZ.setValue(resZ);
>             pixelsZ.setUnit(UnitsLength.MICROMETER);
>             // update database
> gateway.getUpdateService(securityContext).saveObject(pixels.asIObject());
>         } catch (ExecutionException e) {
>             e.printStackTrace();
>             return false;
>         } catch (BigResult bigResult) {
>             bigResult.printStackTrace();
>             return false;
>         } catch (DSOutOfServiceException e) {
>             e.printStackTrace();
>             return false;
>         } catch (ServerError serverError) {
>             serverError.printStackTrace();
>             return false;
>         }
>
>         return true;
>     }
>
> Thanks for any help.
>
> Best,
>
> Thomas
>
> --
> /***************************************************************/
>       Thomas Boudier, Senior Research Officer,
>       BioImage Analysis, Dynamic Imaging Centre,
>       Walter and Eliza Hall Institute (WEHI), Australia.
> /**************************************************************/
>
>
> _______________________________________________
>
> The information in this email is confidential and intended solely for the addressee.
> You must not disclose, forward, print or use it without the permission of the sender.
>
> The Walter and Eliza Hall Institute acknowledges the Wurundjeri people of the Kulin
> Nation as the traditional owners of the land where our campuses are located and
> the continuing connection to country and community.
> _______________________________________________
> _______________________________________________
> ome-devel mailing list
> ome-devel at lists.openmicroscopy.org.uk
> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel


The University of Dundee is a registered Scottish Charity, No: SC015096


More information about the ome-devel mailing list