rimage

package
v0.2.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2023 License: AGPL-3.0 Imports: 50 Imported by: 4

Documentation

Overview

Package rimage defines fundamental image and color processing primitives.

The golang standard library, while useful, is not very productive when it comes to handling/comparing colors of different spaces, transforming images, and drawing images. This package aims to rectify these issues with a few unified interfaces/structures.

Index

Constants

View Source
const MagicNumIntVersionX = 6363110499870197078

MagicNumIntVersionX is the magic number (as an int) for VERSIONX.

View Source
const MagicNumIntViamType = 5782988369567958340

MagicNumIntViamType is the magic number (as an int) for the custom Viam depth type. magic number for ViamCustomType is int64([]byte("DEPTHMAP")).

View Source
const MaxDepth = Depth(math.MaxUint16)

MaxDepth is the maximum allowed depth.

View Source
const RawDepthHeaderLength = 24

RawDepthHeaderLength is the length of our custom header for raw depth map data in bytes. Header contains 8 bytes worth of magic number, followed by 8 bytes for width and another 8bytes for height .

View Source
const RawRGBAHeaderLength = 12

RawRGBAHeaderLength is the length of our custom header for raw RGBA data in bytes. See above as to why.

Variables

View Source
var (
	Red     = NewColor(255, 0, 0)
	DarkRed = NewColor(64, 32, 32)

	Green = NewColor(0, 255, 0)

	Blue     = NewColor(0, 0, 255)
	DarkBlue = NewColor(32, 32, 64)

	White = NewColor(255, 255, 255)
	Gray  = NewColor(128, 128, 128)
	Black = NewColor(0, 0, 0)

	Yellow = NewColor(255, 255, 0)
	Cyan   = NewColor(0, 255, 255)
	Purple = NewColor(255, 0, 255)
	Pink   = NewColor(100, 30, 40)

	Colors = []Color{
		Red,
		DarkRed,
		Green,
		Blue,
		DarkBlue,
		White,
		Gray,
		Black,
		Yellow,
		Cyan,
		Purple,
		Pink,
	}
)

Commonly used colors.

View Source
var DepthMapMagicNumber = []byte("DEPTHMAP")

DepthMapMagicNumber represents the magic number for our custom header for raw DEPTH data.

View Source
var NoPoints = image.Point{-1, -1}

NoPoints TODO.

View Source
var RGBABitmapMagicNumber = []byte("RGBA")

RGBABitmapMagicNumber represents the magic number for our custom header for raw RGBA data. The header is composed of this magic number followed by a 4-byte line of the width as a uint32 number and another for the height. Credit to Ben Zotto for inventing this formulation https://bzotto.medium.com/introducing-the-rgba-bitmap-file-format-4a8a94329e2c

Functions

func AllPointsIn

func AllPointsIn(size image.Point, pts []image.Point) bool

AllPointsIn TODO.

func AreCollinear

func AreCollinear(a, b, c r2.Point, eps float64) bool

AreCollinear returns true if the 3 points a, b and c are collinear.

func ArrayToPoints

func ArrayToPoints(pts []image.Point) []image.Point

ArrayToPoints TODO.

func BoundingBox

func BoundingBox(pts []image.Point) image.Rectangle

BoundingBox TODO.

func Center

func Center(contour []image.Point, maxDiff int) image.Point

Center TODO.

func CleanDepthMap

func CleanDepthMap(dm *DepthMap)

CleanDepthMap removes the connected regions of data below a certain size thershold.

func ClusterImage

func ClusterImage(clusters []Color, img *Image) *image.RGBA

ClusterImage TODO.

func CompareImages

func CompareImages(img1, img2 image.Image) (int, image.Image, error)

CompareImages compares two images and returns a value of how close they are to being equal where zero is equal and the higher it gets, the less like each other they are. https://stackoverflow.com/a/60631079/830628

func ConvertColorImageToLuminanceFloat

func ConvertColorImageToLuminanceFloat(img *Image) *mat.Dense

ConvertColorImageToLuminanceFloat convert an Image to a gray level image as a float dense matrix.

func ConvertImageToGray16 added in v0.0.8

func ConvertImageToGray16(img image.Image) (*image.Gray16, error)

ConvertImageToGray16 takes an image and figures out if it's already an image.Gray16 or if it can be converted into one.

func ConvertToNRGBA

func ConvertToNRGBA(c color.Color) color.NRGBA

ConvertToNRGBA converts a go color to an NRGBA color.

func ConvolveGray

func ConvolveGray(img *image.Gray, kernel *Kernel, anchor image.Point, border BorderPad) (*image.Gray, error)

ConvolveGray applies a convolution matrix (Kernel) to a grayscale image. Example of usage:

res, err := convolution.ConvolveGray(img, kernel, {1, 1}, BorderReflect)

Note: the anchor represents a point inside the area of the kernel. After every step of the convolution the position specified by the anchor point gets updated on the result image.

func ConvolveGrayFloat64

func ConvolveGrayFloat64(m *mat.Dense, filter *Kernel) (*mat.Dense, error)

ConvolveGrayFloat64 implements a gray float64 image convolution with the Kernel filter There is no clamping in this case.

func CountBrightSpots

func CountBrightSpots(img *image.Gray, center image.Point, radius int, threshold uint8) int

CountBrightSpots TODO.

func DecodeImage

func DecodeImage(ctx context.Context, imgBytes []byte, mimeType string) (image.Image, error)

DecodeImage takes an image buffer and decodes it, using the mimeType and the dimensions, to return the image.

func DrawRectangleEmpty

