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
- Variables
- func AllPointsIn(size image.Point, pts []image.Point) bool
- func AreCollinear(a, b, c r2.Point, eps float64) bool
- func ArrayToPoints(pts []image.Point) []image.Point
- func BoundingBox(pts []image.Point) image.Rectangle
- func Center(contour []image.Point, maxDiff int) image.Point
- func CleanDepthMap(dm *DepthMap)
- func ClusterImage(clusters []Color, img *Image) *image.RGBA
- func CompareImages(img1, img2 image.Image) (int, image.Image, error)
- func ConvertColorImageToLuminanceFloat(img *Image) *mat.Dense
- func ConvertImageToGray16(img image.Image) (*image.Gray16, error)
- func ConvertToNRGBA(c color.Color) color.NRGBA
- func ConvertToRGBA(dst *image.RGBA, src *Image)
- func ConvolveGray(img *image.Gray, kernel *Kernel, anchor image.Point, border BorderPad) (*image.Gray, error)
- func ConvolveGrayFloat64(m *mat.Dense, filter *Kernel) (*mat.Dense, error)
- func CountBrightSpots(img *image.Gray, center image.Point, radius int, threshold uint8) int
- func DecodeImage(ctx context.Context, imgBytes []byte, mimeType string) (image.Image, error)
- func DecodeJPEG(r io.Reader) (img image.Image, err error)
- func DrawRectangleEmpty(dc *gg.Context, r image.Rectangle, c color.Color, width float64)
- func DrawString(dc *gg.Context, text string, p image.Point, c color.Color, size float64)
- func EdgeHysteresisFiltering(mag *mat.Dense, low, high float64) (*image.Gray, error)
- func EncodeImage(ctx context.Context, img image.Image, mimeType string) ([]byte, error)
- func EncodeJPEG(w io.Writer, src image.Image) error
- func Font() *truetype.Font
- func GetGrayAvg(pic *image.Gray16) int
- func GetGraySum(gray *image.Gray16) int
- func GetHysteresisThresholds(mag, nms *mat.Dense, ratioHigh, ratioLow float64) (float64, float64, error)
- func GradientNonMaximumSuppressionC8(mag, direction *mat.Dense) (*mat.Dense, error)
- func ImageToFloatBuffer(img image.Image, changeToBGR bool, meanValue, stdDev []float32) []float32
- func ImageToUInt8Buffer(img image.Image, changeToBGR bool) []byte
- func ImageToYCbCrForTesting(dst *image.YCbCr, src image.Image)
- func IsImageFile(fn string) bool
- func IterateImage(img image.Image, f func(x, y int, c color.Color) bool)
- func Luminance(aColor Color) float64
- func MakeGray(pic *Image) *image.Gray
- func MissingDepthData(dm *DepthMap) *image.Gray
- func MorphFilter(inDM, outDM *DepthMap, kernelSize, iterations int, ...) error
- func MultiplyGrays(g1, g2 *image.Gray) (*image.Gray16, error)
- func NewH264Image(bytes []byte, width, height, gopSize int) image.Image
- func NewLazyEncodedImage(imgBytes []byte, mimeType string) image.Image
- func Overlay(i *Image, dm *DepthMap) *image.NRGBA
- func PaddingFloat64(img *mat.Dense, kernelSize, anchor image.Point, border BorderPad) (*mat.Dense, error)
- func PaddingGray(img *image.Gray, kernelSize, anchor image.Point, border BorderPad) (*image.Gray, error)
- func PointAngle(a, b image.Point) float64
- func PointDistance(a, b image.Point) float64
- func R2PointToImagePoint(pt r2.Point) image.Point
- func R2RectToImageRect(rec r2.Rect) image.Rectangle
- func SameImgSize(g1, g2 image.Image) bool
- func SaveImage(pic image.Image, loc string) error
- func SimpleEdgeDetection(img *Image, t1, blur float64) (*image.Gray, error)
- func SliceVecsToXsYs(pts []r2.Point) ([]float64, []float64)
- func TranslateR2Rect(rect r2.Rect, pt r2.Point) r2.Rect
- func Warp(input WarpConnector, m TransformationMatrix)
- func WarpColorDepth(col *Image, dm *DepthMap, src, dst []image.Point, newSize image.Point) (*Image, *DepthMap)
- func WriteImageToFile(path string, img image.Image) (err error)
- func WriteRawDepthMapTo(img image.Image, out io.Writer) (int64, error)
- func WriteRawDepthMapToFile(dm image.Image, fn string) (err error)
- func WriteViamDepthMapTo(img image.Image, out io.Writer) (int64, error)
- type BorderPad
- type CannyEdgeDetector
- type Color
- func AverageColor(colors []Color, weights ...float64) Color
- func BilinearInterpolationColor(pt r2.Point, img *Image) *Color
- func ClusterFromImage(img *Image, numClusters int) ([]Color, error)
- func ClusterHSV(data []Color, numClusters int) ([]Color, error)
- func NearestNeighborColor(pt r2.Point, img *Image) *Color
- func NewColor(r, g, b uint8) Color
- func NewColorFromArray(buf []float64) Color
- func NewColorFromColor(c color.Color) Color
- func NewColorFromHSV(h, s, v float64) Color
- func NewColorFromHex(hex string) (Color, error)
- func NewColorFromHexOrPanic(hex string) Color
- func (c Color) Closest(others []Color) (int, Color, float64)
- func (c Color) Distance(b Color) float64
- func (c Color) DistanceLab(b Color) float64
- func (c Color) Hex() string
- func (c Color) HsvNormal() (float64, float64, float64)
- func (c Color) RGB255() (uint8, uint8, uint8)
- func (c Color) RGBA() (r, g, b, a uint32)
- func (c Color) RawFloatArray() []float64
- func (c Color) RawFloatArrayFill(buf []float64) []float64
- func (c Color) ScaleHSV() (float64, float64, float64)
- func (c Color) String() string
- type ColorDiff
- type ColorDiffs
- type Depth
- type DepthMap
- func ClosingMorph(dm *DepthMap, kernelSize, iterations int) (*DepthMap, error)
- func ConvertImageToDepthMap(ctx context.Context, img image.Image) (*DepthMap, error)
- func FillDepthMap(dm *DepthMap, img *Image) (*DepthMap, error)
- func GaussianSmoothing(dm *DepthMap, sigma float64) (*DepthMap, error)
- func JointBilateralSmoothing(dm *DepthMap, spatialSigma, depthSigma float64) (*DepthMap, error)
- func NewDepthMapFromFile(ctx context.Context, fn string) (*DepthMap, error)
- func NewEmptyDepthMap(width, height int) *DepthMap
- func OpeningMorph(dm *DepthMap, kernelSize, iterations int) (*DepthMap, error)
- func ParseRawDepthMap(fn string) (*DepthMap, error)
- func PreprocessDepthMap(dm *DepthMap, img *Image) (*DepthMap, error)
- func ReadDepthMap(r io.Reader) (*DepthMap, error)
- func SavitskyGolaySmoothing(dm *DepthMap, validPoints *image.Gray, radius, polyOrder int) (*DepthMap, error)
- func (dm *DepthMap) At(x, y int) color.Color
- func (dm *DepthMap) AverageDepthAndStats(p image.Point, radius int) (float64, float64)
- func (dm *DepthMap) Bounds() image.Rectangle
- func (dm *DepthMap) Clone() *DepthMap
- func (dm *DepthMap) ColorModel() color.Model
- func (dm *DepthMap) Contains(x, y int) bool
- func (dm *DepthMap) ConvertDepthMapToLuminanceFloat() *mat.Dense
- func (dm *DepthMap) Data() []Depth
- func (dm *DepthMap) Get(p image.Point) Depth
- func (dm *DepthMap) GetDepth(x, y int) Depth
- func (dm *DepthMap) Height() int
- func (dm *DepthMap) InterestingPixels(t float64) *image.Gray
- func (dm *DepthMap) MinMax() (Depth, Depth)
- func (dm *DepthMap) Rotate(amount int) *DepthMap
- func (dm *DepthMap) Rotate180() *DepthMap
- func (dm *DepthMap) Rotate90(clockwise bool) *DepthMap
- func (dm *DepthMap) Set(x, y int, val Depth)
- func (dm *DepthMap) SubImage(rect image.Rectangle) *DepthMap
- func (dm *DepthMap) ToGray16Picture() *image.Gray16
- func (dm *DepthMap) ToPrettyPicture(hardMin, hardMax Depth) *Image
- func (dm *DepthMap) Warp(m TransformationMatrix, newSize image.Point) *DepthMap
- func (dm *DepthMap) Width() int
- func (dm *DepthMap) WriteToBuf(out io.Writer) error
- type EdgeDetector
- type H264
- type HSVObservation
- type Image
- func CloneImage(img image.Image) *Image
- func ConvertImage(img image.Image) *Image
- func NewImage(width, height int) *Image
- func NewImageFromBounds(bounds image.Rectangle) *Image
- func NewImageFromFile(fn string) (*Image, error)
- func WarpImage(img image.Image, m TransformationMatrix, newSize image.Point) *Image
- func (i *Image) At(x, y int) color.Color
- func (i *Image) AverageColor(p image.Point, radius int) Color
- func (i *Image) AverageColorAndStats(p image.Point, radius int) (Color, float64)
- func (i *Image) AverageColorXY(x, y, radius int) Color
- func (i *Image) Bounds() image.Rectangle
- func (i *Image) Circle(center image.Point, radius int, c Color)
- func (i *Image) Clone() *Image
- func (i *Image) ColorModel() color.Model
- func (i *Image) Get(p image.Point) Color
- func (i *Image) GetXY(x, y int) Color
- func (i *Image) Height() int
- func (i *Image) In(x, y int) bool
- func (i *Image) InterestingPixels(t float64) *image.Gray
- func (i *Image) Rotate(amount int) *Image
- func (i *Image) Set(p image.Point, c Color)
- func (i *Image) SetXY(x, y int, c Color)
- func (i *Image) SubImage(r image.Rectangle) *Image
- func (i *Image) Width() int
- func (i *Image) WriteTo(fn string) error
- type ImageGradient
- type Kernel
- type LazyEncodedImage
- func (lei *LazyEncodedImage) At(x, y int) color.Color
- func (lei *LazyEncodedImage) Bounds() image.Rectangle
- func (lei *LazyEncodedImage) ColorModel() color.Model
- func (lei *LazyEncodedImage) DecodedImage() image.Image
- func (lei *LazyEncodedImage) MIMEType() string
- func (lei *LazyEncodedImage) RawData() []byte
- type Matrix
- type MatrixPixelPoint
- type MultipleImageTestDebugger
- type MultipleImageTestDebuggerProcessor
- type Paddings
- type ProcessorContext
- type TheColorModel
- type TransformationMatrix
- type Vec2D
- type VectorField2D
- func ForwardDepthGradient(dm *DepthMap) VectorField2D
- func MakeEmptyVectorField2D(width, height int) VectorField2D
- func SobelColorGradient(img *Image) (VectorField2D, error)
- func SobelDepthGradient(dm *DepthMap) VectorField2D
- func VectorField2DFromDense(magnitude, direction *mat.Dense) (*VectorField2D, error)
- func (vf *VectorField2D) Blur(radius int) VectorField2D
- func (vf *VectorField2D) Contains(x, y int) bool
- func (vf *VectorField2D) DirectionField() *mat.Dense
- func (vf *VectorField2D) DirectionPicture() image.Image
- func (vf *VectorField2D) Get(p image.Point) Vec2D
- func (vf *VectorField2D) GetVec2D(x, y int) Vec2D
- func (vf *VectorField2D) Height() int
- func (vf *VectorField2D) MagnitudeField() *mat.Dense
- func (vf *VectorField2D) MagnitudePicture() *image.Gray
- func (vf *VectorField2D) MaxMagnitude() float64
- func (vf *VectorField2D) Set(x, y int, val Vec2D)
- func (vf *VectorField2D) Width() int
- type WarpConnector
- type WarpImageConnector
- type WarpMatrixConnector
Constants ¶
const MagicNumIntVersionX = 6363110499870197078
MagicNumIntVersionX is the magic number (as an int) for VERSIONX.
const MagicNumIntViamType = 4919426490892632400
MagicNumIntViamType is the magic number (as an int) for the custom Viam depth type. magic number for ViamCustomType is uint64([]byte("DEPTHMAP")), Big Endian.
const MagicNumIntViamTypeLittleEndian = 5782988369567958340
MagicNumIntViamTypeLittleEndian is "PAMHTPED" for the ReadDepthMap function which uses LittleEndian to read.
const MaxDepth = Depth(math.MaxUint16)
MaxDepth is the maximum allowed depth.
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 .
const RawRGBAHeaderLength = 12
RawRGBAHeaderLength is the length of our custom header for raw RGBA data in bytes. See above as to why.
Variables ¶
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.
var DepthMapMagicNumber = []byte("DEPTHMAP")
DepthMapMagicNumber represents the magic number for our custom header for raw DEPTH data.
var NoPoints = image.Point{-1, -1}
NoPoints TODO.
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 AreCollinear ¶
AreCollinear returns true if the 3 points a, b and c are collinear.
func CleanDepthMap ¶
func CleanDepthMap(dm *DepthMap)
CleanDepthMap removes the connected regions of data below a certain size thershold.
func CompareImages ¶
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 ¶
ConvertColorImageToLuminanceFloat convert an Image to a gray level image as a float dense matrix.
func ConvertImageToGray16 ¶ added in v0.0.8
ConvertImageToGray16 takes an image and figures out if it's already an image.Gray16 or if it can be converted into one.
func ConvertToNRGBA ¶
ConvertToNRGBA converts a go color to an NRGBA color.
func ConvertToRGBA ¶ added in v0.2.24
ConvertToRGBA converts an rimage.Image type image to image.RGBA.
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 ¶
ConvolveGrayFloat64 implements a gray float64 image convolution with the Kernel filter There is no clamping in this case.
func CountBrightSpots ¶
CountBrightSpots TODO.
func DecodeImage ¶
DecodeImage takes an image buffer and decodes it, using the mimeType and the dimensions, to return the image.
func DecodeJPEG ¶ added in v0.2.24
DecodeJPEG decode JPEG []bytes into an image.Image using libjpeg.
func DrawRectangleEmpty ¶
DrawRectangleEmpty draws the given rectangle into the context. The positions of the rectangle are used to place it within the context.
func DrawString ¶
DrawString writes a string to the given context at a particular point.
func EdgeHysteresisFiltering ¶
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 ¶
EncodeImage takes an image and mimeType as input and encodes it into a slice of bytes (buffer) and returns the bytes.
func EncodeJPEG ¶ added in v0.2.24
EncodeJPEG encode an image.Image in JPEG using libjpeg.
func GetGrayAvg ¶
GetGrayAvg takes in a grayscale image and returns the average value as an int.
func GetGraySum ¶
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 ¶
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 ImageToFloatBuffer ¶ added in v0.2.35
ImageToFloatBuffer reads an image into a byte slice (buffer) the most common sense way. Left to right like a book; R, then G, then B. No funny stuff. Assumes values between -1 and 1. if changeToBGR is true, then R and B get swapped. if meanValue and stdDev are not length 0, use those instead to normalize the bytes.
func ImageToUInt8Buffer ¶ added in v0.2.35
ImageToUInt8Buffer reads an image into a byte slice in the most common sense way. Left to right like a book; R, then G, then B. No funny stuff. Assumes values should be between 0-255. if changeToBGR is true, then R and B get swapped.
func ImageToYCbCrForTesting ¶ added in v0.1.5
ImageToYCbCrForTesting converts an image to YCbCr. It is only to be used for testing.
func IsImageFile ¶
IsImageFile returns if the given file is an image file based on what we support.
func IterateImage ¶
IterateImage visits each point in the image and calls the given visitor function that can control whether or not to continue iteration.
func Luminance ¶
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 MissingDepthData ¶
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 ¶
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 NewH264Image ¶ added in v0.17.0
NewH264Image returns a new image.Image from the given bytes and stores the given parameters.
func NewLazyEncodedImage ¶ added in v0.0.8
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 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 R2PointToImagePoint ¶
R2PointToImagePoint TODO.
func R2RectToImageRect ¶
R2RectToImageRect TODO.
func SameImgSize ¶
SameImgSize compares image.Grays to see if they're the same size.
func SaveImage ¶
SaveImage takes an image.Image and saves it to a jpeg at the given file location and also returns the location back.
func SimpleEdgeDetection ¶
SimpleEdgeDetection TODO.
func SliceVecsToXsYs ¶
SliceVecsToXsYs converts a slice of r2.Point to 2 slices floats containing x and y coordinates.
func TranslateR2Rect ¶
TranslateR2Rect 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 ¶
WriteImageToFile writes the given image to a file at the supplied path.
func WriteRawDepthMapTo ¶ added in v0.0.7
WriteRawDepthMapTo writes this depth map to the given writer. the raw depth map type writes 8 bytes of width, 8 bytes of height, and 8 bytes per pixel.
func WriteRawDepthMapToFile ¶ added in v0.0.7
WriteRawDepthMapToFile writes the raw depth map to the given file.
func WriteViamDepthMapTo ¶ added in v0.2.23
WriteViamDepthMapTo writes depth map or gray16 image to the given writer as vnd.viam.dep bytes. the Viam custom depth type writes 8 bytes of "magic number", 8 bytes of width, 8 bytes of height, and 2 bytes per pixel.
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 ¶
DetectDepthEdges uses a Canny edge detector to find edges in a depth map and returns a grayscale image of edges.
func (*CannyEdgeDetector) DetectEdges ¶
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 ¶
AverageColor returns the average of the HSV color. H is angle in degrees. optional weights for the average.
func BilinearInterpolationColor ¶
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 ¶
ClusterFromImage TODO.
func NearestNeighborColor ¶
NearestNeighborColor takes the value of the closest point to the intermediate pixel.
func NewColorFromArray ¶
NewColorFromArray returns a color based off the bytes in array mapping to the byte fields of a Color.
func NewColorFromColor ¶
NewColorFromColor takes in a go Color and finds the best conversion to our Color.
func NewColorFromHSV ¶
NewColorFromHSV returns a color based off HSV.
func NewColorFromHex ¶
NewColorFromHex returns a color from a RGB hex value.
func NewColorFromHexOrPanic ¶
NewColorFromHexOrPanic returns a color from a RGB hex value. It panics if there is an error parsing.
func (Color) Closest ¶
Closest returns the color that is closet to this color based on the given slice of colors.
func (Color) DistanceLab ¶
DistanceLab returns a measure of visual similarity between two colors.
func (Color) HsvNormal ¶
HsvNormal returns a normalized HSV representation of the color. h : 0 -> 360, s,v : 0 -> 1.0.
func (Color) RawFloatArray ¶
RawFloatArray returns the byte fields of the color.
func (Color) RawFloatArrayFill ¶
RawFloatArrayFill sets the bytes fields of the color on the given slice that must have a length of at least 6.
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) 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) 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 ¶
BilinearInterpolationDepth approximates the Depth value between pixels according to a bilinear interpolation. A nil return value means the interpolation is out of bounds.
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 ¶
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 ¶
ConvertImageToDepthMap takes an image and figures out if it's already a DepthMap or if it can be converted into one.
func FillDepthMap ¶
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 ¶
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 ¶
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 ¶
NewDepthMapFromFile extract the depth map from a Z16 image file or a .dat image file.
func NewEmptyDepthMap ¶
NewEmptyDepthMap returns an unset depth map with the given dimensions.
func OpeningMorph ¶
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
ParseRawDepthMap parses a depth map from the given file. It knows how to handle compressed files as well.
func PreprocessDepthMap ¶
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 ¶
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 ¶
At returns the depth value as a color.Color so DepthMap can implement image.Image.
func (*DepthMap) AverageDepthAndStats ¶
AverageDepthAndStats returns average distance, average distance to avg. TODO(erh): should this be std. dev?
func (*DepthMap) ColorModel ¶
ColorModel for DepthMap so that it implements image.Image.
func (*DepthMap) Contains ¶
Contains returns whether or not a point is within bounds of the depth map.
func (*DepthMap) ConvertDepthMapToLuminanceFloat ¶
ConvertDepthMapToLuminanceFloat converts this depth map into a grayscale image of the same dimensions.
func (*DepthMap) InterestingPixels ¶
InterestingPixels TODO.
func (*DepthMap) Rotate90 ¶
Rotate90 rotates a copy of this depth map either by 90 degrees clockwise or counterclockwise.
func (*DepthMap) SubImage ¶
SubImage returns a cropped image of the original DepthMap from the given rectangle.
func (*DepthMap) ToGray16Picture ¶
ToGray16Picture converts this depth map into a grayscale image of the same dimensions.
func (*DepthMap) ToPrettyPicture ¶
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.
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 H264 ¶ added in v0.17.0
H264 is an image.Image that holds an H264 encoded frame.
func (H264) ColorModel ¶ added in v0.17.0
ColorModel unimplemented.
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 ¶
CloneImage creates a copy of the input image.
func ConvertImage ¶
ConvertImage converts a go image into our Image type.
func NewImageFromBounds ¶
NewImageFromBounds returns blank new of dimensions defined by the given rectangle.
func NewImageFromFile ¶
NewImageFromFile returns an image read in from the given file.
func (*Image) AverageColor ¶
AverageColor returns the average color about a certain point.
func (*Image) AverageColorAndStats ¶
AverageColorAndStats returns avg color and avg distances to avg color.
func (*Image) AverageColorXY ¶
AverageColorXY returns the average color about a certain point.
func (*Image) Bounds ¶
Bounds returns the outer bounds of this image. Otherwise known as its dimensions.
func (*Image) ColorModel ¶
ColorModel returns our Color types color model.
func (*Image) InterestingPixels ¶
InterestingPixels TODO TODO(erh): this and SimpleEdgeDetection are super similar, we shouldn't have both probably? or if we do need better names.
type ImageGradient ¶
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 ¶
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 ¶
NewKernel creates a new Kernel with the given width and height. The value for every position of the kernel is 0.
func (*Kernel) Normalize ¶
Normalize returns a normalized kernel where each value is divided by the absolute sum 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) DecodedImage ¶ added in v0.25.0
func (lei *LazyEncodedImage) DecodedImage() image.Image
DecodedImage returns the decoded image.
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 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 ¶
func (d *MultipleImageTestDebugger) Process(t *testing.T, x MultipleImageTestDebuggerProcessor) (err error)
Process TODO.
type MultipleImageTestDebuggerProcessor ¶
type MultipleImageTestDebuggerProcessor interface { Process( t *testing.T, pCtx *ProcessorContext, fn string, img image.Image, img2 image.Image, logger logging.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.
type TransformationMatrix ¶
type TransformationMatrix [][]float64
TransformationMatrix TODO.
func GetPerspectiveTransform ¶
func GetPerspectiveTransform(src, dst []image.Point) TransformationMatrix
GetPerspectiveTransform is cribbed from opencv cv::getPerspectiveTransform.
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].
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) 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.
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 ¶
WarpImageConnector TODO.
func (*WarpImageConnector) Get ¶
func (c *WarpImageConnector) Get(x, y int, buf []float64) bool
Get 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 ¶
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.
Source Files ¶
- color.go
- color_cluster.go
- color_utils.go
- compare_img.go
- convkernel.go
- convolution.go
- convolution_helpers.go
- depth_filling.go
- depth_map.go
- depth_map_raw.go
- depth_processing.go
- draw.go
- filters.go
- gradient.go
- gray_image_helpers.go
- image.go
- image_file.go
- image_processing.go
- image_with_depth.go
- lazy_encoded.go
- libjpeg.go
- morphological.go
- point_utils.go
- test_helper.go
- warp.go
Directories ¶
Path | Synopsis |
---|---|
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. |