Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added _repr_html_ method for _ImageWrapper #394

Merged
merged 6 commits into from
Apr 24, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10426,6 +10426,107 @@ def getROICount(self, shapeType=None, filterByCurrentUser=False):
return count[0][0].getValue()
return len(self._get_rois(shapeType, filterByCurrentUser))

def _repr_html_(self):
import base64

html_style_header = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Details</title>
<style>
img {
min-width: 250px; /* Set the minimum width for all images */
min-height: 250px; /* Set the minimum height for all images */
}
.align-top {
vertical-align: top;
}
.text-right {
text-align: right;
}
</style>
</head>
"""

# create a sub-table for image information
table_imageinfo = f"""
<table>\n
<tr>\n
<td><b>Image name: </b></td> <td class=text-right>{self.getName()}</td>\n
</tr>\n
<tr>\n
<td><b>Image ID: </b></td> <td class=text-right>{self.getId()}</td>\n
</tr>\n
<tr>\n
<td><b>Project ID: </b></td> <td class=text-right>{self.getProject().getId()}</td>\n
jo-mueller marked this conversation as resolved.
Show resolved Hide resolved
</tr>\n
</table>
"""

# get entries for thumbnail and dimensions
encoded_image = base64.b64encode(self.getThumbnail()).decode('utf-8')
dimensions = f"""(
{self.getSizeT()},
{self.getSizeC()},
{self.getSizeZ()},
{self.getSizeY()},
{self.getSizeX()})"""
physical_dims = """({:.3f}, {:.3f}, {:.3f})""".format(
self.getPixelSizeZ(),
self.getPixelSizeY(),
self.getPixelSizeX())
physical_units = f"""(
{self.getPixelSizeZ(units=True).getUnit()},
{self.getPixelSizeY(units=True).getUnit()},
{self.getPixelSizeX(units=True).getUnit()})"""

table_dimensions = f"""
<table>\n
<tr>\n
<td><b>Dimensions (TCZYX): </b></td> <td class=text-right>{dimensions}</td>\n
</tr>\n
<tr>\n
<td><b>Voxel/Pixel dimensions (ZYX): </b></td> <td class=text-right>{physical_dims}</td>\n
</tr>\n
<tr>\n
<td><b>Physical units: </b></td> <td class=text-right>{physical_units}</td>\n
</tr>\n
<tr>\n
<td><b>Channel Names: </b></td> <td class=text-right>{self.getChannelLabels()}</td>\n
</tr>\n
</table>
"""

table_assembly = f"""
<table>
<tr>
<td><div class="thumbnail">
<img src="data:image/jpeg;base64,{encoded_image}" alt="Thumbnail">
</div></td>
<td class="align-top"><h2>Image information </h2>
{table_imageinfo}
</td>
</tr>
</table>
<table>
<tr>
<td>{table_dimensions}</td>
</tr>
</table>
"""

return '\n'.join([
html_style_header,
'<body>',
table_assembly,
'</body>',
'</html>'
])


ImageWrapper = _ImageWrapper

# INSTRUMENT AND ACQUISITION #
Expand Down
Loading