sketchkit.image2sketch.hed package

Submodules

sketchkit.image2sketch.hed.model module

HED (Holistically Nested Edge Detection) integration.

This module wraps the original Caffe implementation using OpenCV’s DNN loader. It mirrors the public API of other image-to-sketch backends and is selected with SketchGenerator(method="HED").

class sketchkit.image2sketch.hed.model.HEDModel(*, checkpoint_dir: str | PathLike | None = None, auto_download: bool = True, postprocess: bool = True, postprocess_threshold: float = 0.09803921568627451, postprocess_small_edge: int = 5)[source]

Bases: object

High level wrapper around the original HED Caffe model.

MEAN_BGR = (104.00698793, 116.66876762, 122.67891434)
MODEL_FILENAME = 'hed_pretrained_bsds.caffemodel'
MODEL_SHA1 = '2c5d7842f25f880eec62fc610b500c5cf2aa351d'
MODEL_URL = 'https://vcl.ucsd.edu/hed/hed_pretrained_bsds.caffemodel'
static _download_weights(url: str, destination: Path, expected_sha1: str) None[source]
_infer_single(net: Any, image: Image, size: Tuple[int, int]) Image[source]
_initialise_net() Any[source]
_net: Any | None
static _to_pil_image(image: Image | ndarray | str | PathLike) Image[source]
static _validate_sha1(path: Path, expected_hex: str) bool[source]
property checkpoint_dir: Path
ensure_assets() None[source]

Ensure the pretrained weights are available locally.

generate(image: Image | ndarray | str | PathLike | Sequence[Image | ndarray | str | PathLike], *, size: int | Tuple[int, int] | None = None) Image | List[Image][source]

Generate edge maps for the provided image(s).

sketchkit.image2sketch.hed.postprocess module

HED post-processing pipeline

class sketchkit.image2sketch.hed.postprocess.PostprocessParams(threshold: float = 0.09803921568627451, small_edge: int = 5, nms_radius: int = 1, nms_border: int = 5, nms_multiplier: float = 1.01, smooth_radius: float = 4.0)[source]

Bases: object

Configuration mirroring the defaults from PostprocessHED.m.

nms_border: int = 5
nms_multiplier: float = 1.01
nms_radius: int = 1
small_edge: int = 5
smooth_radius: float = 4.0
threshold: float = 0.09803921568627451
sketchkit.image2sketch.hed.postprocess.apply_postprocess(edge_map: ndarray, *, params: PostprocessParams = PostprocessParams(threshold=0.09803921568627451, small_edge=5, nms_radius=1, nms_border=5, nms_multiplier=1.01, smooth_radius=4.0)) ndarray[source]

Apply the official HED post-processing steps.

Parameters:
  • edge_map – Single-channel array in the range [0, 1] representing raw HED edge probabilities.

  • params – Tunable parameters. Defaults replicate the MATLAB script.

Returns:

Float32 array in [0, 1] where 1 denotes white background and 0 denotes edge strokes.

Return type:

np.ndarray

Module contents

Public entry points for the HED image2sketch backend.

class sketchkit.image2sketch.hed.HEDModel(*, checkpoint_dir: str | PathLike | None = None, auto_download: bool = True, postprocess: bool = True, postprocess_threshold: float = 0.09803921568627451, postprocess_small_edge: int = 5)[source]

Bases: object

High level wrapper around the original HED Caffe model.

MEAN_BGR = (104.00698793, 116.66876762, 122.67891434)
MODEL_FILENAME = 'hed_pretrained_bsds.caffemodel'
MODEL_SHA1 = '2c5d7842f25f880eec62fc610b500c5cf2aa351d'
MODEL_URL = 'https://vcl.ucsd.edu/hed/hed_pretrained_bsds.caffemodel'
static _download_weights(url: str, destination: Path, expected_sha1: str) None[source]
_infer_single(net: Any, image: Image, size: Tuple[int, int]) Image[source]
_initialise_net() Any[source]
_net: Any | None
static _to_pil_image(image: Image | ndarray | str | PathLike) Image[source]
static _validate_sha1(path: Path, expected_hex: str) bool[source]
property checkpoint_dir: Path
ensure_assets() None[source]

Ensure the pretrained weights are available locally.

generate(image: Image | ndarray | str | PathLike | Sequence[Image | ndarray | str | PathLike], *, size: int | Tuple[int, int] | None = None) Image | List[Image][source]

Generate edge maps for the provided image(s).