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

Add the GrabCut example #193

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
16 changes: 8 additions & 8 deletions grabcut/grabcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from holoviews.core.spaces import DynamicMap
from holoviews.core.util import pd
from holoviews.element.util import split_path
from holoviews.operation.datashader import ResamplingOperation, rasterize, regrid
from holoviews.operation.datashader import ResampleOperation2D, rasterize, regrid
from holoviews.operation import contours
from holoviews.streams import FreehandDraw, BoxEdit
from shapely.geometry import Polygon, LinearRing, MultiPolygon
Expand Down Expand Up @@ -73,7 +73,7 @@ def paths_to_polys(path):
return path.clone(polys_with_holes, new_type=gv.Polygons)


class rasterize_polygon(ResamplingOperation):
class rasterize_polygon(ResampleOperation2D):
"""
Rasterizes Polygons elements to a boolean mask using PIL
"""
Expand Down Expand Up @@ -320,8 +320,8 @@ def view(self):
dmap = hv.DynamicMap(self.extract_foreground)
dmap = hv.util.Dynamic(dmap, operation=self._filter_contours)
dmap = hv.util.Dynamic(dmap, operation=self._simplify_contours)
return (regrid(self.image).options(**options) * self.bg_paths * self.fg_paths +
Copy link
Contributor

@ahuang11 ahuang11 Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the regrid add here? It kept making the shapes mismatched and took me forever to find what caused the shape mismatches :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably to make it possible to display really large images without causing issues in the browser? That would be my initial guess at least.

dmap.options(**options))
return (self.image.opts(**options) * self.bg_paths * self.fg_paths +
dmap.opts(**options))

@param.output(polys=hv.Path)
def output(self):
Expand Down Expand Up @@ -372,12 +372,12 @@ class SelectRegionPanel(param.Parameterized):

def __init__(self, poly_data=[], **params):
super(SelectRegionPanel, self).__init__(**params)
self.boxes = gv.Polygons(poly_data).options(
self.boxes = gv.Polygons(poly_data).opts(
fill_alpha=0.5, color='grey', line_color='white',
line_width=2, width=self.width, height=self.height
)
if not self.boxes:
self.boxes = self.boxes.options(global_extent=True)
self.boxes = self.boxes.opts(global_extent=True)
self.box_stream = BoxEdit(source=self.boxes, num_objects=1)

@classmethod
Expand Down Expand Up @@ -455,7 +455,7 @@ def get_image(self):
return img

def view(self):
return (gv.DynamicMap(self.callback) * self.boxes).options(active_tools=['wheel_zoom'])
return (gv.DynamicMap(self.callback) * self.boxes).opts(active_tools=['wheel_zoom'])

@param.output(image=hv.Image)
def output(self):
Expand All @@ -465,7 +465,7 @@ def panel(self):
return pn.Row(self.param, self.view())


options = Store.options('bokeh')
options = Store.opts('bokeh')

options.Points = Options('plot', padding=0.1)
options.Path = Options('plot', padding=0.1)
Expand Down