@@ -217,3 +217,111 @@ def propertiesToDict(m, prefix=None):
217
217
except :
218
218
d [items [- 1 ]] = value
219
219
return nested_dict
220
+
221
+ def image_to_html (image ):
222
+ import base64
223
+
224
+ try :
225
+ pixsizeX = '{:.3f}' .format (image .getPixelSizeX ())
226
+ pixsizeY = '{:.3f}' .format (image .getPixelSizeY ())
227
+ pixsizeZ = '{:.3f}' .format (image .getPixelSizeZ ())
228
+ UnitX = image .getPixelSizeX ().getUnit ()
229
+ UnitY = image .getPixelSizeY ().getUnit ()
230
+ UnitZ = image .getPixelSizeZ ().getUnit ()
231
+ except :
232
+ pixsizeX , pixsizeY , pixsizeZ = 'na' , 'na' , 'na'
233
+ UnitX , UnitY , UnitZ = 'na' , 'na' , 'na'
234
+
235
+ html_style_header = """
236
+ <!DOCTYPE html>
237
+ <html lang="en">
238
+ <head>
239
+ <meta charset="UTF-8">
240
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
241
+ <title>Image Details</title>
242
+ <style>
243
+ img {
244
+ min-width: 250px; /* Set the minimum width for all images */
245
+ min-height: 250px; /* Set the minimum height for all images */
246
+ }
247
+ .align-top {
248
+ vertical-align: top;
249
+ }
250
+ .text-right {
251
+ text-align: right;
252
+ }
253
+ </style>
254
+ </head>
255
+ """
256
+
257
+ def obj_html (obj , otype ):
258
+ return f"""<tr>
259
+ <td><b>{ otype } </b></td>
260
+ <td class=text-right>{ obj .id if obj else "" } </td>
261
+ <td class=text-right>{ obj .name if obj else "" } </td>
262
+ </tr>
263
+ """
264
+
265
+ # create a sub-table for image information
266
+ table_imageinfo = f"""
267
+ <table>
268
+ <tr><th></th><th>ID</th><th>Name</th></tr>
269
+ { obj_html (image , 'Image' )}
270
+ { obj_html (image .getParent (), 'Dataset' )}
271
+ { obj_html (image .getProject (), 'Project' )}
272
+ </table>
273
+ """
274
+
275
+ # get entries for thumbnail and dimensions
276
+ encoded_image = base64 .b64encode (image .getThumbnail ()).decode ('utf-8' )
277
+ dimensions = f"""(
278
+ { image .getSizeT ()} ,
279
+ { image .getSizeC ()} ,
280
+ { image .getSizeZ ()} ,
281
+ { image .getSizeY ()} ,
282
+ { image .getSizeX ()} )"""
283
+ physical_dims = f"""({ pixsizeZ } , { pixsizeY } , { pixsizeX } )""" .format ()
284
+ physical_units = f"""({ UnitZ } , { UnitY } , { UnitX } )"""
285
+
286
+ table_dimensions = f"""
287
+ <table>\n
288
+ <tr>\n
289
+ <td><b>Dimensions (TCZYX): </b></td> <td class=text-right>{ dimensions } </td>\n
290
+ </tr>\n
291
+ <tr>\n
292
+ <td><b>Voxel/Pixel dimensions (ZYX): </b></td> <td class=text-right>{ physical_dims } </td>\n
293
+ </tr>\n
294
+ <tr>\n
295
+ <td><b>Physical units: </b></td> <td class=text-right>{ physical_units } </td>\n
296
+ </tr>\n
297
+ <tr>\n
298
+ <td><b>Channel Names: </b></td> <td class=text-right>{ image .getChannelLabels ()} </td>\n
299
+ </tr>\n
300
+ </table>
301
+ """
302
+
303
+ table_assembly = f"""
304
+ <table>
305
+ <tr>
306
+ <td><div class="thumbnail">
307
+ <img src="data:image/jpeg;base64,{ encoded_image } " alt="Thumbnail">
308
+ </div></td>
309
+ <td class="align-top"><h2>Image information </h2>
310
+ { table_imageinfo }
311
+ </td>
312
+ </tr>
313
+ </table>
314
+ <table>
315
+ <tr>
316
+ <td>{ table_dimensions } </td>
317
+ </tr>
318
+ </table>
319
+ """
320
+
321
+ return '\n ' .join ([
322
+ html_style_header ,
323
+ '<body>' ,
324
+ table_assembly ,
325
+ '</body>' ,
326
+ '</html>'
327
+ ])
0 commit comments