func DrawRectangleEmpty(dc *gg.Context, r image.Rectangle, c color.Color, width float64)

DrawRectangleEmpty draws the given rectangle into the context. The positions of the rectangle are used to place it within the context.

func DrawString

func DrawString(dc *gg.Context, text string, p image.Point, c color.Color, size float64)

DrawString writes a string to the given context at a particular point.

func EdgeHysteresisFiltering

func EdgeHysteresisFiltering(mag *mat.Dense, low, high float64) (*image.Gray, error)

EdgeHysteresisFiltering performs the Non Maximum Suppressed edges hysteresis filtering every pixel whose value is above high is preserved. Any pixel whose value falls into [low, high] and that is connected to a high value pixel is preserved as well as all pixel whose value is below low is set to zero. This allows to remove weak edges but preserves edges that are strong or partially strong.

func EncodeImage

func EncodeImage(ctx context.Context, img image.Image, mimeType string) ([]byte, error)

EncodeImage takes an image and mimeType as input and encodes it into a slice of bytes (buffer) and returns the bytes.

func Font

func Font() *truetype.Font

Font returns the font we use for drawing.

func GetGrayAvg

func GetGrayAvg(pic *image.Gray16) int

GetGrayAvg takes in a grayscale image and returns the average value as an int.

func GetGraySum

func GetGraySum(gray *image.Gray16) int

GetGraySum takes in a grayscale image and returns the total sum as an int.

func GetHysteresisThresholds

func GetHysteresisThresholds(mag, nms *mat.Dense, ratioHigh, ratioLow float64) (float64, float64, error)

GetHysteresisThresholds computes the low and high thresholds for the Canny Hysteresis Edge Thresholding. John Canny said in his paper "A Computational Approach to Edge Detection" that "The ratio of the high to low threshold in the implementation is in the range two or three to one." So, in this implementation, we should choose tlow ~= 0.5 or 0.33333. A good value for thigh is around 0.8.

func GradientNonMaximumSuppressionC8

func GradientNonMaximumSuppressionC8(mag, direction *mat.Dense) (*mat.Dense, error)

GradientNonMaximumSuppressionC8 computes the non maximal suppression of edges in Connectivity 8. For each pixel, it checks if at least one the two pixels in the current gradient direction has a greater magnitude than the current pixel.

func ImageToYCbCrForTesting added in v0.1.5

func ImageToYCbCrForTesting(dst *image.YCbCr, src image.Image)

ImageToYCbCrForTesting converts an image to YCbCr. It is only to be used for testing.

func IsImageFile

func IsImageFile(fn string) bool

IsImageFile returns if the given file is an image file based on what we support.

func IterateImage

func IterateImage(img image.Image, f func(x, y int, c color.Color) bool)

IterateImage visits each point in the image and calls the given visitor function that can control whether or not to continue iteration.

func Luminance

func Luminance(aColor Color) float64

Luminance computes the luminance value from the R,G and B values. It is defined as (299*R + 587*G + 114*B) / 1000 in order to avoid floating point math issue b/w different architectures Formula from : https://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale - luma coding.

func MakeGray

func MakeGray(pic *Image) *image.Gray

MakeGray takes a rimage.Image and well... makes it gray (image.Gray).

func MissingDepthData

func MissingDepthData(dm *DepthMap) *image.Gray

MissingDepthData outputs a binary map where white represents where data is, and black is where data is missing.

func MorphFilter

func MorphFilter(inDM, outDM *DepthMap, kernelSize, iterations int, process func(center image.Point, dm, kernel *DepthMap) Depth) error

MorphFilter takes in a pointer of the input depth map, the output depth map, the size of the kernel, the number of times to apply the filter, and the filter to apply. Morphological filters are used in image preprocessing to smooth, prune, and fill in noise in the image.

func MultiplyGrays

func MultiplyGrays(g1, g2 *image.Gray) (*image.Gray16, error)

MultiplyGrays takes in two image.Grays and calculates the product. The result must go in a image.Gray16 so that the numbers have space to breathe.

func NewLazyEncodedImage added in v0.0.8

func NewLazyEncodedImage(imgBytes []byte, mimeType string) image.Image

NewLazyEncodedImage returns a new image that will only get decoded once actual data is needed from it. This is helpful for zero copy scenarios. If a width or height of the image is unknown, pass 0 or -1; when done a decode will happen on Bounds. In the future this can probably go away with reading all metadata from the header of the image bytes. NOTE: Usage of an image that would fail to decode causes a lazy panic.

func Overlay

func Overlay(i *Image, dm *DepthMap) *image.NRGBA

Overlay overlays an rgb image over a depth map.

func PaddingFloat64

func PaddingFloat64(img *mat.Dense, kernelSize, anchor image.Point, border BorderPad) (*mat.Dense, error)

PaddingFloat64 pads a *mat.Dense - padding mode = reflect.

func PaddingGray

func PaddingGray(img *image.Gray, kernelSize, anchor image.Point, border BorderPad) (*image.Gray, error)

PaddingGray appends padding to a given grayscale image. The size of the padding is calculated from the kernel size and the anchor point. Supported Border types are: BorderConstant, BorderReplicate, BorderReflect. Example of usage:

res, err := padding.PaddingGray(img, {5, 5}, {1, 1}, BorderReflect)

Note: this will add a 1px padding for the top and left borders of the image and a 3px padding fot the bottom and right borders of the image.

func PointAngle

func PointAngle(a, b image.Point) float64

PointAngle TODO.

func PointDistance

func PointDistance(a, b image.Point) float64

PointDistance TODO.

