-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from BiAPoL/add-pixel-size-setting-demo
Tutorial on how to set pixel sizes
- Loading branch information
Showing
4 changed files
with
392 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Setting pixel sizes of an image\n", | ||
"\n", | ||
"A key part of the metadata are the pixel/voxel sizes of image data. When upload processed image data to OMERO, they are by default not part of the uploaded data but a key part you wish to add to your data. Following up [this dicsussion](https://forum.image.sc/t/specifying-pixel-size-using-python-bridge-for-omero-ezomero/81729/2) on image.sc, here's how you can do it using [omero-py](https://pypi.org/project/omero-py/):" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import omero\n", | ||
"import ezomero\n", | ||
"\n", | ||
"from omero.model.enums import UnitsLength" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"host = 'omero-int.biotec.tu-dresden.de'\n", | ||
"user = '' # replace this with your username\n", | ||
"secure = True\n", | ||
"port = 4064\n", | ||
"group = 'default'\n", | ||
"\n", | ||
"conn = ezomero.connect(host=host, user=user, secure=secure, port=port, group=group)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We first need to retrieve the remote object:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"image_object = conn.getObject(\"Image\", 330)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"If there are already pixel sizes set, you can retrieve them like this:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Pixel size X: 0.2\n", | ||
"Pixel size Y: 0.2\n", | ||
"Pixel size Z: 2.0\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print('Pixel size X: ', image_object.getPixelSizeX())\n", | ||
"print('Pixel size Y: ', image_object.getPixelSizeY())\n", | ||
"print('Pixel size Z: ', image_object.getPixelSizeZ())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"If you want to set them yourself, you can do it like this:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"unit_x = omero.model.LengthI(0.5, UnitsLength.MICROMETER)\n", | ||
"unit_y = omero.model.LengthI(0.5, UnitsLength.MICROMETER)\n", | ||
"unit_z = omero.model.LengthI(3, UnitsLength.MICROMETER)\n", | ||
"\n", | ||
"primary_pixels_object = image_object.getPrimaryPixels()._obj\n", | ||
"primary_pixels_object.setPhysicalSizeX(unit_x)\n", | ||
"primary_pixels_object.setPhysicalSizeY(unit_y)\n", | ||
"primary_pixels_object.setPhysicalSizeZ(unit_z)\n", | ||
"\n", | ||
"# update the image object\n", | ||
"conn.getUpdateService().saveObject(primary_pixels_object)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We can doublecheck whether this worked:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 15, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Pixel size X: 0.5\n", | ||
"Pixel size Y: 0.5\n", | ||
"Pixel size Z: 3.0\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"image_object = conn.getObject(\"Image\", 330)\n", | ||
"\n", | ||
"print('Pixel size X: ', image_object.getPixelSizeX())\n", | ||
"print('Pixel size Y: ', image_object.getPixelSizeY())\n", | ||
"print('Pixel size Z: ', image_object.getPixelSizeZ())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "omero", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.19" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.