Documentation
¶
Overview ¶
Package saliency2 is a standard-library-only toolkit of visual saliency and attention algorithms built on top of the parent cv package's cv.Mat image type.
Saliency estimation predicts where a human observer's gaze is drawn in an image: bright, novel, high-contrast or moving regions "pop out" from their surroundings. This package collects the classic static and dynamic saliency models, plus an objectness proposal generator and a set of reusable post-processing operators, all implemented from scratch against the Go standard library (image, math, math/cmplx). There is no cgo, no third-party dependency and no GPU requirement; every routine is deterministic and CPU-only.
Detectors ¶
The static single-image detectors implement the StaticSaliency interface and each return a single-channel saliency map the same size as the input:
- StaticSaliencySpectralResidual — Hou & Zhang's spectral-residual model (CVPR 2007), operating in the Fourier domain.
- StaticSaliencyFineGrained — Montabone & Soto's multi-scale center-surround contrast (Image and Vision Computing 2010).
- StaticSaliencyFrequencyTuned — Achanta et al.'s frequency-tuned model in CIE L*a*b* space (CVPR 2009).
- StaticSaliencyIttiKoch — the Itti-Koch-Niebur center-surround attention model (PAMI 1998) built from intensity, colour-opponency and orientation conspicuity maps.
The ObjectnessBING proposal generator ranks candidate windows by their normed-gradient boundary energy, a lightweight untrained variant of Cheng et al.'s BING (CVPR 2014). The MotionSaliencyByDifference and MotionSaliencyRunningAverage detectors implement the MotionSaliency interface for streaming video.
The SaliencyMap type ¶
SaliencyMap is a single-channel float64 grid used as the common working and result representation. It carries the analysis and post-processing methods (normalisation, thresholding, centre of mass, bounding box) and converts to and from cv.Mat with SaliencyMap.ToMat and SaliencyMapFromMat. Free functions in this package operating on maps — GaussianSmooth, IttiNormalize, CenterPrior and friends — provide the reusable saliency post-processing pipeline.
Conventions ¶
Following the parent package, coordinates are (x, y) with the origin at the top-left, x the column and y the row. Neighbourhood operators replicate the edge sample at the border. Unexported helper identifiers are prefixed with "saliency2" so this package composes cleanly with the rest of the module.
Index ¶
- func FineGrainedSaliency(img *cv.Mat) *cv.Mat
- func FrequencyTunedSaliency(img *cv.Mat) *cv.Mat
- func HeatmapOverlay(img *cv.Mat, m *SaliencyMap, alpha float64) *cv.Mat
- func IttiKochSaliency(img *cv.Mat) *cv.Mat
- func SalientMask(m *SaliencyMap) *cv.Mat
- func SpectralResidualSaliency(img *cv.Mat) *cv.Mat
- type Box
- type MotionSaliency
- type MotionSaliencyByDifference
- type MotionSaliencyRunningAverage
- type Objectness
- type ObjectnessBING
- type SaliencyMap
- func BoxSmooth(m *SaliencyMap, radius int) *SaliencyMap
- func CenterPrior(m *SaliencyMap, sigmaFrac float64) *SaliencyMap
- func CenterSurround(center, surround *SaliencyMap) *SaliencyMap
- func CombineMaps(maps ...*SaliencyMap) *SaliencyMap
- func GammaCorrect(m *SaliencyMap, gamma float64) *SaliencyMap
- func GaussianSmooth(m *SaliencyMap, sigma float64) *SaliencyMap
- func IttiNormalize(m *SaliencyMap) *SaliencyMap
- func LogScale(m *SaliencyMap) *SaliencyMap
- func NewSaliencyMap(rows, cols int) *SaliencyMap
- func NormalizeRange(m *SaliencyMap, lo, hi float64) *SaliencyMap
- func NormedGradient(img *cv.Mat) *SaliencyMap
- func SaliencyMapFromFloatMat(f *cv.FloatMat) *SaliencyMap
- func SaliencyMapFromMat(img *cv.Mat) *SaliencyMap
- func (m *SaliencyMap) AddMap(other *SaliencyMap) *SaliencyMap
- func (m *SaliencyMap) At(y, x int) float64
- func (m *SaliencyMap) BoundingBox(t float64) (rect image.Rectangle, ok bool)
- func (m *SaliencyMap) CenterOfMass() (x, y float64)
- func (m *SaliencyMap) Clone() *SaliencyMap
- func (m *SaliencyMap) Mean() float64
- func (m *SaliencyMap) MeanThreshold(k float64) (mask *cv.Mat, threshold float64)
- func (m *SaliencyMap) MinMax() (min, max float64)
- func (m *SaliencyMap) MultiplyMap(other *SaliencyMap) *SaliencyMap
- func (m *SaliencyMap) Normalize() *SaliencyMap
- func (m *SaliencyMap) OtsuThreshold() (mask *cv.Mat, threshold float64)
- func (m *SaliencyMap) PercentileThreshold(p float64) (mask *cv.Mat, threshold float64)
- func (m *SaliencyMap) Scale(factor float64) *SaliencyMap
- func (m *SaliencyMap) Set(y, x int, value float64)
- func (m *SaliencyMap) Size() (rows, cols int)
- func (m *SaliencyMap) StdDev() float64
- func (m *SaliencyMap) Sum() float64
- func (m *SaliencyMap) Threshold(t float64) *cv.Mat
- func (m *SaliencyMap) ToFloatMat() *cv.FloatMat
- func (m *SaliencyMap) ToMat() *cv.Mat
- type StaticSaliency
- type StaticSaliencyFineGrained
- type StaticSaliencyFrequencyTuned
- type StaticSaliencyIttiKoch
- type StaticSaliencySpectralResidual
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FineGrainedSaliency ¶
FineGrainedSaliency is a convenience wrapper that computes the fine-grained saliency map of img with the default detector settings.
func FrequencyTunedSaliency ¶
FrequencyTunedSaliency is a convenience wrapper that computes the frequency-tuned saliency map of img with the default detector settings.
func HeatmapOverlay ¶
HeatmapOverlay blends a colourised saliency map over a copy of img and returns the three-channel result. alpha (in [0,1]) is the saliency weight: 0 returns the image unchanged, 1 shows the pure heat colours. Salient regions are tinted from blue (low) through green to red (high). The saliency map is resized to the image size if necessary.
func IttiKochSaliency ¶
IttiKochSaliency is a convenience wrapper that computes the Itti-Koch saliency map of img with the default detector settings.
func SalientMask ¶
func SalientMask(m *SaliencyMap) *cv.Mat
SalientMask returns the adaptive binary segmentation of m using the mean-based rule of Achanta et al.: a pixel is foreground when its value is at least twice the map mean. It is a convenience wrapper over SaliencyMap.MeanThreshold with k=2.
Types ¶
type Box ¶
type Box struct {
// Rect is the window in image coordinates (Min inclusive, Max exclusive).
Rect image.Rectangle
// Score is the objectness score; larger is more object-like.
Score float64
}
Box is a scored candidate window produced by an Objectness detector. Higher Score means the window is more likely to tightly bound an object.
type MotionSaliency ¶
type MotionSaliency interface {
// ComputeSaliency ingests the next frame and returns its motion saliency
// map as a single-channel [cv.Mat].
ComputeSaliency(frame *cv.Mat) *cv.Mat
// Reset discards accumulated temporal state so the next frame is treated as
// the start of a new sequence.
Reset()
}
MotionSaliency is implemented by the streaming (video) saliency detectors, mirroring OpenCV's cv::saliency::MotionSaliency. Each frame passed to ComputeSaliency updates the detector's internal state, so frames must be fed in temporal order; Reset clears that state.
type MotionSaliencyByDifference ¶
type MotionSaliencyByDifference struct {
// Sigma is the Gaussian smoothing applied to the difference image; 0
// disables smoothing.
Sigma float64
// contains filtered or unexported fields
}
MotionSaliencyByDifference is a streaming motion-saliency detector based on temporal frame differencing. Each incoming frame is compared against the previous one; the absolute luminance difference — optionally Gaussian smoothed — highlights regions that changed, which for a static camera are the moving objects. It implements the MotionSaliency interface.
Construct one with NewMotionSaliencyByDifference. The first frame of a sequence has no predecessor, so its saliency map is all zeros.
func NewMotionSaliencyByDifference ¶
func NewMotionSaliencyByDifference() *MotionSaliencyByDifference
NewMotionSaliencyByDifference returns a frame-difference detector with a mild sigma-1 smoothing.
func (*MotionSaliencyByDifference) ComputeSaliency ¶
func (m *MotionSaliencyByDifference) ComputeSaliency(frame *cv.Mat) *cv.Mat
ComputeSaliency ingests the next frame and returns its motion saliency map as an 8-bit single-channel cv.Mat. It satisfies the MotionSaliency interface.
func (*MotionSaliencyByDifference) ComputeSaliencyMap ¶
func (m *MotionSaliencyByDifference) ComputeSaliencyMap(frame *cv.Mat) *SaliencyMap
ComputeSaliencyMap ingests the next frame and returns its motion saliency as a SaliencyMap. The first frame yields a zero map. It panics if frame is nil or empty, or if its size differs from earlier frames.
func (*MotionSaliencyByDifference) Reset ¶
func (m *MotionSaliencyByDifference) Reset()
Reset discards the stored previous frame so the next frame starts a new sequence.
type MotionSaliencyRunningAverage ¶
type MotionSaliencyRunningAverage struct {
// Alpha is the background learning rate in [0,1]; smaller values give a
// longer memory and a more stable background.
Alpha float64
// Sigma is the Gaussian smoothing applied to the saliency output; 0
// disables smoothing.
Sigma float64
// contains filtered or unexported fields
}
MotionSaliencyRunningAverage is a streaming motion-saliency detector that compares each frame against an exponentially decaying background model rather than only the immediately preceding frame. The background is updated as bg = (1-Alpha)*bg + Alpha*frame, and saliency is the absolute difference of the current frame from that background. Compared with plain differencing it suppresses the "ghost" trail a moving object leaves behind and tolerates slow illumination change. It implements the MotionSaliency interface.
Construct one with NewMotionSaliencyRunningAverage.
func NewMotionSaliencyRunningAverage ¶
func NewMotionSaliencyRunningAverage() *MotionSaliencyRunningAverage
NewMotionSaliencyRunningAverage returns a running-average detector with a 0.05 learning rate and mild sigma-1 smoothing.
func (*MotionSaliencyRunningAverage) Background ¶
func (m *MotionSaliencyRunningAverage) Background() *cv.Mat
Background returns a snapshot of the current background model as an 8-bit single-channel cv.Mat, or nil before any frame has been ingested.
func (*MotionSaliencyRunningAverage) ComputeSaliency ¶
func (m *MotionSaliencyRunningAverage) ComputeSaliency(frame *cv.Mat) *cv.Mat
ComputeSaliency ingests the next frame and returns its motion saliency map as an 8-bit single-channel cv.Mat. It satisfies the MotionSaliency interface.
func (*MotionSaliencyRunningAverage) ComputeSaliencyMap ¶
func (m *MotionSaliencyRunningAverage) ComputeSaliencyMap(frame *cv.Mat) *SaliencyMap
ComputeSaliencyMap ingests the next frame, updates the background model and returns the frame's motion saliency as a SaliencyMap. The first frame initialises the background and yields a zero map. It panics if frame is nil or empty, or if its size differs from earlier frames.
func (*MotionSaliencyRunningAverage) Reset ¶
func (m *MotionSaliencyRunningAverage) Reset()
Reset discards the background model so the next frame starts a new sequence.
type Objectness ¶
type Objectness interface {
// ObjectnessBoundingBoxes returns candidate object windows ranked by
// decreasing objectness score.
ObjectnessBoundingBoxes(img *cv.Mat) []Box
}
Objectness is implemented by generic object-proposal generators, mirroring OpenCV's cv::saliency::Objectness. It scores and ranks candidate windows that are likely to contain an object of any class.
type ObjectnessBING ¶
type ObjectnessBING struct {
// SizeFractions lists window side lengths as fractions of the smaller image
// dimension. Each pair of fractions also forms non-square windows.
SizeFractions []float64
// MaxBoxes bounds the number of proposals returned.
MaxBoxes int
// NMSThreshold is the intersection-over-union above which a lower-scoring
// window is suppressed by a higher-scoring one.
NMSThreshold float64
}
ObjectnessBING is a lightweight, untrained object-proposal generator in the spirit of Cheng, Zhang, Lin & Torr's BING, "Binarized Normed Gradients for Objectness Estimation at 300fps" (CVPR 2014).
Full BING resizes each candidate window to 8x8 normed gradients and scores it with a learned linear SVM. This dependency-free variant keeps BING's core insight — objects are bounded by closed rings of strong gradient — but replaces the trained filter with a boundary-energy score: a window is rated by the mean normed-gradient sampled along its rectangular border, so windows whose edges snap onto object contours rank highest. Candidate windows are generated at several sizes and aspect ratios, scored, and reduced to a ranked, non-overlapping shortlist with greedy non-maximum suppression.
Construct one with NewObjectnessBING; the zero value is not usable.
func NewObjectnessBING ¶
func NewObjectnessBING() *ObjectnessBING
NewObjectnessBING returns a generator with sensible defaults: window sizes at 1/4, 1/2 and 3/4 of the smaller image side, up to 32 proposals, and an IoU suppression threshold of 0.5.
func (*ObjectnessBING) ComputeSaliency ¶
func (o *ObjectnessBING) ComputeSaliency(img *cv.Mat) *cv.Mat
ComputeSaliency returns the objectness map of img as an 8-bit single-channel cv.Mat, with bright pixels marking likely object-window anchors. It lets ObjectnessBING double as a static saliency source.
func (*ObjectnessBING) ObjectnessBoundingBoxes ¶
func (o *ObjectnessBING) ObjectnessBoundingBoxes(img *cv.Mat) []Box
ObjectnessBoundingBoxes returns candidate object windows for img ranked by decreasing objectness score, after non-maximum suppression. It satisfies the Objectness interface. It panics if img is nil or empty.
func (*ObjectnessBING) ObjectnessMap ¶
func (o *ObjectnessBING) ObjectnessMap(img *cv.Mat) *SaliencyMap
ObjectnessMap returns the normed-gradient boundary-energy field used to score windows: for every pixel it holds the mean gradient along the border of a mid-sized window anchored there. Bright locations are good top-left corners for object windows. It is exposed for visualisation and reuse.
type SaliencyMap ¶
type SaliencyMap struct {
// Rows is the map height.
Rows int
// Cols is the map width.
Cols int
// Data holds Rows*Cols values in row-major order.
Data []float64
}
SaliencyMap is a single-channel grid of float64 saliency values. It is the common working and result type of the package: detectors compute it, the post-processing operators transform it, and it converts to a displayable 8-bit cv.Mat with SaliencyMap.ToMat.
Values are stored row-major in Data: the value at row y, column x is at Data[y*Cols+x]. Higher values mark more salient locations, but the range is not fixed — raw detector output can span any scale until it is normalised.
func BoxSmooth ¶
func BoxSmooth(m *SaliencyMap, radius int) *SaliencyMap
BoxSmooth returns a box-averaged copy of m with the given window radius, computed in linear time with an integral image.
func CenterPrior ¶
func CenterPrior(m *SaliencyMap, sigmaFrac float64) *SaliencyMap
CenterPrior multiplies m by an isotropic Gaussian centre prior, damping responses toward the image border. sigmaFrac sets the standard deviation as a fraction of the half-diagonal (0.5 is a mild prior). Human fixations cluster near the image centre, so this bias improves most saliency maps.
func CenterSurround ¶
func CenterSurround(center, surround *SaliencyMap) *SaliencyMap
CenterSurround returns the center-surround response of a single feature map: the absolute difference between center and an up-sampled copy of surround, passed through the IttiNormalize operator. It is the elementary operation the Itti-Koch model repeats across scales, exposed for reuse. The surround map is resized to the center map's dimensions.
func CombineMaps ¶
func CombineMaps(maps ...*SaliencyMap) *SaliencyMap
CombineMaps averages several saliency maps into one, after normalising each to [0,1] so they contribute equally. All maps must share the same dimensions. It panics if the slice is empty or the sizes differ.
func GammaCorrect ¶
func GammaCorrect(m *SaliencyMap, gamma float64) *SaliencyMap
GammaCorrect returns a copy of m with each value raised to the power gamma after normalisation to [0,1]. gamma > 1 sharpens the map toward its peaks; gamma < 1 lifts weak responses.
func GaussianSmooth ¶
func GaussianSmooth(m *SaliencyMap, sigma float64) *SaliencyMap
GaussianSmooth returns a Gaussian-blurred copy of m. The kernel size is derived from sigma (about 6*sigma, forced odd) and the border sample is replicated. Smoothing suppresses pixel noise so nearby salient responses merge into coherent blobs.
func IttiNormalize ¶
func IttiNormalize(m *SaliencyMap) *SaliencyMap
IttiNormalize applies Itti, Koch and Niebur's normalisation operator N(.) to m: the map is scaled to [0,1], then multiplied by (1 - mean)^2 where mean is the average of its local maxima (excluding the single global maximum). A map with one dominant peak is promoted; a map with many comparable peaks is suppressed. This is the operator used to combine feature maps in the Itti-Koch model.
func LogScale ¶
func LogScale(m *SaliencyMap) *SaliencyMap
LogScale returns a copy of m compressed by log(1+v) after shifting so its minimum is zero. It tames maps with a few very large outliers.
func NewSaliencyMap ¶
func NewSaliencyMap(rows, cols int) *SaliencyMap
NewSaliencyMap allocates a zero-filled map of the given size. It panics if either dimension is not positive.
func NormalizeRange ¶
func NormalizeRange(m *SaliencyMap, lo, hi float64) *SaliencyMap
NormalizeRange returns a copy of m linearly rescaled to the closed interval [lo, hi]. It is the range-targeted companion to SaliencyMap.Normalize, which always targets [0,1].
func NormedGradient ¶
func NormedGradient(img *cv.Mat) *SaliencyMap
NormedGradient returns the normed-gradient magnitude map of img: the Sobel gradient magnitude of its luminance. Object boundaries carry strong, closed gradient contours, which is the cue the ObjectnessBING proposal generator scores.
func SaliencyMapFromFloatMat ¶
func SaliencyMapFromFloatMat(f *cv.FloatMat) *SaliencyMap
SaliencyMapFromFloatMat copies the parent package's cv.FloatMat into a SaliencyMap of the same size.
func SaliencyMapFromMat ¶
func SaliencyMapFromMat(img *cv.Mat) *SaliencyMap
SaliencyMapFromMat builds a map from the luminance of img, with values in [0,255]. Multi-channel input is converted to grayscale first.
func (*SaliencyMap) AddMap ¶
func (m *SaliencyMap) AddMap(other *SaliencyMap) *SaliencyMap
AddMap returns the elementwise sum of m and other, which must have the same dimensions.
func (*SaliencyMap) At ¶
func (m *SaliencyMap) At(y, x int) float64
At returns the value at row y, column x. It panics on out-of-range access.
func (*SaliencyMap) BoundingBox ¶
func (m *SaliencyMap) BoundingBox(t float64) (rect image.Rectangle, ok bool)
BoundingBox returns the smallest axis-aligned rectangle enclosing every pixel whose value is greater than or equal to t. The ok result is false when no pixel meets the threshold, in which case the rectangle is empty.
func (*SaliencyMap) CenterOfMass ¶
func (m *SaliencyMap) CenterOfMass() (x, y float64)
CenterOfMass returns the value-weighted centroid (x, y) of the map, treating values below zero as zero. For an all-zero map it returns the geometric centre.
func (*SaliencyMap) Clone ¶
func (m *SaliencyMap) Clone() *SaliencyMap
Clone returns a deep copy of the map with its own backing storage.
func (*SaliencyMap) Mean ¶
func (m *SaliencyMap) Mean() float64
Mean returns the arithmetic mean of all values in the map.
func (*SaliencyMap) MeanThreshold ¶
func (m *SaliencyMap) MeanThreshold(k float64) (mask *cv.Mat, threshold float64)
MeanThreshold returns the binary mask produced by thresholding the map at k times its mean value — the adaptive rule of Achanta et al., which uses k=2. It returns both the mask and the threshold that was applied.
func (*SaliencyMap) MinMax ¶
func (m *SaliencyMap) MinMax() (min, max float64)
MinMax returns the smallest and largest values in the map.
func (*SaliencyMap) MultiplyMap ¶
func (m *SaliencyMap) MultiplyMap(other *SaliencyMap) *SaliencyMap
MultiplyMap returns the elementwise product of m and other, which must have the same dimensions.
func (*SaliencyMap) Normalize ¶
func (m *SaliencyMap) Normalize() *SaliencyMap
Normalize returns a copy of the map linearly rescaled so its minimum maps to 0 and its maximum to 1. A constant map yields all zeros.
func (*SaliencyMap) OtsuThreshold ¶
func (m *SaliencyMap) OtsuThreshold() (mask *cv.Mat, threshold float64)
OtsuThreshold binarises the map using Otsu's method, which chooses the threshold that maximises between-class variance over a 256-bin histogram of the value range. It returns the mask and the threshold in the map's own units.
func (*SaliencyMap) PercentileThreshold ¶
func (m *SaliencyMap) PercentileThreshold(p float64) (mask *cv.Mat, threshold float64)
PercentileThreshold returns the binary mask keeping the fraction p (in [0,1]) of the highest-valued pixels, together with the threshold value used. p=0.1 keeps roughly the top 10 percent.
func (*SaliencyMap) Scale ¶
func (m *SaliencyMap) Scale(factor float64) *SaliencyMap
Scale returns a copy of the map with every value multiplied by factor.
func (*SaliencyMap) Set ¶
func (m *SaliencyMap) Set(y, x int, value float64)
Set stores value at row y, column x. It panics on out-of-range access.
func (*SaliencyMap) Size ¶
func (m *SaliencyMap) Size() (rows, cols int)
Size returns the map dimensions as (rows, cols).
func (*SaliencyMap) StdDev ¶
func (m *SaliencyMap) StdDev() float64
StdDev returns the population standard deviation of the map's values.
func (*SaliencyMap) Sum ¶
func (m *SaliencyMap) Sum() float64
Sum returns the total of all values in the map.
func (*SaliencyMap) Threshold ¶
func (m *SaliencyMap) Threshold(t float64) *cv.Mat
Threshold returns a binary cv.Mat in which pixels whose value is greater than or equal to t are 255 and all others 0.
func (*SaliencyMap) ToFloatMat ¶
func (m *SaliencyMap) ToFloatMat() *cv.FloatMat
ToFloatMat returns a copy of the map as the parent package's cv.FloatMat.
type StaticSaliency ¶
type StaticSaliency interface {
// ComputeSaliency returns a single-channel saliency map the same size as
// img, min-max normalised to the 8-bit range.
ComputeSaliency(img *cv.Mat) *cv.Mat
}
StaticSaliency is implemented by the single-image saliency detectors. It mirrors OpenCV's cv::saliency::StaticSaliency: a detector consumes one image and produces a single-channel saliency map in which brighter samples mark more visually salient locations.
type StaticSaliencyFineGrained ¶
type StaticSaliencyFineGrained struct {
// Scales holds the window radii used for the center-surround differences.
// Radii that do not fit the image (>= half the smaller dimension) are
// skipped at compute time. When empty, a default geometric set is used.
Scales []int
}
StaticSaliencyFineGrained detects saliency with the fine-grained center-surround model of Montabone & Soto, "Human detection using a mobile platform and novel features derived from a visual saliency mechanism" (Image and Vision Computing 2010), the algorithm behind OpenCV's cv::saliency::StaticSaliencyFineGrained.
The grayscale image is compared against local averages taken over a range of window radii. At each scale the absolute difference between a pixel and the mean of its surrounding window measures on-centre/off-centre contrast; the per-scale differences are averaged so that both small, crisp features and large, smooth objects contribute. The local means are computed in linear time with an integral image, so the cost is independent of window size.
Construct one with NewStaticSaliencyFineGrained; the zero value computes a single default scale.
func NewStaticSaliencyFineGrained ¶
func NewStaticSaliencyFineGrained() *StaticSaliencyFineGrained
NewStaticSaliencyFineGrained returns a detector with the default multi-scale radii {1, 2, 4, 8, 16}.
func (*StaticSaliencyFineGrained) ComputeSaliency ¶
func (s *StaticSaliencyFineGrained) ComputeSaliency(img *cv.Mat) *cv.Mat
ComputeSaliency returns the fine-grained saliency map of img as an 8-bit single-channel cv.Mat. It satisfies the StaticSaliency interface.
func (*StaticSaliencyFineGrained) ComputeSaliencyMap ¶
func (s *StaticSaliencyFineGrained) ComputeSaliencyMap(img *cv.Mat) *SaliencyMap
ComputeSaliencyMap returns the fine-grained saliency of img as a SaliencyMap the same size as img. It panics if img is nil or empty.
type StaticSaliencyFrequencyTuned ¶
type StaticSaliencyFrequencyTuned struct {
// Ksize is the Gaussian pre-smoothing kernel size (default 3).
Ksize int
// Sigma is the Gaussian pre-smoothing standard deviation (default 1),
// applied to each L*a*b* channel.
Sigma float64
}
StaticSaliencyFrequencyTuned detects saliency with the frequency-tuned model of Achanta, Hemami, Estrada & Susstrunk, "Frequency-tuned Salient Region Detection" (CVPR 2009).
The image is converted to CIE L*a*b* colour. Each channel is smoothed with a small Gaussian to remove high-frequency texture, and the saliency of a pixel is the squared Euclidean distance in L*a*b* between its smoothed colour and the whole-image mean colour. Regions whose colour departs from the global average — the defining property of a salient object against its background — score highly, at full input resolution and with well-defined boundaries.
Construct one with NewStaticSaliencyFrequencyTuned; the zero value uses a 1-pixel-sigma smoothing.
func NewStaticSaliencyFrequencyTuned ¶
func NewStaticSaliencyFrequencyTuned() *StaticSaliencyFrequencyTuned
NewStaticSaliencyFrequencyTuned returns a detector with a 3x3, sigma-1 smoothing kernel.
func (*StaticSaliencyFrequencyTuned) ComputeSaliency ¶
func (s *StaticSaliencyFrequencyTuned) ComputeSaliency(img *cv.Mat) *cv.Mat
ComputeSaliency returns the frequency-tuned saliency map of img as an 8-bit single-channel cv.Mat. It satisfies the StaticSaliency interface.
func (*StaticSaliencyFrequencyTuned) ComputeSaliencyMap ¶
func (s *StaticSaliencyFrequencyTuned) ComputeSaliencyMap(img *cv.Mat) *SaliencyMap
ComputeSaliencyMap returns the frequency-tuned saliency of img as a SaliencyMap the same size as img. It panics if img is nil or empty.
type StaticSaliencyIttiKoch ¶
type StaticSaliencyIttiKoch struct {
// MaxLevels caps the depth of the Gaussian pyramids.
MaxLevels int
// CenterLevels and SurroundDeltas select the pyramid levels differenced:
// for each centre level c and delta d, level c is compared against level
// c+d. Missing levels are skipped.
CenterLevels, SurroundDeltas []int
}
StaticSaliencyIttiKoch implements a center-surround attention model in the spirit of Itti, Koch & Niebur, "A Model of Saliency-Based Visual Attention for Rapid Scene Analysis" (PAMI 1998).
Three biologically motivated feature families are extracted: an intensity channel, two colour-opponency channels (red-green and blue-yellow) and four orientation channels (0, 45, 90 and 135 degrees, from oriented gradients). Each feature is built into a Gaussian pyramid and its saliency comes from across-scale center-surround differences — a fine "centre" level minus a coarse "surround" level — which respond wherever a location differs from its neighbourhood. The per-feature maps are combined with the IttiNormalize operator N(.) into intensity, colour and orientation conspicuity maps, whose normalised average is the final saliency map. This is the heaviest detector in the package.
Construct one with NewStaticSaliencyIttiKoch; the zero value is not usable.
func NewStaticSaliencyIttiKoch ¶
func NewStaticSaliencyIttiKoch() *StaticSaliencyIttiKoch
NewStaticSaliencyIttiKoch returns a detector with the classical pyramid configuration (up to 9 levels, centres {2,3}, surround deltas {2,3}).
func (*StaticSaliencyIttiKoch) ComputeSaliency ¶
func (s *StaticSaliencyIttiKoch) ComputeSaliency(img *cv.Mat) *cv.Mat
ComputeSaliency returns the Itti-Koch saliency map of img as an 8-bit single-channel cv.Mat. It satisfies the StaticSaliency interface.
func (*StaticSaliencyIttiKoch) ComputeSaliencyMap ¶
func (s *StaticSaliencyIttiKoch) ComputeSaliencyMap(img *cv.Mat) *SaliencyMap
ComputeSaliencyMap returns the Itti-Koch saliency of img as a SaliencyMap the same size as img. It panics if img is nil or empty.
type StaticSaliencySpectralResidual ¶
type StaticSaliencySpectralResidual struct {
// ResizedWidth and ResizedHeight are the working dimensions the image is
// resampled to before the transform. They are rounded up to a power of two
// internally so the radix-2 FFT applies. Smaller sizes emphasise coarse,
// large-scale saliency; the OpenCV default is 64x64.
ResizedWidth, ResizedHeight int
}
StaticSaliencySpectralResidual detects saliency with the spectral-residual method of Hou & Zhang, "Saliency Detection: A Spectral Residual Approach" (CVPR 2007), the same algorithm as OpenCV's cv::saliency::StaticSaliencySpectralResidual.
The image is reduced to grayscale and resampled to a small working size. Its 2-D Fourier transform is split into a log-amplitude spectrum and a phase spectrum. The spectral residual — the log-amplitude minus its own 3x3 local average — isolates the parts of the spectrum that deviate from the smooth, statistically expected 1/f falloff and therefore correspond to novel, salient structure. Recombining the residual amplitude with the original phase and inverse-transforming yields the saliency map, which is squared, blurred and resized back to the input dimensions.
Construct one with NewStaticSaliencySpectralResidual; the zero value is not usable.
func NewStaticSaliencySpectralResidual ¶
func NewStaticSaliencySpectralResidual() *StaticSaliencySpectralResidual
NewStaticSaliencySpectralResidual returns a detector configured with the OpenCV default 64x64 working resolution.
func (*StaticSaliencySpectralResidual) ComputeSaliency ¶
func (s *StaticSaliencySpectralResidual) ComputeSaliency(img *cv.Mat) *cv.Mat
ComputeSaliency returns the spectral-residual saliency map of img as an 8-bit single-channel cv.Mat. It satisfies the StaticSaliency interface.
func (*StaticSaliencySpectralResidual) ComputeSaliencyMap ¶
func (s *StaticSaliencySpectralResidual) ComputeSaliencyMap(img *cv.Mat) *SaliencyMap
ComputeSaliencyMap returns the spectral-residual saliency of img as a SaliencyMap the same size as img. It panics if img is nil or empty.