func R2PointToImagePoint

func R2PointToImagePoint(pt r2.Point) image.Point

R2PointToImagePoint TODO.

func R2RectToImageRect

func R2RectToImageRect(rec r2.Rect) image.Rectangle

R2RectToImageRect TODO.

func SameImgSize

func SameImgSize(g1, g2 image.Image) bool

SameImgSize compares image.Grays to see if they're the same size.

func SaveImage

func SaveImage(pic image.Image, loc string) error

SaveImage takes an image.Image and saves it to a jpeg at the given file location and also returns the location back.

func SimpleEdgeDetection

func SimpleEdgeDetection(img *Image, t1, blur float64) (*image.Gray, error)

SimpleEdgeDetection TODO.

func SliceVecsToXsYs

func SliceVecsToXsYs(pts []r2.Point) ([]float64, []float64)

SliceVecsToXsYs converts a slice of r2.Point to 2 slices floats containing x and y coordinates.

func TranslateR2Rect

func TranslateR2Rect(rect r2.Rect, pt r2.Point) r2.Rect

TranslateR2Rect TODO.

func Warp

func Warp(input WarpConnector, m TransformationMatrix)

Warp TODO.

func WarpColorDepth

func WarpColorDepth(col *Image, dm *DepthMap, src, dst []image.Point, newSize image.Point) (*Image, *DepthMap)

WarpColorDepth adapts the image to a new size.

func WriteImageToFile

func WriteImageToFile(path string, img image.Image) (err error)

WriteImageToFile writes the given image to a file at the supplied path.

func WriteRawDepthMapTo added in v0.0.7

func WriteRawDepthMapTo(dm *DepthMap, out io.Writer) (int64, error)

WriteRawDepthMapTo writes this depth map to the given writer.

func WriteRawDepthMapToFile added in v0.0.7

func WriteRawDepthMapToFile(dm *DepthMap, fn string) (err error)

WriteRawDepthMapToFile writes the raw depth map to the given file.

Types

type BorderPad

type BorderPad int

BorderPad is an enum type for supported padding types.

const (
	//nolint:dupword
	// BorderConstant - X X X A B C D E X X X - where X is a black ( color.Gray{0} ) pixel.
	BorderConstant BorderPad = iota
	//nolint:dupword
	// BorderReplicate - A A A A B C D E E E E  - copies the nearest border pixel into padding.
	BorderReplicate
	// BorderReflect - D C B A B C D E D C B - reflects the nearest pixel group around border pixel.
	BorderReflect
)

type CannyEdgeDetector

type CannyEdgeDetector struct {
	// contains filtered or unexported fields
}

CannyEdgeDetector TODO.

func NewCannyDericheEdgeDetector

func NewCannyDericheEdgeDetector() *CannyEdgeDetector

NewCannyDericheEdgeDetector TODO.

func NewCannyDericheEdgeDetectorWithParameters

func NewCannyDericheEdgeDetectorWithParameters(hiRatio, loRatio float64, preproc bool) *CannyEdgeDetector

NewCannyDericheEdgeDetectorWithParameters creates a new Canny edge detector with user provided parameters.

func (*CannyEdgeDetector) DetectDepthEdges

func (cd *CannyEdgeDetector) DetectDepthEdges(dmIn *DepthMap, blur float64) (*image.Gray, error)

DetectDepthEdges uses a Canny edge detector to find edges in a depth map and returns a grayscale image of edges.

func (*CannyEdgeDetector) DetectEdges

func (cd *CannyEdgeDetector) DetectEdges(img *Image, blur float64) (*image.Gray, error)

DetectEdges TODO.

type Color

type Color uint64

Color is a more featured color type than color.Color. Prefer to use this over color.Color where possible.

Byte layout 0: r 1: g 2: b 3&4: h 5: s 6: v 7: unused

func AverageColor

func AverageColor(colors []Color, weights ...float64) Color

AverageColor returns the average of the HSV color. H is angle in degrees. optional weights for the average.

func BilinearInterpolationColor

func BilinearInterpolationColor(pt r2.Point, img *Image) *Color

BilinearInterpolationColor approximates the Color value between pixels according to a bilinear interpolation. A nil return value means the interpolation is out of bounds.

func ClusterFromImage

func ClusterFromImage(img *Image, numClusters int) ([]Color, error)

ClusterFromImage TODO.

func ClusterHSV

func ClusterHSV(data []Color, numClusters int) ([]Color, error)

ClusterHSV TODO.

func NearestNeighborColor

func NearestNeighborColor(pt r2.Point, img *Image) *Color

NearestNeighborColor takes the value of the closest point to the intermediate pixel.

func NewColor

func NewColor(r, g, b uint8) Color

NewColor returns a color based off RGB.

func NewColorFromArray

func NewColorFromArray(buf []float64) Color

NewColorFromArray returns a color based off the bytes in array mapping to the byte fields of a Color.

func NewColorFromColor

func NewColorFromColor(c color.Color) Color

NewColorFromColor takes in a go Color and finds the best conversion to our Color.

func NewColorFromHSV

func NewColorFromHSV(h, s, v float64) Color

NewColorFromHSV returns a color based off HSV.

func NewColorFromHex

func NewColorFromHex(hex string) (Color, error)

NewColorFromHex returns a color from a RGB hex value.

func NewColorFromHexOrPanic

func NewColorFromHexOrPanic(hex string) Color

NewColorFromHexOrPanic returns a color from a RGB hex value. It panics if there is an error parsing.

func (Color) Closest

func (c Color) Closest(others []Color) (int, Color, float64)

