Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

Commit

Permalink
playing around with jpeg2000 based imageview for bokeh dpt
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalkolar committed Apr 18, 2021
1 parent 8c5e6ba commit 4e75b89
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions mesmerize/plotting/web_widgets/datapoint_tracer.py
@@ -1,7 +1,7 @@
from bokeh.plotting import figure, Figure
from bokeh.models.glyphs import Image, MultiLine
from bokeh.models import HoverTool, ColumnDataSource, TapTool, Slider, TextInput, Select, \
BoxAnnotation, Patches
BoxAnnotation, Patches, Div
from bokeh.models.mappers import LogColorMapper
from bokeh.layouts import gridplot, column, row
import os
Expand All @@ -15,7 +15,8 @@
from mesmerize.plotting.web_widgets.core import BokehCallbackSignal, WebPlot
import logging
import pickle

from pathlib import Path
import skimage.io

logger = logging.getLogger()

Expand All @@ -33,6 +34,13 @@
tools='tap,hover,pan,wheel_zoom,box_zoom,reset',
)

div = Div(text="""<div class="videoWrapper">
<iframe width="420" height="315" src="http://8d30867d13b5.ngrok.io/odor_by_11122019_a3-_-1.mp4" frameborder="0" allowfullscreen></iframe>
</div>""",
width=420, height=315)

seq_path = Path('/work/kushal/jpeg_seq_mono_jp2')


def get_numerical_columns(dataframe: pd.DataFrame):
return [c for c in dataframe.columns if c.startswith('_')]
Expand Down Expand Up @@ -75,7 +83,6 @@ def __init__(
**{
**_default_image_figure_params,
**image_figure_params,
'output_backend': "webgl"
}
)

Expand All @@ -86,6 +93,7 @@ def __init__(
image=[empty_img],
x=0, y=0,
dw=10, dh=10,
palette="Inferno256",
level="image"
)

Expand Down Expand Up @@ -208,23 +216,24 @@ def set_sample(self, dataframe: pd.DataFrame):
self.label_sample_id.update(value=self.sample_id)

def _set_video(self, vid_path: Union[Path, str]):
self.tif = tifffile.TiffFile(vid_path)
#self.tif = tifffile.TiffFile(vid_path)

self.current_frame = 0
self.frame = self.tif.asarray(key=self.current_frame)
#self.frame = self.tif.asarray(key=self.current_frame)
self.frame = skimage.io.imread(seq_path.joinpath('0'.zfill(6) + '.jp2'))

# this is basically used for vmin mvax
self.color_mapper = LogColorMapper(
palette=auto_colormap(256, 'gnuplot2', output='bokeh'),
low=np.nanmin(self.frame),
high=np.nanmax(self.frame)
palette=auto_colormap(256, 'jet', output='bokeh'),
low=0,#np.nanmin(self.frame),
high=200#np.nanmax(self.frame)
)

self.image_glyph.data_source.data['image'] = [self.frame]
self.image_glyph.glyph.color_mapper = self.color_mapper
#self.image_glyph.glyph.color_mapper = self.color_mapper

# shows the file size in gigabytes
self.label_filesize.update(value=str(os.path.getsize(vid_path) / 1024 / 1024 / 1024))
#self.label_filesize.update(value=str(os.path.getsize(vid_path) / 1024 / 1024 / 1024))

def _get_roi_coors(self, r: pd.Series):
roi_type = r['roi_type']
Expand Down Expand Up @@ -272,9 +281,9 @@ def _update_plot_options(self):

def _set_current_frame(self, i: int):
self.current_frame = i
frame = self.tif.asarray(key=self.current_frame, maxworkers=20)

self.image_glyph.data_source.data['image'] = [frame]
#frame = self.tif.asarray(key=self.current_frame, maxworkers=20)
self.frame = skimage.io.imread(seq_path.joinpath(str(i).zfill(6) + '.jp2'))
self.image_glyph.data_source.data['image'] = [self.frame]

def _get_trimmed_dataframe(self) -> pd.DataFrame:
"""
Expand Down

0 comments on commit 4e75b89

Please sign in to comment.