holoviz-topics / EarthSim

Tools for working with and visualizing environmental simulations.
https://earthsim.holoviz.org
BSD 3-Clause "New" or "Revised" License
65 stars 21 forks source link

GrabCut Dashboard #186

Closed jlstevens closed 5 years ago

jlstevens commented 6 years ago

This PR demonstrates how the interactive visualizations developed and used in the notebooks can be made to work as dashboards served using bokeh server. It also demonstrates how a workflow can be made to work in stages using multiple browser tabs.

Stage 1:

image

Stage 2 (based on the region selected in stage 1):

image

(Obviously this is just showing that grab cut works as this is not a useful contour!)

The third stage (development in progress) will be to mesh the chosen contour into a trimesh.

Currently, my biggest obstacle for these first two stages is that I cannot slice the selected tile returned by quest (due to what look like incorrect coordinates) as described in https://github.com/pyviz/EarthSim/pull/174.

kcpevey commented 6 years ago

This selection for bbox (-88.9216878421812, 30.459612315305694, -88.91979601215786, 30.461269942946736)

SelectRegionPlot(height=700, magnification=1, name='SelectRegionPlot03873', tile_server='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}', width=900, zoom_level=18)

Results in this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-22df9bcf3676> in <module>()
      1 try:
----> 2     tiff_path = grabcut.GrabCutDashboard.tiff_from_bbox(selection.tile_server, selection.zoom_level, selection.bbox)
      3 #     tiff_path = grabcut.GrabCutDashboard.tiff_from_bbox(selection.tile_server, 13, selection.bbox)
      4 except ValueError:
      5     print('Using a default example over Quebec')

c:\projects\ers\github\earthsim\grabcut\earthsim\earthsim\grabcut.py in tiff_from_bbox(cls, tile_server, zoom_level, bbox)
    184         meta = quest.api.get_metadata(staged_id)
    185         file_path = meta[download_id].get('file_path',None)
--> 186         if not os.path.isfile(file_path):
    187             print('Error: No TIFF downloaded')
    188         return file_path

C:\ProgramData\Anaconda3\envs\earthsimAUG\lib\genericpath.py in isfile(path)
     28     """Test whether a path is a regular file"""
     29     try:
---> 30         st = os.stat(path)
     31     except OSError:
     32         return False

TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

Strangely enough, if I rerun the cell without changing the bbox, it doesn't throw an error again.

kcpevey commented 6 years ago

Need to add bounds to minimum_size = param.Integer(default=10, bounds=(0, 1000)) (line 145 in grabcut.py). Re: https://github.com/pyviz/panel/issues/33

kcpevey commented 6 years ago

This error from above TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType happens when the zoom level is a really low number for an image that is highly zoomed in.

jlstevens commented 6 years ago

@kcpevey Thanks for reporting these issues! I trust that these errors appear in those particular edge cases (e.g that bbox and when zoomed in a lot) and is otherwise (mostly) working?

kcpevey commented 6 years ago

@jlstevens I'm not seeing any other errors, but I do suspect there is another tricky bug in there somewhere. Occasionally the update contour button doesn't work (nothing appears on the right). I know that it can take a lot of time with no feedback, but this is NOT that. Basically, the update contour button randomly decides to stop working no matter how long I wait. Usually if I pan around a bit, mess with the min size slider, and click the filter contour button a few times and maybe throw in one more update contour for kicks, then it will run properly again and polygons will appear on the right.

In summary - I think there's a bug, but its so elusive I haven't been able to even begin to track it down.

kcpevey commented 6 years ago

Also, a minor suggestion - I'd like the ability to instantiate the grabcut dashboard with drawn bbox. I'm working to have the workflows set up to be able to be run as-is if the user would just like to check things out. This is particularly important with the grabcuts tool because finding a land/water region which is appropriate can take effort (e.g. coloration difference between land/water is significant)

kcpevey commented 6 years ago

It seems like the zoom level that's being selected is lower than what I anticipate. At one point, I drew a bbox and the resulting image was literally 6 giant pixels. I messed around a bit and redrew roughly the same box and I got a reasonable image (see below). I can't make the giant pixel (poor zoom level selection) happen again, but I did see something similar happen the other day as well. grabcut

kcpevey commented 6 years ago

I apologize for my vague reporting, I just can't seem to track anything down. Strange things are happening and I'm not sure why, but I will continue to try and figure it out and report back any findings. An example of strange behavior is this image below. I see no reason why grabcut doesn't pick up the left river bank.
grabcut2

kcpevey commented 6 years ago

And then this when I tried to correct it:
grabcut3

kcpevey commented 6 years ago

Just did this:
grabcut5a
And got this:
grabcut5b

Then after running a cell with this:

rgb = grabcut.GrabCutDashboard.tiff_to_rgb(tiff_path)
grabcuts = grabcut.GrabCutDashboard(rgb, fg_data=[], bg_data=[], height=600,
                                              name='GrabCut Extractor', minimum_size=200)
panel.Column(grabcuts, grabcuts.view())

I immediately double checked selection.zoom_level and it had reset itself to 14 (which is what it should have been). So there is some issue with the zoom level not being set at the correct time.

jlstevens commented 6 years ago

@kcpevey I have encountered the bug where the zoom level was clearly wrong but it only happened once to me.

As that was the only time I saw the issue myself (and haven't seen it since) I had hoped it was a bug that has since got fixed. Thanks for confirming that it continues to happen sporadically: I now know it still needs tracking down!

philippjfr commented 5 years ago

I'll close in favor of #253 but won't delete the branch in case there's anything we want to reuse from this dashboard in the future.