Closest returns the color that is closet to this color based on the given slice of colors.

func (Color) Distance

func (c Color) Distance(b Color) float64

Distance returns the "distance" between two colors.

func (Color) DistanceLab

func (c Color) DistanceLab(b Color) float64

DistanceLab returns a measure of visual similarity between two colors.

func (Color) Hex

func (c Color) Hex() string

Hex returns the RGB hexadecimal representation of the color.

func (Color) HsvNormal

func (c Color) HsvNormal() (float64, float64, float64)

HsvNormal returns a normalized HSV representation of the color. h : 0 -> 360, s,v : 0 -> 1.0.

func (Color) RGB255

func (c Color) RGB255() (uint8, uint8, uint8)

RGB255 returns the RGB representation of the color.

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

RGBA returns the non-alpha-premultiplied RGBA values of the color.

func (Color) RawFloatArray

func (c Color) RawFloatArray() []float64

RawFloatArray returns the byte fields of the color.

func (Color) RawFloatArrayFill

func (c Color) RawFloatArrayFill(buf []float64) []float64

RawFloatArrayFill sets the bytes fields of the color on the given slice that must have a length of at least 6.

func (Color) ScaleHSV

func (c Color) ScaleHSV() (float64, float64, float64)

ScaleHSV returns a scaled HSV representation of the color.

func (Color) String

func (c Color) String() string

String returns a human readable representation of the color.

type ColorDiff

type ColorDiff struct {
	Left  Color
	Right Color
	Diff  float64
}

ColorDiff TODO.

type ColorDiffs

type ColorDiffs struct {
	// contains filtered or unexported fields
}

ColorDiffs TODO.

func ComputeColorDiffs

func ComputeColorDiffs(all []Color) ColorDiffs

ComputeColorDiffs computes the different between the all of the colors given.

func (*ColorDiffs) Add

func (x *ColorDiffs) Add(a, b Color)

Add TODO.

func (*ColorDiffs) AddD

func (x *ColorDiffs) AddD(a, b Color, d float64)

AddD TODO.

func (*ColorDiffs) Len

func (x *ColorDiffs) Len() int

Len returns the number of diffs.

func (*ColorDiffs) Less

func (x *ColorDiffs) Less(i, j int) bool

Less returns if one diff is less than another based on its diff value.

func (*ColorDiffs) Sort

func (x *ColorDiffs) Sort()

Sort sorts the diffs based on satisfying the Sort interface above.

func (*ColorDiffs) Swap

func (x *ColorDiffs) Swap(i, j int)

Swap swaps two diffs positionally.

func (*ColorDiffs) WriteTo

func (x *ColorDiffs) WriteTo(fn string) error

WriteTo writes the diff information out to a file.

type Depth

type Depth uint16

Depth is the depth in mm.

func BilinearInterpolationDepth

func BilinearInterpolationDepth(pt r2.Point, dm *DepthMap) *Depth

BilinearInterpolationDepth approximates the Depth value between pixels according to a bilinear interpolation. A nil return value means the interpolation is out of bounds.

func NearestNeighborDepth

func NearestNeighborDepth(pt r2.Point, dm *DepthMap) *Depth

NearestNeighborDepth takes the value of the closest point to the intermediate pixel.

type DepthMap

type DepthMap struct {
	// contains filtered or unexported fields
}

DepthMap fulfills the image.Image interface and represents the depth information of the scene in mm.

func ClosingMorph

func ClosingMorph(dm *DepthMap, kernelSize, iterations int) (*DepthMap, error)

ClosingMorph applies a closing morphological transform, which is a Dilation followed by an Erosion. Closing smooths an image by fusing narrow breaks and filling small holes and gaps. https://clouard.users.greyc.fr/Pantheon/experiments/morphology/index-en.html#ch3-A

func ConvertImageToDepthMap

func ConvertImageToDepthMap(ctx context.Context, img image.Image) (*DepthMap, error)

ConvertImageToDepthMap takes an image and figures out if it's already a DepthMap or if it can be converted into one.

func FillDepthMap

func FillDepthMap(dm *DepthMap, img *Image) (*DepthMap, error)

FillDepthMap finds regions of connected missing data, and for those below a certain size, fills them in with an average of the surrounding pixels by using 16-point ray-marching, taking care of regions that are on the boundaries between objects. Assumes rgb image and depth map are aligned.

func GaussianSmoothing

func GaussianSmoothing(dm *DepthMap, sigma float64) (*DepthMap, error)

GaussianSmoothing smoothes a depth map affect by noise by using a weighted average of the pixel values in a window according to a gaussian distribution with a given sigma.

func JointBilateralSmoothing

func JointBilateralSmoothing(dm *DepthMap, spatialSigma, depthSigma float64) (*DepthMap, error)

JointBilateralSmoothing smoothes a depth map affected by noise by using the product of two gaussian filters, one based on spatial distance, and the other based on depth differences. depthSigma essentially sets a threshold to not smooth across large differences in depth.

func NewDepthMapFromFile

func NewDepthMapFromFile(ctx context.Context, fn string) (*DepthMap, error)

NewDepthMapFromFile extract the depth map from a Z16 image file or a .dat image file.

func NewEmptyDepthMap

func NewEmptyDepthMap(width, height int) *DepthMap

NewEmptyDepthMap returns an unset depth map with the given dimensions.

func OpeningMorph

func OpeningMorph(dm *DepthMap, kernelSize, iterations int) (*DepthMap, error)

OpeningMorph applies an opening morphological transform, which is a Erosion followed by a Dilation. Opening smooths an image by eliminating thin protrusions and narrow outcroppings. https://clouard.users.greyc.fr/Pantheon/experiments/morphology/index-en.html#ch3-A

func ParseRawDepthMap added in v0.0.7

func ParseRawDepthMap(fn string) (*DepthMap, error)

ParseRawDepthMap parses a depth map from the given file. It knows how to handle compressed files as well.

func PreprocessDepthMap

func PreprocessDepthMap(dm *DepthMap, img *Image) (*DepthMap, error)

PreprocessDepthMap applies data cleaning and smoothing procedures to an input depth map, and optional rgb image. It is assumed the depth map and rgb image are aligned.

func ReadDepthMap

func ReadDepthMap(r io.Reader) (*DepthMap, error)

ReadDepthMap returns a depth map from the given reader.

func SavitskyGolaySmoothing

func SavitskyGolaySmoothing(dm *DepthMap, validPoints *image.Gray, radius, polyOrder int) (*DepthMap, error)

SavitskyGolaySmoothing smoothes a depth map affected by noise by using a least-squares fit to a 2D polynomial equation. radius determines the window of the smoothing, while polyOrder determines the order of the polynomial fit.

func (*DepthMap) At

func (dm *DepthMap) At(x, y int) color.Color

At returns the depth value as a color.Color so DepthMap can implement image.Image.

func (*DepthMap) AverageDepthAndStats

func (dm *DepthMap) AverageDepthAndStats(p image.Point, radius int) (float64, float64)

AverageDepthAndStats returns average distance, average distance to avg. TODO(erh): should this be std. dev?

func (*DepthMap) Bounds

func (dm *DepthMap) Bounds() image.Rectangle

Bounds returns the rectangle dimensions of the image.

func (*DepthMap) Clone

func (dm *DepthMap) Clone() *DepthMap

Clone makes a copy of the depth map.

func (*DepthMap) ColorModel

func (dm *DepthMap) ColorModel() color.Model

ColorModel for DepthMap so that it implements image.Image.

func (*DepthMap) Contains

func (dm *DepthMap) Contains(x, y int) bool

Contains returns whether or not a point is within bounds of the depth map.

func (*DepthMap) ConvertDepthMapToLuminanceFloat

func (dm *DepthMap) ConvertDepthMapToLuminanceFloat() *mat.Dense

ConvertDepthMapToLuminanceFloat converts this depth map into a grayscale image of the same dimensions.

func (*DepthMap) Get

func (dm *DepthMap) Get(p image.Point) Depth

Get returns the depth at a given image.Point.

func (*DepthMap) GetDepth

func (dm *DepthMap) GetDepth(x, y int) Depth

GetDepth returns the depth at a given (x,y) coordinate.

func (*DepthMap) Height

func (dm *DepthMap) Height() int

Height returns the height of the depth map.

func (*DepthMap) InterestingPixels

func (dm *DepthMap) InterestingPixels(t float64) *image.Gray

InterestingPixels TODO.

func (*DepthMap) MinMax

func (dm *DepthMap) MinMax() (Depth, Depth)

MinMax returns the minimum and maximum depth values within the depth map.

func (*DepthMap) Rotate

func (dm *DepthMap) Rotate(amount int) *DepthMap

Rotate rotates a copy of this depth map clockwise by the given amount.

func (*DepthMap) Rotate180

func (dm *DepthMap) Rotate180() *DepthMap

Rotate180 rotates a copy of this depth map by 180 degrees.

func (*DepthMap) Rotate90

func (dm *DepthMap) Rotate90(clockwise bool) *DepthMap

Rotate90 rotates a copy of this depth map either by 90 degrees clockwise or counterclockwise.

func (*DepthMap) Set

func (dm *DepthMap) Set(x, y int, val Depth)

Set sets the depth at a given (x,y) coordinate.

func (*DepthMap) SubImage

func (dm *DepthMap) SubImage(r image.Rectangle) *DepthMap

SubImage returns a cropped image of the original DepthMap from the given rectangle.

func (*DepthMap) ToGray16Picture

func (dm *DepthMap) ToGray16Picture() *image.Gray16

ToGray16Picture converts this depth map into a grayscale image of the same dimensions.

func (*DepthMap) ToPrettyPicture

func (dm *DepthMap) ToPrettyPicture(hardMin, hardMax Depth) *Image

ToPrettyPicture converts the depth map into a colorful image to make it easier to see the depth gradients. The colorful picture will have no useful depth information, though.

func (*DepthMap) Warp

func (dm *DepthMap) Warp(m TransformationMatrix, newSize image.Point) *DepthMap

Warp returns a copy of this depth map warped by the given transformation matrix into a new size.

func (*DepthMap) Width

func (dm *DepthMap) Width() int

Width returns the width of the depth map.

func (*DepthMap) WriteToBuf added in v0.0.7

func (dm *DepthMap) WriteToBuf(out io.Writer) error

WriteToBuf writes the depth map to a writer as 16bit grayscale png.

type EdgeDetector

type EdgeDetector interface {
	// DetectEdges detects edges in the given image represented in a grayscale image
	// returns either a map of edges with magnitude or probability or a binary image
	DetectEdges(*Image, ...float64) *image.Gray
	// Edge binary image
	EdgeMap(*Image, ...float64) *Image
}

EdgeDetector defines a way to detect edges within an image.

type HSVObservation

type HSVObservation struct {
	// contains filtered or unexported fields
}

HSVObservation TODO.

func (HSVObservation) Coordinates

func (o HSVObservation) Coordinates() clusters.Coordinates

Coordinates TODO.

func (HSVObservation) Distance

func (o HSVObservation) Distance(point clusters.Coordinates) float64

Distance TODO.

type Image

type Image struct {
	// contains filtered or unexported fields
}

Image is like image.Image but it uses our Color type with a few more helper methods on it.

func CloneImage

func CloneImage(img image.Image) *Image

CloneImage creates a copy of the input image.

func ConvertImage

func ConvertImage(img image.Image) *Image

ConvertImage converts a go image into our Image type.

func NewImage

func NewImage(width, height int) *Image

NewImage returns a blank new image of the given dimensions.

func NewImageFromBounds

func NewImageFromBounds(bounds image.Rectangle) *Image

NewImageFromBounds returns blank new of dimensions defined by the given rectangle.

func NewImageFromFile

func NewImageFromFile(fn string) (*Image, error)

NewImageFromFile returns an image read in from the given file.

func WarpImage

func WarpImage(img image.Image, m TransformationMatrix, newSize image.Point) *Image

WarpImage TODO.

func (*Image) At

func (i *Image) At(x, y int) color.Color

At returns the color at the given point; black if not set.

func (*Image) AverageColor

func (i *Image) AverageColor(p image.Point, radius int) Color

AverageColor returns the average color about a certain point.

func (*Image) AverageColorAndStats

func (i *Image) AverageColorAndStats(p image.Point, radius int) (Color, float64)

AverageColorAndStats returns avg color and avg distances to avg color.

func (*Image) AverageColorXY

func (i *Image) AverageColorXY(x, y, radius int) Color

AverageColorXY returns the average color about a certain point.

func (*Image) Bounds

func (i *Image) Bounds() image.Rectangle

Bounds returns the outer bounds of this image. Otherwise known as its dimensions.

func (*Image) Circle

func (i *Image) Circle(center image.Point, radius int, c Color)

Circle inscribes a circle centered at the given point.

func (*Image) Clone

func (i *Image) Clone() *Image

Clone makes a copy of the image.

func (*Image) ColorModel

func (i *Image) ColorModel() color.Model

ColorModel returns our Color types color model.

func (*Image) Get

func (i *Image) Get(p image.Point) Color

Get returns the color at the given point; black if not set.

func (*Image) GetXY

func (i *Image) GetXY(x, y int) Color

GetXY returns the color at the given point; black if not set.

func (*Image) Height

func (i *Image) Height() int

Height returns the vertical height of this image.

func (*Image) In

func (i *Image) In(x, y int) bool

In returns whether or not a point is within bounds of this image.

func (*Image) InterestingPixels

func (i *Image) InterestingPixels(t float64) *image.Gray

InterestingPixels TODO TODO(erh): this and SimpleEdgeDetection are super similar, we shouldn't have both probably? or if we do need better names.

func (*Image) Rotate

func (i *Image) Rotate(amount int) *Image

Rotate rotates the image clockwise by a certain amount of degrees.

func (*Image) Set

func (i *Image) Set(p image.Point, c Color)

Set sets the color at the given point.

func (*Image) SetXY

func (i *Image) SetXY(x, y int, c Color)

SetXY sets the color at the given point.

func (*Image) SubImage

func (i *Image) SubImage(r image.Rectangle) *Image

SubImage returns a subset of the image defined by the given rectangle.

func (*Image) Width

func (i *Image) Width() int

Width returns the horizontal width of this image.

func (*Image) WriteTo

func (i *Image) WriteTo(fn string) error

WriteTo writes the image to the given file encoded based on the file extension.

type ImageGradient

type ImageGradient struct {
	GradX, GradY         *mat.Dense
	Magnitude, Direction *mat.Dense
}

ImageGradient TODO.

func ForwardGradient

func ForwardGradient(img *Image, blur float64, preprocess bool) (ImageGradient, error)

ForwardGradient computes the forward gradients in X and Y direction of an image in the Lab space Returns: gradient in x direction, gradient in y direction, its magnitude and direction at each pixel in a dense mat, and an error.

type Kernel

type Kernel struct {
	Content [][]float64
	Width   int
	Height  int
}

Kernel is a 2 dimensional matrix used mainly for convolution.

func GetBlur3

func GetBlur3() Kernel

GetBlur3 returns the Kernel corresponding to a mean averaging kernel.

func GetGaussian3

func GetGaussian3() Kernel

GetGaussian3 returns the Kernel corresponding to 3x3 Gaussian blurring kernel.

func GetGaussian5

func GetGaussian5() Kernel

GetGaussian5 returns the Kernel corresponding to 5x5 Gaussian blurring kernel.

func GetSobelX

func GetSobelX() Kernel

GetSobelX returns the Kernel corresponding to the Sobel kernel in the x direction.

func GetSobelY

func GetSobelY() Kernel

GetSobelY returns the Kernel corresponding to the Sobel kernel in the y direction.

func NewKernel

func NewKernel(width, height int) (*Kernel, error)

NewKernel creates a new Kernel with the given width and height. The value for every position of the kernel is 0.

func (*Kernel) AbSum

func (k *Kernel) AbSum() float64

AbSum returns the sum of every absolute value from a kernel.

func (*Kernel) At

func (k *Kernel) At(x, y int) float64

At returns a value from the position of {x, y} of a kernel.

func (*Kernel) Normalize

func (k *Kernel) Normalize() *Kernel

Normalize returns a normalized kernel where each value is divided by the absolute sum of the kernel.

func (*Kernel) Set

func (k *Kernel) Set(x, y int, value float64)

Set sets a value at a given {x, y} position.

func (*Kernel) Size

func (k *Kernel) Size() image.Point

Size returns the size of the kernel. The size is a type of image.Point containing the width and height of the kernel.

type LazyEncodedImage added in v0.0.8

type LazyEncodedImage struct {
	// contains filtered or unexported fields
}

LazyEncodedImage defers the decoding of an image until necessary.

func (*LazyEncodedImage) At added in v0.0.8

func (lei *LazyEncodedImage) At(x, y int) color.Color

At returns the color of the pixel at (x, y). At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid. At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.

func (*LazyEncodedImage) Bounds added in v0.0.8

func (lei *LazyEncodedImage) Bounds() image.Rectangle

Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).

func (*LazyEncodedImage) ColorModel added in v0.0.8

func (lei *LazyEncodedImage) ColorModel() color.Model

ColorModel returns the Image's color model.

func (*LazyEncodedImage) MIMEType added in v0.0.8

func (lei *LazyEncodedImage) MIMEType() string

MIMEType returns the encoded Image's MIME type.

func (*LazyEncodedImage) RawData added in v0.0.8

func (lei *LazyEncodedImage) RawData() []byte

RawData returns the encoded Image's raw data. Note: This is not a copy and should only be read from.

type Matrix

type Matrix interface {
	At(x, y int) float64
}

Matrix interface for the Kernel.

type MatrixPixelPoint

type MatrixPixelPoint struct {
	I, J int
}

MatrixPixelPoint defines a point in a matrix.

func GetConnectivity8Neighbors

func GetConnectivity8Neighbors(i, j, r, c int) []MatrixPixelPoint

GetConnectivity8Neighbors return the pixel coordinates of the neighbors of a pixel (i,j) in connectivity 8; Returns only the pixel within the image bounds. Connectivity 8 :

.   .   .
.   o   .
.   .   .

type MultipleImageTestDebugger

type MultipleImageTestDebugger struct {
	// contains filtered or unexported fields
}

MultipleImageTestDebugger TODO.

func NewMultipleImageTestDebugger

func NewMultipleImageTestDebugger(t *testing.T, prefixOne, glob, prefixTwo string) *MultipleImageTestDebugger

NewMultipleImageTestDebugger TODO.

func (*MultipleImageTestDebugger) Process

Process TODO.

type MultipleImageTestDebuggerProcessor

type MultipleImageTestDebuggerProcessor interface {
	Process(
		t *testing.T,
		pCtx *ProcessorContext,
		fn string,
		img image.Image,
		img2 image.Image,
		logger golog.Logger,
	) error
}

MultipleImageTestDebuggerProcessor TODO.

type Paddings

type Paddings struct {
	// PaddingLeft is the size of the left padding
	PaddingLeft int
	// PaddingRight is the size of the right padding
	PaddingRight int
	// PaddingTop is the size of the top padding
	PaddingTop int
	// PaddingBottom is the size of the bottom padding
	PaddingBottom int
}

Paddings struct holds the padding sizes for each padding.

type ProcessorContext

type ProcessorContext struct {
	// contains filtered or unexported fields
}

ProcessorContext TODO.

func (*ProcessorContext) CurrentImgConfig

func (pCtx *ProcessorContext) CurrentImgConfig(out interface{}) error

CurrentImgConfig TODO.

func (*ProcessorContext) GotDebugImage

func (pCtx *ProcessorContext) GotDebugImage(img image.Image, name string)

GotDebugImage TODO.

func (*ProcessorContext) GotDebugPointCloud

func (pCtx *ProcessorContext) GotDebugPointCloud(pc pointcloud.PointCloud, name string)

GotDebugPointCloud TODO in order to use this, you'll have to run a webserver from the output directory of the html something like: python3 -m http.server will work.

type TheColorModel

type TheColorModel struct{}

TheColorModel represents our Color type as a model to be used for color conversions in color.Color.

func (*TheColorModel) Convert

func (cm *TheColorModel) Convert(c color.Color) color.Color

Convert converts the given color into our Color type but still returns it as a go color.

type TransformationMatrix

type TransformationMatrix [][]float64

TransformationMatrix TODO.

func GetPerspectiveTransform

func GetPerspectiveTransform(src, dst []image.Point) TransformationMatrix

GetPerspectiveTransform is cribbed from opencv cv::getPerspectiveTransform.

func (TransformationMatrix) At

func (m TransformationMatrix) At(x, y int) float64

At TODO.

func (TransformationMatrix) Dims

func (m TransformationMatrix) Dims() (int, int)

Dims TODO.

type Vec2D

type Vec2D struct {
	// contains filtered or unexported fields
}

Vec2D represents the gradient of an image at a point. The gradient has both a magnitude and direction. Magnitude has values (0, infinity) and direction is [-pi, pi].

func NewVec2D

func NewVec2D(mag, dir float64) Vec2D

NewVec2D creates a new 2D vector given a magnitude and direction.

func (Vec2D) Cartesian

func (g Vec2D) Cartesian() (float64, float64)

Cartesian returns the componnents of the vector in cartesian coordinates.

func (Vec2D) Direction

func (g Vec2D) Direction() float64

Direction TODO.

func (Vec2D) Magnitude

func (g Vec2D) Magnitude() float64

Magnitude TODO.

func (Vec2D) Unit

func (g Vec2D) Unit() Vec2D

Unit returns the Vec2D with magnitude 1.

type VectorField2D

type VectorField2D struct {
	// contains filtered or unexported fields
}

VectorField2D stores all the gradient vectors of the image allowing one to retrieve the gradient for any given (x,y) point.

func ForwardDepthGradient

func ForwardDepthGradient(dm *DepthMap) VectorField2D

ForwardDepthGradient computes the forward gradients in the X and Y direction of a depth map and returns a vector field.

func MakeEmptyVectorField2D

func MakeEmptyVectorField2D(width, height int) VectorField2D

MakeEmptyVectorField2D TODO.

func SobelColorGradient

func SobelColorGradient(img *Image) (VectorField2D, error)

SobelColorGradient takes in a color image, approximates the gradient in the X and Y direction at every pixel creates a vector in polar form, and returns a vector field.

func SobelDepthGradient

func SobelDepthGradient(dm *DepthMap) VectorField2D

SobelDepthGradient computes the approximate gradients in the X and Y direction of a depth map and returns a vector field.

func VectorField2DFromDense

func VectorField2DFromDense(magnitude, direction *mat.Dense) (*VectorField2D, error)

VectorField2DFromDense returns a vector from a mat.Dense of both the magnitude and direction of the gradients of an image.

func (*VectorField2D) Blur

func (vf *VectorField2D) Blur(radius int) VectorField2D

Blur takes in a radius and creates a new blurred vector field from the input vector field.

func (*VectorField2D) Contains

func (vf *VectorField2D) Contains(x, y int) bool

Contains returns whether the given point is in the vector field.

func (*VectorField2D) DirectionField

func (vf *VectorField2D) DirectionField() *mat.Dense

DirectionField gets all the directions of the gradient in the image as a mat.Dense.

func (*VectorField2D) DirectionPicture

func (vf *VectorField2D) DirectionPicture() image.Image

DirectionPicture creates a picture of the direction that the gradients point to in the original image.

func (*VectorField2D) Get

func (vf *VectorField2D) Get(p image.Point) Vec2D

Get TODO.

func (*VectorField2D) GetVec2D

func (vf *VectorField2D) GetVec2D(x, y int) Vec2D

GetVec2D TODO.

func (*VectorField2D) Height

func (vf *VectorField2D) Height() int

Height TODO.

func (*VectorField2D) MagnitudeField

func (vf *VectorField2D) MagnitudeField() *mat.Dense

MagnitudeField gets all the magnitudes of the gradient in the image as a mat.Dense.

func (*VectorField2D) MagnitudePicture

func (vf *VectorField2D) MagnitudePicture() *image.Gray

MagnitudePicture creates a picture of the magnitude that the gradients point to in the original image.

func (*VectorField2D) MaxMagnitude

func (vf *VectorField2D) MaxMagnitude() float64

MaxMagnitude returns the largest magnitude value in the field.

func (*VectorField2D) Set

func (vf *VectorField2D) Set(x, y int, val Vec2D)

Set TODO.

func (*VectorField2D) Width

func (vf *VectorField2D) Width() int

Width TODO.

type WarpConnector

type WarpConnector interface {
	// return is if the point is valid or not
	Get(x, y int, buf []float64) bool
	Set(x, y int, data []float64)
	OutputDims() (int, int)
	NumFields() int // how many float64 are in the buffers above
}

WarpConnector TODO.

type WarpImageConnector

type WarpImageConnector struct {
	Input  *Image
	Output *Image
}

WarpImageConnector TODO.

func (*WarpImageConnector) Get

func (c *WarpImageConnector) Get(x, y int, buf []float64) bool

Get TODO.

func (*WarpImageConnector) NumFields

func (c *WarpImageConnector) NumFields() int

NumFields TODO.

func (*WarpImageConnector) OutputDims

func (c *WarpImageConnector) OutputDims() (int, int)

OutputDims TODO.

func (*WarpImageConnector) Set

func (c *WarpImageConnector) Set(x, y int, data []float64)

Set TODO.

type WarpMatrixConnector

type WarpMatrixConnector struct {
	Input  mat.Matrix
	Output *mat.Dense
}

WarpMatrixConnector TODO.

func (*WarpMatrixConnector) Get

func (c *WarpMatrixConnector) Get(x, y int, buf []float64) bool

Get TODO.

func (*WarpMatrixConnector) NumFields

func (c *WarpMatrixConnector) NumFields() int

NumFields TODO.

func (*WarpMatrixConnector) OutputDims

func (c *WarpMatrixConnector) OutputDims() (int, int)

OutputDims TODO.

func (*WarpMatrixConnector) Set

func (c *WarpMatrixConnector) Set(x, y int, data []float64)

Set TODO.

Directories

Path Synopsis
cmd
stream_camera
Package main streams a specific camera over WebRTC.
Package main streams a specific camera over WebRTC.
Package depthadapter is a simple package that turns a DepthMap into a point cloud using intrinsic parameters of a camera.
Package depthadapter is a simple package that turns a DepthMap into a point cloud using intrinsic parameters of a camera.
Package transform provides image transformation utilities relying on camera parameters.
Package transform provides image transformation utilities relying on camera parameters.
cmd/depth_to_color
Get the coordinates of a depth pixel in the depth map in the reference frame of the color image $./depth_to_color -conf=/path/to/intrinsics/extrinsic/file X Y Z
Get the coordinates of a depth pixel in the depth map in the reference frame of the color image $./depth_to_color -conf=/path/to/intrinsics/extrinsic/file X Y Z
cmd/extrinsic_calibration
Given at least 4 corresponding points, and the intrinsic matrices of both cameras, computes the rigid transform (rotation + translation) that would be the extrinsic transformation from camera 1 to camera 2.
Given at least 4 corresponding points, and the intrinsic matrices of both cameras, computes the rigid transform (rotation + translation) that would be the extrinsic transformation from camera 1 to camera 2.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL