Class Image<TColor, TDepth>
An Image is a wrapper to IplImage of OpenCV.
public class Image<TColor, TDepth> : CvArray<TDepth>, IXmlSerializable, ISerializable, IEquatable<Image<TColor, TDepth>>, IInputOutputArray, IInputArrayOfArrays, IOutputArrayOfArrays, IOutputArray, IInputArray, IDisposable where TColor : struct, IColor where TDepth : new()
Type Parameters
TColor
Color type of this image (either Gray, Bgr, Bgra, Hsv, Hls, Lab, Luv, Xyz, Ycc, Rgb or Rbga)
TDepth
Depth of this image (either Byte, SByte, Single, double, UInt16, Int16 or Int32)
- Inheritance
-
CvArray<TDepth>Image<TColor, TDepth>
- Implements
-
IXmlSerializableIEquatable<Image<TColor, TDepth>>
- Derived
- Inherited Members
- Extension Methods
Constructors
Image()
Create an empty Image
protected Image()
Image(Image<Gray, TDepth>[])
Create a multi-channel image from multiple gray scale images
public Image(Image<Gray, TDepth>[] channels)
Parameters
Image(Mat)
Create an Image by copying data from a Mat.
public Image(Mat mat)
Parameters
mat
MatThe Mat to copy pixel data from
Image(Size)
Create a blank Image of the specific size
public Image(Size size)
Parameters
size
SizeThe size of the image
Image(int, int)
Create a blank Image of the specified width and height.
public Image(int width, int height)
Parameters
Image(int, int, int, nint)
Create an Image from unmanaged data.
public Image(int width, int height, int stride, nint scan0)
Parameters
width
intThe width of the image
height
intThe height of the image
stride
intSize of aligned image row in bytes
scan0
nintPointer to aligned image data, where each row should be 4-align
Remarks
The caller is responsible for allocating and freeing the block of memory specified by the scan0 parameter, however, the memory should not be released until the related Image is released.
Image(int, int, TColor)
Create a blank Image of the specified width, height and color.
public Image(int width, int height, TColor value)
Parameters
width
intThe width of the image
height
intThe height of the image
value
TColorThe initial color of the image
Image(SerializationInfo, StreamingContext)
Constructor used to deserialize runtime serialized object
public Image(SerializationInfo info, StreamingContext context)
Parameters
info
SerializationInfoThe serialization info
context
StreamingContextThe streaming context
Image(string)
Read image from a file
public Image(string fileName)
Parameters
fileName
stringthe name of the file that contains the image
Image(TDepth[,,])
Create image from the specific multi-dimensional data, where the 1st dimension is # of rows (height), the 2nd dimension is # cols (width) and the 3rd dimension is the channel
public Image(TDepth[,,] data)
Parameters
data
TDepth[,,]The multi-dimensional data where the 1st dimension is # of rows (height), the 2nd dimension is # cols (width) and the 3rd dimension is the channel
Properties
CvDepth
Get the equivalent opencv depth type for this image
public static IplDepth CvDepth { get; }
Property Value
Data
Get or Set the data for this matrix. The Get function has O(1) complexity. The Set function make a copy of the data
public TDepth[,,] Data { get; set; }
Property Value
- TDepth[,,]
Remarks
If the image contains Byte and width is not a multiple of 4. The second dimension of the array might be larger than the Width of this image.
This is necessary since the length of a row need to be 4 align for OpenCV optimization.
The Set function always make a copy of the specific value. If the image contains Byte and width is not a multiple of 4. The second dimension of the array created might be larger than the Width of this image.
IsROISet
Indicates if the region of interest has been set
public bool IsROISet { get; }
Property Value
this[Point]
Get or Set the color in the location
public TColor this[Point location] { get; set; }
Parameters
location
Pointthe location of the pixel
Property Value
- TColor
the color in the
location
this[int]
Get or Set the specific channel of the current image. For Get operation, a copy of the specific channel is returned. For Set operation, the specific channel is copied to this image.
public Image<Gray, TDepth> this[int channel] { get; set; }
Parameters
channel
intThe channel to get from the current image, zero based index
Property Value
this[int, int]
Get or Set the color in the row
th row (y direction) and column
th column (x direction)
public TColor this[int row, int column] { get; set; }
Parameters
row
intThe zero-based row (y direction) of the pixel
column
intThe zero-based column (x direction) of the pixel
Property Value
- TColor
The color in the specific
row
andcolumn
MIplImage
The IplImage structure
public MIplImage MIplImage { get; }
Property Value
ManagedArray
Get the underneath managed array
public override Array ManagedArray { get; set; }
Property Value
NumberOfChannels
Get the number of channels for this image
public override int NumberOfChannels { get; }
Property Value
ROI
Get or Set the region of interest for this image. To clear the ROI, set it to System.Drawing.Rectangle.Empty
public Rectangle ROI { get; set; }
Property Value
Size
Get the size of the array
public override Size Size { get; }
Property Value
Methods
AbsDiff(Image<TColor, TDepth>)
Computes absolute different between this image and the other image
public Image<TColor, TDepth> AbsDiff(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The other image to compute absolute different with
Returns
- Image<TColor, TDepth>
The image that contains the absolute different value
AbsDiff(TColor)
Computes absolute different between this image and the specific color
[ExposableMethod(Exposable = true, Category = "Math")]
public Image<TColor, TDepth> AbsDiff(TColor color)
Parameters
color
TColorThe color to compute absolute different with
Returns
- Image<TColor, TDepth>
The image that contains the absolute different value
Accumulate(Image<TColor, TDepth>)
Accumulate img2
to the current image using the specific mask
public void Accumulate(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The image to be added to the current image
Accumulate(Image<TColor, TDepth>, Image<Gray, byte>)
Accumulate img2
to the current image using the specific mask
public void Accumulate(Image<TColor, TDepth> img2, Image<Gray, byte> mask)
Parameters
img2
Image<TColor, TDepth>The image to be added to the current image
mask
Image<Gray, byte>the mask
AccumulateWeighted(Image<TColor, TDepth>, double, Image<Gray, byte>)
Update Running Average. this = (1-alpha)this + alphaimg, using the mask
public void AccumulateWeighted(Image<TColor, TDepth> img, double alpha, Image<Gray, byte> mask = null)
Parameters
img
Image<TColor, TDepth>Input image, 1- or 3-channel, Byte or Single (each channel of multi-channel image is processed independently).
alpha
doubleThe weight of
img
mask
Image<Gray, byte>The mask for the running average
Action(Action<TDepth>)
perform an generic action based on each element of the image
public void Action(Action<TDepth> action)
Parameters
action
Action<TDepth>The action to be applied to each element of the image
Action<TOtherDepth>(Image<TColor, TOtherDepth>, Action<TDepth, TOtherDepth>)
Perform an generic operation based on the elements of the two images
public void Action<TOtherDepth>(Image<TColor, TOtherDepth> img2, Action<TDepth, TOtherDepth> action) where TOtherDepth : new()
Parameters
img2
Image<TColor, TOtherDepth>The second image to perform action on
action
Action<TDepth, TOtherDepth>An action such that the first parameter is the a single channel of a pixel from the first image, the second parameter is the corresponding channel of the correspondind pixel from the second image
Type Parameters
TOtherDepth
The depth of the second image
Add(Image<TColor, TDepth>)
Elementwise add another image with the current image
public Image<TColor, TDepth> Add(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The image to be added to the current image
Returns
- Image<TColor, TDepth>
The result of elementwise adding img2 to the current image
Add(Image<TColor, TDepth>, Image<Gray, byte>)
Elementwise add img2
with the current image, using a mask
public Image<TColor, TDepth> Add(Image<TColor, TDepth> img2, Image<Gray, byte> mask)
Parameters
img2
Image<TColor, TDepth>The image to be added to the current image
mask
Image<Gray, byte>The mask for the add operation
Returns
- Image<TColor, TDepth>
The result of elementwise adding img2 to the current image, using the specific mask
Add(TColor)
Elementwise add a color val
to the current image
[ExposableMethod(Exposable = true, Category = "Math")]
public Image<TColor, TDepth> Add(TColor val)
Parameters
val
TColorThe color value to be added to the current image
Returns
- Image<TColor, TDepth>
The result of elementwise adding color
val
from the current image
AddWeighted(Image<TColor, TDepth>, double, double, double)
Return the weighted sum such that: res = this * alpha + img2 * beta + gamma
public Image<TColor, TDepth> AddWeighted(Image<TColor, TDepth> img2, double alpha, double beta, double gamma)
Parameters
img2
Image<TColor, TDepth>img2 in: res = this * alpha + img2 * beta + gamma
alpha
doublealpha in: res = this * alpha + img2 * beta + gamma
beta
doublebeta in: res = this * alpha + img2 * beta + gamma
gamma
doublegamma in: res = this * alpha + img2 * beta + gamma
Returns
- Image<TColor, TDepth>
this * alpha + img2 * beta + gamma
AllocateData(int, int, int)
Re-allocate data for the array
protected override void AllocateData(int rows, int cols, int numberOfChannels)
Parameters
rows
intThe number of rows
cols
intThe number of columns
numberOfChannels
intThe number of channels of this image
And(Image<TColor, TDepth>)
Perform an elementwise AND operation with another image and return the result
public Image<TColor, TDepth> And(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The second image for the AND operation
Returns
- Image<TColor, TDepth>
The result of the AND operation
And(Image<TColor, TDepth>, Image<Gray, byte>)
Perform an elementwise AND operation with another image, using a mask, and return the result
public Image<TColor, TDepth> And(Image<TColor, TDepth> img2, Image<Gray, byte> mask)
Parameters
img2
Image<TColor, TDepth>The second image for the AND operation
mask
Image<Gray, byte>The mask for the AND operation
Returns
- Image<TColor, TDepth>
The result of the AND operation
And(TColor)
Perform an binary AND operation with some color
public Image<TColor, TDepth> And(TColor val)
Parameters
val
TColorThe color for the AND operation
Returns
- Image<TColor, TDepth>
The result of the AND operation
And(TColor, Image<Gray, byte>)
Perform an binary AND operation with some color using a mask
public Image<TColor, TDepth> And(TColor val, Image<Gray, byte> mask)
Parameters
Returns
- Image<TColor, TDepth>
The result of the AND operation
AvgSdv(out TColor, out MCvScalar)
Calculates the average value and standard deviation of array elements, independently for each channel
public void AvgSdv(out TColor avg, out MCvScalar sdv)
Parameters
avg
TColorThe avg color
sdv
MCvScalarThe standard deviation for each channel
AvgSdv(out TColor, out MCvScalar, Image<Gray, byte>)
Calculates the average value and standard deviation of array elements, independently for each channel
public void AvgSdv(out TColor average, out MCvScalar sdv, Image<Gray, byte> mask)
Parameters
average
TColorThe avg color
sdv
MCvScalarThe standard deviation for each channel
mask
Image<Gray, byte>The operation mask
BuildPyramid(int)
Compute the image pyramid
public Image<TColor, TDepth>[] BuildPyramid(int maxLevel)
Parameters
maxLevel
intThe number of level's for the pyramid; Level 0 referes to the current image, level n is computed by calling the PyrDown() function on level n-1
Returns
- Image<TColor, TDepth>[]
The image pyramid
Canny(double, double)
Find the edges on this image and marked them in the returned image.
[ExposableMethod(Exposable = true, Category = "Gradients, Edges")]
public Image<Gray, byte> Canny(double thresh, double threshLinking)
Parameters
thresh
doubleThe threshhold to find initial segments of strong edges
threshLinking
doubleThe threshold used for edge Linking
Returns
Canny(double, double, int, bool)
Find the edges on this image and marked them in the returned image.
public Image<Gray, byte> Canny(double thresh, double threshLinking, int apertureSize, bool l2Gradient)
Parameters
thresh
doubleThe threshhold to find initial segments of strong edges
threshLinking
doubleThe threshold used for edge Linking
apertureSize
intThe aperture size, use 3 for default
l2Gradient
boola flag, indicating whether a more accurate norm should be used to calculate the image gradient magnitude ( L2gradient=true ), or whether the default norm is enough ( L2gradient=false ).
Returns
Clone()
Make a clone of the current image. All image data as well as the COI and ROI are cloned
public Image<TColor, TDepth> Clone()
Returns
- Image<TColor, TDepth>
A clone of the current image. All image data as well as the COI and ROI are cloned
Cmp(Image<TColor, TDepth>, CmpType)
Compare the current image with img2
and returns the comparison mask
public Image<TColor, byte> Cmp(Image<TColor, TDepth> img2, CmpType cmpType)
Parameters
Returns
Cmp(double, CmpType)
Compare the current image with value
and returns the comparison mask
[ExposableMethod(Exposable = true, Category = "Logic")]
public Image<TColor, byte> Cmp(double value, CmpType comparisonType)
Parameters
Returns
ConcateHorizontal(Image<TColor, TDepth>)
Concate the current image with another image horizontally.
public Image<TColor, TDepth> ConcateHorizontal(Image<TColor, TDepth> otherImage)
Parameters
otherImage
Image<TColor, TDepth>The other image to concate
Returns
- Image<TColor, TDepth>
A new image that is the horizontal concatening of this image and
otherImage
ConcateVertical(Image<TColor, TDepth>)
Concate the current image with another image vertically.
public Image<TColor, TDepth> ConcateVertical(Image<TColor, TDepth> otherImage)
Parameters
otherImage
Image<TColor, TDepth>The other image to concate
Returns
- Image<TColor, TDepth>
A new image that is the vertical concatening of this image and
otherImage
ConvertFrom(IInputArray)
Convert the source image to the current image, if the size are different, the current image will be a resized version of the srcImage.
public void ConvertFrom(IInputArray srcImage)
Parameters
srcImage
IInputArrayThe sourceImage
ConvertFrom<TSrcColor, TSrcDepth>(Image<TSrcColor, TSrcDepth>)
Convert the source image to the current image, if the size are different, the current image will be a resized version of the srcImage.
public void ConvertFrom<TSrcColor, TSrcDepth>(Image<TSrcColor, TSrcDepth> srcImage) where TSrcColor : struct, IColor where TSrcDepth : new()
Parameters
srcImage
Image<TSrcColor, TSrcDepth>The sourceImage
Type Parameters
TSrcColor
The color type of the source image
TSrcDepth
The color depth of the source image
ConvertScale<TOtherDepth>(double, double)
Convert the current image to the specific depth, at the same time scale and shift the values of the pixel
public Image<TColor, TOtherDepth> ConvertScale<TOtherDepth>(double scale, double shift) where TOtherDepth : new()
Parameters
scale
doubleThe value to be multiplied with the pixel
shift
doubleThe value to be added to the pixel
Returns
- Image<TColor, TOtherDepth>
Image of the specific depth, val = val * scale + shift
Type Parameters
TOtherDepth
The type of depth to convert to
Convert<TOtherDepth>(Func<TDepth, int, int, TOtherDepth>)
Compute the element of a new image based on the value as well as the x and y positions of each pixel on the image
public Image<TColor, TOtherDepth> Convert<TOtherDepth>(Func<TDepth, int, int, TOtherDepth> converter) where TOtherDepth : new()
Parameters
Returns
- Image<TColor, TOtherDepth>
The result image
Type Parameters
TOtherDepth
The depth type to convert the image to.
Convert<TOtherDepth>(Func<TDepth, TOtherDepth>)
Compute the element of the new image based on element of this image
public Image<TColor, TOtherDepth> Convert<TOtherDepth>(Func<TDepth, TOtherDepth> converter) where TOtherDepth : new()
Parameters
converter
Func<TDepth, TOtherDepth>The function to be applied to the image pixels
Returns
- Image<TColor, TOtherDepth>
The result image
Type Parameters
TOtherDepth
The depth type of the result image
Convert<TOtherColor, TOtherDepth>()
Convert the current image to the specific color and depth
[ExposableMethod(Exposable = true, Category = "Conversion", GenericParametersOptions = new Type[] { typeof(Bgr), typeof(Bgra), typeof(Gray), typeof(Hsv), typeof(Hls), typeof(Lab), typeof(Luv), typeof(Xyz), typeof(Ycc), typeof(float), typeof(byte), typeof(double) }, GenericParametersOptionSizes = new int[] { 9, 3 })]
public Image<TOtherColor, TOtherDepth> Convert<TOtherColor, TOtherDepth>() where TOtherColor : struct, IColor where TOtherDepth : new()
Returns
- Image<TOtherColor, TOtherDepth>
Image of the specific color and depth
Type Parameters
TOtherColor
The type of color to be converted to
TOtherDepth
The type of pixel depth to be converted to
Convert<TDepth2, TDepth3>(Image<TColor, TDepth2>, Func<TDepth, TDepth2, TDepth3>)
Compute the element of the new image based on the elements of the two image
public Image<TColor, TDepth3> Convert<TDepth2, TDepth3>(Image<TColor, TDepth2> img2, Func<TDepth, TDepth2, TDepth3> converter) where TDepth2 : new() where TDepth3 : new()
Parameters
img2
Image<TColor, TDepth2>The second image
converter
Func<TDepth, TDepth2, TDepth3>The function to be applied to the image pixels
Returns
- Image<TColor, TDepth3>
The result image
Type Parameters
TDepth2
The depth type of img2
TDepth3
The depth type of the result image
Convert<TDepth2, TDepth3, TDepth4>(Image<TColor, TDepth2>, Image<TColor, TDepth3>, Func<TDepth, TDepth2, TDepth3, TDepth4>)
Compute the element of the new image based on the elements of the three image
public Image<TColor, TDepth4> Convert<TDepth2, TDepth3, TDepth4>(Image<TColor, TDepth2> img2, Image<TColor, TDepth3> img3, Func<TDepth, TDepth2, TDepth3, TDepth4> converter) where TDepth2 : new() where TDepth3 : new() where TDepth4 : new()
Parameters
img2
Image<TColor, TDepth2>The second image
img3
Image<TColor, TDepth3>The third image
converter
Func<TDepth, TDepth2, TDepth3, TDepth4>The function to be applied to the image pixels
Returns
- Image<TColor, TDepth4>
The result image
Type Parameters
TDepth2
The depth type of img2
TDepth3
The depth type of img3
TDepth4
The depth type of the result image
Convert<TDepth2, TDepth3, TDepth4, TDepth5>(Image<TColor, TDepth2>, Image<TColor, TDepth3>, Image<TColor, TDepth4>, Func<TDepth, TDepth2, TDepth3, TDepth4, TDepth5>)
Compute the element of the new image based on the elements of the four image
public Image<TColor, TDepth5> Convert<TDepth2, TDepth3, TDepth4, TDepth5>(Image<TColor, TDepth2> img2, Image<TColor, TDepth3> img3, Image<TColor, TDepth4> img4, Func<TDepth, TDepth2, TDepth3, TDepth4, TDepth5> converter) where TDepth2 : new() where TDepth3 : new() where TDepth4 : new() where TDepth5 : new()
Parameters
img2
Image<TColor, TDepth2>The second image
img3
Image<TColor, TDepth3>The third image
img4
Image<TColor, TDepth4>The fourth image
converter
Func<TDepth, TDepth2, TDepth3, TDepth4, TDepth5>The function to be applied to the image pixels
Returns
- Image<TColor, TDepth5>
The result image
Type Parameters
TDepth2
The depth type of img2
TDepth3
The depth type of img3
TDepth4
The depth type of img4
TDepth5
The depth type of the result image
Convolution(ConvolutionKernelF, double, BorderType)
Performs a convolution using the specific kernel
public Image<TColor, float> Convolution(ConvolutionKernelF kernel, double delta = 0, BorderType borderType = BorderType.Default)
Parameters
kernel
ConvolutionKernelFThe convolution kernel
delta
doubleThe optional value added to the filtered pixels before storing them in dst
borderType
BorderTypeThe pixel extrapolation method.
Returns
Copy(Image<Gray, byte>)
Make a copy of the image using a mask, if ROI is set, only copy the ROI
public Image<TColor, TDepth> Copy(Image<Gray, byte> mask = null)
Parameters
Returns
- Image<TColor, TDepth>
A copy of the image
Copy(Image<TColor, TDepth>, Image<Gray, byte>)
Copy the masked area of this image to destination
public void Copy(Image<TColor, TDepth> dest, Image<Gray, byte> mask)
Parameters
Copy(RotatedRect)
Get a copy of the boxed region of the image
public Image<TColor, TDepth> Copy(RotatedRect box)
Parameters
box
RotatedRectThe boxed region of the image
Returns
- Image<TColor, TDepth>
A copy of the boxed region of the image
Copy(Rectangle)
Make a copy of the specific ROI (Region of Interest) from the image
public Image<TColor, TDepth> Copy(Rectangle roi)
Parameters
roi
RectangleThe roi to be copied
Returns
- Image<TColor, TDepth>
The region of interest
CopyBlank()
Create an image of the same size
public Image<TColor, TDepth> CopyBlank()
Returns
- Image<TColor, TDepth>
The image of the same size
Remarks
The initial pixel in the image equals zero
CountNonzero()
Count the non Zero elements for each channel
public int[] CountNonzero()
Returns
- int[]
Count the non Zero elements for each channel
Dilate(int)
Dilates this image using a 3x3 rectangular structuring element. Dilation are applied several (iterations) times
public Image<TColor, TDepth> Dilate(int iterations)
Parameters
iterations
intThe number of dilate iterations
Returns
- Image<TColor, TDepth>
The dilated image
DisposeObject()
Release all unmanaged memory associate with the image
protected override void DisposeObject()
Draw(IConvexPolygonF, TColor, int)
Draw a convex polygon using the specific color and thickness
public virtual void Draw(IConvexPolygonF polygon, TColor color, int thickness)
Parameters
polygon
IConvexPolygonFThe convex polygon to be drawn
color
TColorThe color of the triangle
thickness
intIf thickness is less than 1, the triangle is filled up
Draw(IInputArrayOfArrays, int, TColor, int, LineType, IInputArray, int, Point)
Draws contour outlines in the image if thickness>=0 or fills area bounded by the contours if thickness<0
public void Draw(IInputArrayOfArrays contours, int contourIdx, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, IInputArray hierarchy = null, int maxLevel = 2147483647, Point offset = default)
Parameters
contours
IInputArrayOfArraysAll the input contours. Each contour is stored as a point vector.
contourIdx
intParameter indicating a contour to draw. If it is negative, all the contours are drawn.
color
TColorColor of the contours
thickness
intThickness of lines the contours are drawn with. If it is negative the contour interiors are drawn
lineType
LineTypeType of the contour segments
hierarchy
IInputArrayOptional information about hierarchy. It is only needed if you want to draw only some of the contours
maxLevel
intMaximal level for drawn contours. If 0, only contour is drawn. If 1, the contour and all contours after it on the same level are drawn. If 2, all contours after and all contours one level below the contours are drawn, etc. If the value is negative, the function does not draw the contours following after contour but draws child contours of contour up to abs(maxLevel)-1 level.
offset
PointShift all the point coordinates by the specified value. It is useful in case if the contours retrieved in some image ROI and then the ROI offset needs to be taken into account during the rendering.
Draw(CircleF, TColor, int, LineType, int)
Draw a Circle of the specific color and thickness
public virtual void Draw(CircleF circle, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0)
Parameters
circle
CircleFThe circle to be drawn
color
TColorThe color of the circle
thickness
intIf thickness is less than 1, the circle is filled up
lineType
LineTypeLine type
shift
intNumber of fractional bits in the center coordinates and radius value
Draw(Cross2DF, TColor, int)
Draw a 2D Cross using the specific color and thickness
public void Draw(Cross2DF cross, TColor color, int thickness)
Parameters
cross
Cross2DFThe 2D Cross to be drawn
color
TColorThe color of the cross
thickness
intMust be > 0
Draw(Ellipse, TColor, int, LineType)
Draw a Ellipse of the specific color and thickness
public void Draw(Ellipse ellipse, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected)
Parameters
ellipse
EllipseThe ellipse to be draw
color
TColorThe color of the ellipse
thickness
intIf thickness is less than 1, the ellipse is filled up
lineType
LineTypeLine type
Draw(LineSegment2D, TColor, int, LineType, int)
Draw a line segment using the specific color and thickness
public virtual void Draw(LineSegment2D line, TColor color, int thickness, LineType lineType = LineType.EightConnected, int shift = 0)
Parameters
line
LineSegment2DThe line segment to be drawn
color
TColorThe color of the line segment
thickness
intThe thickness of the line segment
lineType
LineTypeLine type
shift
intNumber of fractional bits in the center coordinates and radius value
Draw(LineSegment2DF, TColor, int, LineType, int)
Draw a line segment using the specific color and thickness
public virtual void Draw(LineSegment2DF line, TColor color, int thickness, LineType lineType = LineType.EightConnected, int shift = 0)
Parameters
line
LineSegment2DFThe line segment to be drawn
color
TColorThe color of the line segment
thickness
intThe thickness of the line segment
lineType
LineTypeLine type
shift
intNumber of fractional bits in the center coordinates and radius value
Draw(Point[], TColor, int, LineType, Point)
Draws contour outlines in the image if thickness>=0 or fills area bounded by the contours if thickness<0
public void Draw(Point[] contours, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, Point offset = default)
Parameters
contours
Point[]The input contour stored as a point vector.
color
TColorColor of the contours
thickness
intThickness of lines the contours are drawn with. If it is negative the contour interiors are drawn
lineType
LineTypeType of the contour segments
offset
PointShift all the point coordinates by the specified value. It is useful in case if the contours retrieved in some image ROI and then the ROI offset needs to be taken into account during the rendering.
Draw(Rectangle, TColor, int, LineType, int)
Draw an Rectangle of the specific color and thickness
public virtual void Draw(Rectangle rect, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0)
Parameters
rect
RectangleThe rectangle to be drawn
color
TColorThe color of the rectangle
thickness
intIf thickness is less than 1, the rectangle is filled up
lineType
LineTypeLine type
shift
intNumber of fractional bits in the center coordinates and radius value
Draw(string, Point, FontFace, double, TColor, int, LineType, bool)
Draw the text using the specific font on the image
public virtual void Draw(string message, Point bottomLeft, FontFace fontFace, double fontScale, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, bool bottomLeftOrigin = false)
Parameters
message
stringThe text message to be draw
bottomLeft
PointThe location of the bottom left corner of the font
fontFace
FontFaceFont type.
fontScale
doubleFont scale factor that is multiplied by the font-specific base size.
color
TColorThe color of the text
thickness
intThickness of the lines used to draw a text.
lineType
LineTypeLine type
bottomLeftOrigin
boolWhen true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.
DrawPolyline(Point[], bool, TColor, int, LineType, int)
Draw the polyline defined by the array of 2D points
public void DrawPolyline(Point[] pts, bool isClosed, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0)
Parameters
pts
Point[]A polyline defined by its point
isClosed
boolif true, the last line segment is defined by the last point of the array and the first point of the array
color
TColorthe color used for drawing
thickness
intthe thinkness of the line
lineType
LineTypeLine type
shift
intNumber of fractional bits in the center coordinates and radius value
DrawPolyline(Point[][], bool, TColor, int, LineType, int)
Draw the polylines defined by the array of array of 2D points
public void DrawPolyline(Point[][] pts, bool isClosed, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0)
Parameters
pts
Point[][]An array of polylines each represented by an array of points
isClosed
boolif true, the last line segment is defined by the last point of the array and the first point of the array
color
TColorthe color used for drawing
thickness
intthe thickness of the line
lineType
LineTypeLine type
shift
intNumber of fractional bits in the center coordinates and radius value
Equals(Image<TColor, TDepth>)
Compare two images, returns true if each of the pixels are equal, false otherwise
public bool Equals(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The other image to compare with
Returns
- bool
true if each of the pixels for the two images are equal, false otherwise
Erode(int)
Erodes this image using a 3x3 rectangular structuring element. Erosion are applied several (iterations) times
public Image<TColor, TDepth> Erode(int iterations)
Parameters
iterations
intThe number of erode iterations
Returns
- Image<TColor, TDepth>
The eroded image
Exp()
Calculates exponent of every element of input array: dst(I)=exp(src(I))
[ExposableMethod(Exposable = true, Category = "Math")]
public Image<TColor, TDepth> Exp()
Returns
- Image<TColor, TDepth>
The exponent image
Remarks
Maximum relative error is ~7e-6. Currently, the function converts denormalized values to zeros on output.
FillConvexPoly(Point[], TColor, LineType, int)
Fill the convex polygon with the specific color
public void FillConvexPoly(Point[] pts, TColor color, LineType lineType = LineType.EightConnected, int shift = 0)
Parameters
pts
Point[]The array of points that define the convex polygon
color
TColorThe color to fill the polygon with
lineType
LineTypeLine type
shift
intNumber of fractional bits in the center coordinates and radius value
FindCornerSubPix(PointF[][], Size, Size, MCvTermCriteria)
Iterates to find the sub-pixel accurate location of corners, or radial saddle points
public void FindCornerSubPix(PointF[][] corners, Size win, Size zeroZone, MCvTermCriteria criteria)
Parameters
corners
PointF[][]Coordinates of the input corners, the values will be modified by this function call
win
SizeHalf sizes of the search window. For example, if win=(5,5) then 52+1 x 52+1 = 11 x 11 search window is used
zeroZone
SizeHalf size of the dead region in the middle of the search zone over which the summation in formulae below is not done. It is used sometimes to avoid possible singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such size
criteria
MCvTermCriteriaCriteria for termination of the iterative process of corner refinement. That is, the process of corner position refinement stops either after certain number of iteration or when a required accuracy is achieved. The criteria may specify either of or both the maximum number of iteration and the required accuracy
Flip(FlipType)
Return a flipped copy of the current image
public Image<TColor, TDepth> Flip(FlipType flipType)
Parameters
flipType
FlipTypeThe type of the flipping
Returns
- Image<TColor, TDepth>
The flipped copy of this image
FromIplImagePtr(nint)
Get the managed image from an unmanaged IplImagePointer
public static Image<TColor, TDepth> FromIplImagePtr(nint iplImage)
Parameters
iplImage
nintThe pointer to the iplImage
Returns
- Image<TColor, TDepth>
The managed image from the iplImage pointer
GetAverage()
Get the average value on this image
public TColor GetAverage()
Returns
- TColor
The average color of the image
GetAverage(Image<Gray, byte>)
Get the average value on this image, using the specific mask
public TColor GetAverage(Image<Gray, byte> mask)
Parameters
Returns
- TColor
The average color of the masked area
GetMoments(bool)
Calculates spatial and central moments up to the third order and writes them to moments. The moments may be used then to calculate gravity center of the shape, its area, main axises and various shape characteristics including 7 Hu invariants.
public Moments GetMoments(bool binary)
Parameters
binary
boolIf the flag is true, all the zero pixel values are treated as zeroes, all the others are treated as 1's
Returns
- Moments
spatial and central moments up to the third order
GetObjectData(SerializationInfo, StreamingContext)
A function used for runtime serialization of the object
public override void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
info
SerializationInfoSerialization info
context
StreamingContextstreaming context
GetSubRect(Rectangle)
Get a subimage which image data is shared with the current image.
public Image<TColor, TDepth> GetSubRect(Rectangle rect)
Parameters
rect
RectangleThe rectangle area of the sub-image
Returns
- Image<TColor, TDepth>
A subimage which image data is shared with the current image
GetSum()
Get the sum for each color channel
public TColor GetSum()
Returns
- TColor
The sum for each color channel
GrabCut(Rectangle, int)
Use grabcut to perform background foreground segmentation.
public Image<Gray, byte> GrabCut(Rectangle rect, int iteration)
Parameters
rect
RectangleThe initial rectangle region for the foreground
iteration
intThe number of iterations to run GrabCut
Returns
- Image<Gray, byte>
The background foreground mask where 2 indicates background and 3 indicates foreground
HoughCircles(TColor, TColor, double, double, int, int)
First apply Canny Edge Detector on the current image, then apply Hough transform to find circles
public CircleF[][] HoughCircles(TColor cannyThreshold, TColor accumulatorThreshold, double dp, double minDist, int minRadius = 0, int maxRadius = 0)
Parameters
cannyThreshold
TColorThe higher threshold of the two passed to Canny edge detector (the lower one will be twice smaller).
accumulatorThreshold
TColorAccumulator threshold at the center detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first
dp
doubleResolution of the accumulator used to detect centers of the circles. For example, if it is 1, the accumulator will have the same resolution as the input image, if it is 2 - accumulator will have twice smaller width and height, etc
minDist
doubleMinimum distance between centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed
minRadius
intMinimal radius of the circles to search for
maxRadius
intMaximal radius of the circles to search for
Returns
- CircleF[][]
The circle detected for each of the channels
HoughLines(double, double, double, double, int, double, double)
Apply Canny Edge Detector follows by Probabilistic Hough transform to find line segments in the image
public LineSegment2D[][] HoughLines(double cannyThreshold, double cannyThresholdLinking, double rhoResolution, double thetaResolution, int threshold, double minLineWidth, double gapBetweenLines)
Parameters
cannyThreshold
doubleThe threshold to find initial segments of strong edges
cannyThresholdLinking
doubleThe threshold used for edge Linking
rhoResolution
doubleDistance resolution in pixel-related units.
thetaResolution
doubleAngle resolution measured in radians
threshold
intA line is returned by the function if the corresponding accumulator value is greater than threshold
minLineWidth
doubleMinimum width of a line
gapBetweenLines
doubleMinimum gap between lines
Returns
- LineSegment2D[][]
The line segments detected for each of the channels
HoughLinesBinary(double, double, int, double, double)
Apply Probabilistic Hough transform to find line segments. The current image must be a binary image (eg. the edges as a result of the Canny edge detector)
public LineSegment2D[][] HoughLinesBinary(double rhoResolution, double thetaResolution, int threshold, double minLineWidth, double gapBetweenLines)
Parameters
rhoResolution
doubleDistance resolution in pixel-related units.
thetaResolution
doubleAngle resolution measured in radians
threshold
intA line is returned by the function if the corresponding accumulator value is greater than threshold
minLineWidth
doubleMinimum width of a line
gapBetweenLines
doubleMinimum gap between lines
Returns
- LineSegment2D[][]
The line segments detected for each of the channels
InPaint(Image<Gray, byte>, double)
Use inpaint to recover the intensity of the pixels which location defined by mask
on this image
public Image<TColor, TDepth> InPaint(Image<Gray, byte> mask, double radius)
Parameters
mask
Image<Gray, byte>The inpainting mask. Non-zero pixels indicate the area that needs to be inpainted
radius
doubleThe radius of circular neighborhood of each point inpainted that is considered by the algorithm
Returns
- Image<TColor, TDepth>
The inpainted image
InRange(Image<TColor, TDepth>, Image<TColor, TDepth>)
Checks that image elements lie between values defined by two images of same size and type
public Image<Gray, byte> InRange(Image<TColor, TDepth> lower, Image<TColor, TDepth> higher)
Parameters
lower
Image<TColor, TDepth>The inclusive lower limit of color value
higher
Image<TColor, TDepth>The inclusive upper limit of color value
Returns
InRange(TColor, TColor)
Checks that image elements lie between two scalars
[ExposableMethod(Exposable = true, Category = "Logic")]
public Image<Gray, byte> InRange(TColor lower, TColor higher)
Parameters
lower
TColorThe inclusive lower limit of color value
higher
TColorThe inclusive upper limit of color value
Returns
Integral()
Calculates integral images for the source image
public Image<TColor, double> Integral()
Returns
Integral(out Image<TColor, double>, out Image<TColor, double>)
Calculates integral images for the source image
public void Integral(out Image<TColor, double> sum, out Image<TColor, double> squareSum)
Parameters
sum
Image<TColor, double>The integral image
squareSum
Image<TColor, double>The integral image for squared pixel values
Integral(out Image<TColor, double>, out Image<TColor, double>, out Image<TColor, double>)
Calculates one or more integral images for the source image
public void Integral(out Image<TColor, double> sum, out Image<TColor, double> squareSum, out Image<TColor, double> titledSum)
Parameters
sum
Image<TColor, double>The integral image
squareSum
Image<TColor, double>The integral image for squared pixel values
titledSum
Image<TColor, double>The integral for the image rotated by 45 degrees
Laplace(int)
Calculates Laplacian of the source image by summing second x- and y- derivatives calculated using Sobel operator. Specifying aperture_size=1 gives the fastest variant that is equal to convolving the image with the following kernel:
|0 1 0| |1 -4 1| |0 1 0|
[ExposableMethod(Exposable = true, Category = "Gradients, Edges")]
public Image<TColor, float> Laplace(int apertureSize)
Parameters
apertureSize
intAperture size
Returns
Log()
Calculates natural logarithm of absolute value of every element of input array
[ExposableMethod(Exposable = true, Category = "Math")]
public Image<TColor, TDepth> Log()
Returns
- Image<TColor, TDepth>
Natural logarithm of absolute value of every element of input array
LogPolar(PointF, double, Inter, Warp)
Convert the image to log polar, simulating the human foveal vision
[ExposableMethod(Exposable = true, Category = "Transform")]
public Image<TColor, TDepth> LogPolar(PointF center, double magnitude, Inter interpolationType = Inter.Linear, Warp warpType = Warp.FillOutliers)
Parameters
center
PointFThe transformation center, where the output precision is maximal
magnitude
doubleMagnitude scale parameter
interpolationType
Interinterpolation type
warpType
WarpWarp type
Returns
- Image<TColor, TDepth>
The converted image
MapDataToImage(int, int, int, nint)
Let this Image object use the specific Image data.
protected void MapDataToImage(int width, int height, int stride, nint scan0)
Parameters
width
intThe width of the image
height
intThe height of the image
stride
intThe data stride (bytes per row)
scan0
nintThe origin of the data
MatchTemplate(Image<TColor, TDepth>, TemplateMatchingType)
The function slides through image, compares overlapped patches of size wxh with templ using the specified method and return the comparison results
public Image<Gray, float> MatchTemplate(Image<TColor, TDepth> template, TemplateMatchingType method)
Parameters
template
Image<TColor, TDepth>Searched template; must be not greater than the source image and the same data type as the image
method
TemplateMatchingTypeSpecifies the way the template must be compared with image regions
Returns
- Image<Gray, float>
The comparison result: width = this.Width - template.Width + 1; height = this.Height - template.Height + 1
Max(Image<TColor, TDepth>)
Find the elementwise maximum value
public Image<TColor, TDepth> Max(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The second image for the Max operation
Returns
- Image<TColor, TDepth>
An image where each pixel is the maximum of this image and the parameter image
Max(double)
Find the elementwise maximum value
public Image<TColor, TDepth> Max(double value)
Parameters
value
doubleThe value to compare with
Returns
- Image<TColor, TDepth>
An image where each pixel is the maximum of this image and
value
Min(Image<TColor, TDepth>)
Find the elementwise minimum value
public Image<TColor, TDepth> Min(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The second image for the Min operation
Returns
- Image<TColor, TDepth>
An image where each pixel is the minimum of this image and the parameter image
Min(double)
Find the elementwise minimum value
public Image<TColor, TDepth> Min(double value)
Parameters
value
doubleThe value to compare with
Returns
- Image<TColor, TDepth>
An image where each pixel is the minimum of this image and
value
MinMax(out double[], out double[], out Point[], out Point[])
Returns the min / max location and values for the image
public void MinMax(out double[] minValues, out double[] maxValues, out Point[] minLocations, out Point[] maxLocations)
Parameters
minValues
double[]The minimum values for each channel
maxValues
double[]The maximum values for each channel
minLocations
Point[]The minimum locations for each channel
maxLocations
Point[]The maximum locations for each channel
MorphologyEx(MorphOp, IInputArray, Point, int, BorderType, MCvScalar)
Perform advanced morphological transformations using erosion and dilation as basic operations.
public Image<TColor, TDepth> MorphologyEx(MorphOp operation, IInputArray kernel, Point anchor, int iterations, BorderType borderType, MCvScalar borderValue)
Parameters
operation
MorphOpType of morphological operation
kernel
IInputArrayStructuring element
anchor
PointAnchor position with the kernel. Negative values mean that the anchor is at the kernel center.
iterations
intNumber of times erosion and dilation are applied
borderType
BorderTypeBorder type
borderValue
MCvScalarBorder value
Returns
- Image<TColor, TDepth>
The result of the morphological operation
Mul(Image<TColor, TDepth>)
Elementwise multiply img2
with the current image
public Image<TColor, TDepth> Mul(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The image to be elementwise multiplied to the current image
Returns
- Image<TColor, TDepth>
this .* img2
Mul(Image<TColor, TDepth>, double)
Elementwise multiply another image with the current image and the scale
public Image<TColor, TDepth> Mul(Image<TColor, TDepth> img2, double scale)
Parameters
img2
Image<TColor, TDepth>The image to be elementwise multiplied to the current image
scale
doubleThe scale to be multiplied
Returns
- Image<TColor, TDepth>
this .* img2 * scale
Mul(double)
Elementwise multiply the current image with scale
[ExposableMethod(Exposable = true, Category = "Math")]
public Image<TColor, TDepth> Mul(double scale)
Parameters
scale
doubleThe scale to be multiplied
Returns
- Image<TColor, TDepth>
The scaled image
Not()
Compute the complement image
public Image<TColor, TDepth> Not()
Returns
- Image<TColor, TDepth>
The complement image
Or(Image<TColor, TDepth>)
Perform an elementwise OR operation with another image and return the result
public Image<TColor, TDepth> Or(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The second image for the OR operation
Returns
- Image<TColor, TDepth>
The result of the OR operation
Or(Image<TColor, TDepth>, Image<Gray, byte>)
Perform an elementwise OR operation with another image, using a mask, and return the result
public Image<TColor, TDepth> Or(Image<TColor, TDepth> img2, Image<Gray, byte> mask)
Parameters
img2
Image<TColor, TDepth>The second image for the OR operation
mask
Image<Gray, byte>The mask for the OR operation
Returns
- Image<TColor, TDepth>
The result of the OR operation
Or(TColor)
Perform an elementwise OR operation with some color
[ExposableMethod(Exposable = true, Category = "Logic")]
public Image<TColor, TDepth> Or(TColor val)
Parameters
val
TColorThe value for the OR operation
Returns
- Image<TColor, TDepth>
The result of the OR operation
Or(TColor, Image<Gray, byte>)
Perform an elementwise OR operation with some color using a mask
public Image<TColor, TDepth> Or(TColor val, Image<Gray, byte> mask)
Parameters
Returns
- Image<TColor, TDepth>
The result of the OR operation
Pow(double)
Raises every element of input array to p dst(I)=src(I)^p, if p is integer dst(I)=abs(src(I))^p, otherwise
[ExposableMethod(Exposable = true, Category = "Math")]
public Image<TColor, TDepth> Pow(double power)
Parameters
power
doubleThe exponent of power
Returns
- Image<TColor, TDepth>
The power image
PyrDown()
Performs downsampling step of Gaussian pyramid decomposition. First it convolves this image with the specified filter and then downsamples the image by rejecting even rows and columns.
[ExposableMethod(Exposable = true, Category = "Pyramids")]
public Image<TColor, TDepth> PyrDown()
Returns
- Image<TColor, TDepth>
The down-sampled image
PyrUp()
Performs up-sampling step of Gaussian pyramid decomposition. First it up-samples this image by injecting even zero rows and columns and then convolves result with the specified filter multiplied by 4 for interpolation. So the resulting image is four times larger than the source image.
[ExposableMethod(Exposable = true, Category = "Pyramids")]
public Image<TColor, TDepth> PyrUp()
Returns
- Image<TColor, TDepth>
The up-sampled image
Resize(double, Inter)
Scale the image to the specific size: width *= scale; height *= scale
[ExposableMethod(Exposable = true)]
public Image<TColor, TDepth> Resize(double scale, Inter interpolationType)
Parameters
Returns
- Image<TColor, TDepth>
The scaled image
Resize(int, int, Inter)
Scale the image to the specific size
[ExposableMethod(Exposable = true)]
public Image<TColor, TDepth> Resize(int width, int height, Inter interpolationType)
Parameters
width
intThe width of the returned image.
height
intThe height of the returned image.
interpolationType
InterThe type of interpolation
Returns
- Image<TColor, TDepth>
The resized image
Resize(int, int, Inter, bool)
Scale the image to the specific size
public Image<TColor, TDepth> Resize(int width, int height, Inter interpolationType, bool preserveScale)
Parameters
width
intThe width of the returned image.
height
intThe height of the returned image.
interpolationType
InterThe type of interpolation
preserveScale
boolif true, the scale is preservered and the resulting image has maximum width(height) possible that is <=
width
(height
), if false, this function is equaivalent to Resize(int width, int height)
Returns
- Image<TColor, TDepth>
The resized image
RoiParam(nint, out long, out int, out int, out int, out int)
Return parameters based on ROI
protected static void RoiParam(nint ptr, out long start, out int rows, out int elementCount, out int byteWidth, out int widthStep)
Parameters
ptr
nintThe Pointer to the IplImage
start
longThe address of the pointer that point to the start of the Bytes taken into consideration ROI
rows
intThe number of rows taken into consideration ROI
elementCount
intROI.Width * ColorType.Dimension
byteWidth
intThe number of bytes in a row taken into consideration ROI
widthStep
intThe width step required to jump to the next row
Rotate(double, PointF, Inter, TColor, bool)
Rotate this image the specified angle
public Image<TColor, TDepth> Rotate(double angle, PointF center, Inter interpolationMethod, TColor background, bool crop)
Parameters
angle
doubleThe angle of rotation in degrees. Positive means clockwise.
center
PointFThe center of rotation
interpolationMethod
InterThe interpolation method
background
TColorThe color with with to fill the background
crop
boolIf set to true the image is cropped to its original size, possibly losing corners information. If set to false the result image has different size than original and all rotation information is preserved
Returns
- Image<TColor, TDepth>
The rotated image
Rotate(double, TColor, bool)
Rotate this image the specified angle
[ExposableMethod(Exposable = true, Category = "Transform")]
public Image<TColor, TDepth> Rotate(double angle, TColor background, bool crop = true)
Parameters
angle
doubleThe angle of rotation in degrees.
background
TColorThe color with which to fill the background
crop
boolIf set to true the image is cropped to its original size, possibly losing corners information. If set to false the result image has different size than original and all rotation information is preserved
Returns
- Image<TColor, TDepth>
The rotated image
Save(string)
Save this image to the specific file.
public override void Save(string fileName)
Parameters
fileName
stringThe name of the file to be saved to
Remarks
The image format is chosen depending on the filename extension, see cvLoadImage. Only 8-bit single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function. If the format, depth or channel order is different, use cvCvtScale and cvCvtColor to convert it before saving, or use universal cvSave to save the image to XML or YAML format.
SetValue(TColor)
Set every pixel of the image to the specific color
public void SetValue(TColor color)
Parameters
color
TColorThe color to be set
SetValue(TColor, Image<Gray, byte>)
Set every pixel of the image to the specific color, using a mask
public void SetValue(TColor color, Image<Gray, byte> mask)
Parameters
SmoothBilateral(int, int, int)
Applying bilateral 3x3 filtering
[ExposableMethod(Exposable = true, Category = "Smoothing")]
public Image<TColor, TDepth> SmoothBilateral(int kernelSize, int colorSigma, int spaceSigma)
Parameters
kernelSize
intThe size of the bilateral kernel
colorSigma
intColor sigma
spaceSigma
intSpace sigma
Returns
- Image<TColor, TDepth>
The result of bilateral smooth
SmoothBlur(int, int, bool)
Summation over a pixel param1 x param2 neighborhood. If scale is true, the result is subsequent scaled by 1/(param1 x param2)
[ExposableMethod(Exposable = true, Category = "Smoothing")]
public Image<TColor, TDepth> SmoothBlur(int width, int height, bool scale = true)
Parameters
width
intThe width of the window
height
intThe height of the window
scale
boolIf true, the result is subsequent scaled by 1/(param1 x param2)
Returns
- Image<TColor, TDepth>
The result of blur
SmoothGaussian(int)
Perform Gaussian Smoothing in the current image and return the result
public Image<TColor, TDepth> SmoothGaussian(int kernelSize)
Parameters
kernelSize
intThe size of the Gaussian kernel (
kernelSize
xkernelSize
)
Returns
- Image<TColor, TDepth>
The smoothed image
SmoothGaussian(int, int, double, double)
Perform Gaussian Smoothing in the current image and return the result
[ExposableMethod(Exposable = true, Category = "Smoothing")]
public Image<TColor, TDepth> SmoothGaussian(int kernelWidth, int kernelHeight, double sigma1, double sigma2)
Parameters
kernelWidth
intThe width of the Gaussian kernel
kernelHeight
intThe height of the Gaussian kernel
sigma1
doubleThe standard deviation of the Gaussian kernel in the horizontal dimension
sigma2
doubleThe standard deviation of the Gaussian kernel in the vertical dimension
Returns
- Image<TColor, TDepth>
The smoothed image
SmoothMedian(int)
Finding median of size
xsize
neighborhood
[ExposableMethod(Exposable = true, Category = "Smoothing")]
public Image<TColor, TDepth> SmoothMedian(int size)
Parameters
size
intThe size (width & height) of the window
Returns
- Image<TColor, TDepth>
The result of median smooth
Sobel(int, int, int)
Calculates the image derivative by convolving the image with the appropriate kernel The Sobel operators combine Gaussian smoothing and differentiation so the result is more or less robust to the noise. Most often, the function is called with (xorder=1, yorder=0, aperture_size=3) or (xorder=0, yorder=1, aperture_size=3) to calculate first x- or y- image derivative.
[ExposableMethod(Exposable = true, Category = "Gradients, Edges")]
public Image<TColor, float> Sobel(int xorder, int yorder, int apertureSize)
Parameters
xorder
intOrder of the derivative x
yorder
intOrder of the derivative y
apertureSize
intSize of the extended Sobel kernel, must be 1, 3, 5 or 7. In all cases except 1, aperture_size xaperture_size separable kernel will be used to calculate the derivative.
Returns
Split()
Split current Image into an array of gray scale images where each element in the array represent a single color channel of the original image
public Image<Gray, TDepth>[] Split()
Returns
- Image<Gray, TDepth>[]
An array of gray scale images where each element
in the array represent a single color channel of the original image
Sub(Image<TColor, TDepth>)
Elementwise subtract another image from the current image
public Image<TColor, TDepth> Sub(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The second image to be subtracted from the current image
Returns
- Image<TColor, TDepth>
The result of elementwise subtracting img2 from the current image
Sub(Image<TColor, TDepth>, Image<Gray, byte>)
Elementwise subtract another image from the current image, using a mask
public Image<TColor, TDepth> Sub(Image<TColor, TDepth> img2, Image<Gray, byte> mask)
Parameters
img2
Image<TColor, TDepth>The image to be subtracted from the current image
mask
Image<Gray, byte>The mask for the subtract operation
Returns
- Image<TColor, TDepth>
The result of elementwise subtracting img2 from the current image, using the specific mask
Sub(TColor)
Elementwise subtract a color from the current image
[ExposableMethod(Exposable = true, Category = "Math")]
public Image<TColor, TDepth> Sub(TColor val)
Parameters
val
TColorThe color value to be subtracted from the current image
Returns
- Image<TColor, TDepth>
The result of elementwise subtracting color 'val' from the current image
SubR(TColor)
result = val - this
[ExposableMethod(Exposable = true, Category = "Math")]
public Image<TColor, TDepth> SubR(TColor val)
Parameters
val
TColorthe value which subtract this image
Returns
- Image<TColor, TDepth>
val - this
SubR(TColor, Image<Gray, byte>)
result = val - this, using a mask
public Image<TColor, TDepth> SubR(TColor val, Image<Gray, byte> mask)
Parameters
Returns
- Image<TColor, TDepth>
val - this, with mask
ThresholdAdaptive(TColor, AdaptiveThresholdType, ThresholdType, int, TColor)
Transforms grayscale image to binary image.
Threshold calculated individually for each pixel.
For the method CV_ADAPTIVE_THRESH_MEAN_C it is a mean of blockSize
x blockSize
pixel
neighborhood, subtracted by param1.
For the method CV_ADAPTIVE_THRESH_GAUSSIAN_C it is a weighted sum (gaussian) of blockSize
x blockSize
pixel neighborhood, subtracted by param1.
[ExposableMethod(Exposable = true, Category = "Threshold")]
public Image<TColor, TDepth> ThresholdAdaptive(TColor maxValue, AdaptiveThresholdType adaptiveType, ThresholdType thresholdType, int blockSize, TColor param1)
Parameters
maxValue
TColorMaximum value to use with CV_THRESH_BINARY and CV_THRESH_BINARY_INV thresholding types
adaptiveType
AdaptiveThresholdTypeAdaptive_method
thresholdType
ThresholdTypeThresholding type. must be one of CV_THRESH_BINARY, CV_THRESH_BINARY_INV
blockSize
intThe size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ...
param1
TColorConstant subtracted from mean or weighted mean. It may be negative.
Returns
- Image<TColor, TDepth>
The result of the adaptive threshold
ThresholdBinary(TColor, TColor)
Threshold the image such that: dst(x,y) = max_value, if src(x,y)>threshold; 0, otherwise
public Image<TColor, TDepth> ThresholdBinary(TColor threshold, TColor maxValue)
Parameters
threshold
TColorThe threshold value
maxValue
TColorThe maximum value of the pixel on the result
Returns
- Image<TColor, TDepth>
The image such that: dst(x,y) = max_value, if src(x,y)>threshold; 0, otherwise
ThresholdBinaryInv(TColor, TColor)
Threshold the image such that: dst(x,y) = 0, if src(x,y)>threshold; max_value, otherwise
public Image<TColor, TDepth> ThresholdBinaryInv(TColor threshold, TColor maxValue)
Parameters
threshold
TColorThe threshold value
maxValue
TColorThe maximum value of the pixel on the result
Returns
- Image<TColor, TDepth>
The image such that: dst(x,y) = 0, if src(x,y)>threshold; max_value, otherwise
ThresholdToZero(TColor)
Threshold the image such that: dst(x,y) = src(x,y), if src(x,y)>threshold; 0, otherwise
public Image<TColor, TDepth> ThresholdToZero(TColor threshold)
Parameters
threshold
TColorThe threshold value
Returns
- Image<TColor, TDepth>
dst(x,y) = src(x,y), if src(x,y)>threshold; 0, otherwise
ThresholdToZeroInv(TColor)
Threshold the image such that: dst(x,y) = 0, if src(x,y)>threshold; src(x,y), otherwise
public Image<TColor, TDepth> ThresholdToZeroInv(TColor threshold)
Parameters
threshold
TColorThe threshold value
Returns
- Image<TColor, TDepth>
The image such that: dst(x,y) = 0, if src(x,y)>threshold; src(x,y), otherwise
ThresholdTrunc(TColor)
Threshold the image such that: dst(x,y) = threshold, if src(x,y)>threshold; src(x,y), otherwise
public Image<TColor, TDepth> ThresholdTrunc(TColor threshold)
Parameters
threshold
TColorThe threshold value
Returns
- Image<TColor, TDepth>
The image such that: dst(x,y) = threshold, if src(x,y)>threshold; src(x,y), otherwise
ToJpegData(int)
Get the jpeg representation of the image
public byte[] ToJpegData(int quality = 95)
Parameters
quality
intThe jpeg quality
Returns
- byte[]
An byte array that contains the image as jpeg data
WarpAffine(Mat, Inter, Warp, BorderType, TColor)
Transforms source image using the specified matrix
public Image<TColor, TDepth> WarpAffine(Mat mapMatrix, Inter interpolationType, Warp warpType, BorderType borderMode, TColor backgroundColor)
Parameters
mapMatrix
Mat2x3 transformation matrix
interpolationType
InterInterpolation type
warpType
WarpWarp type
borderMode
BorderTypePixel extrapolation method
backgroundColor
TColorA value used to fill outliers
Returns
- Image<TColor, TDepth>
The result of the transformation
WarpAffine(Mat, int, int, Inter, Warp, BorderType, TColor)
Transforms source image using the specified matrix
public Image<TColor, TDepth> WarpAffine(Mat mapMatrix, int width, int height, Inter interpolationType, Warp warpType, BorderType borderMode, TColor backgroundColor)
Parameters
mapMatrix
Mat2x3 transformation matrix
width
intThe width of the resulting image
height
intthe height of the resulting image
interpolationType
InterInterpolation type
warpType
WarpWarp type
borderMode
BorderTypePixel extrapolation method
backgroundColor
TColorA value used to fill outliers
Returns
- Image<TColor, TDepth>
The result of the transformation
WarpPerspective<TMapDepth>(Matrix<TMapDepth>, Inter, Warp, BorderType, TColor)
Transforms source image using the specified matrix
public Image<TColor, TDepth> WarpPerspective<TMapDepth>(Matrix<TMapDepth> mapMatrix, Inter interpolationType, Warp warpType, BorderType borderMode, TColor backgroundColor) where TMapDepth : new()
Parameters
mapMatrix
Matrix<TMapDepth>3x3 transformation matrix
interpolationType
InterInterpolation type
warpType
WarpWarp type
borderMode
BorderTypePixel extrapolation method
backgroundColor
TColorA value used to fill outliers
Returns
- Image<TColor, TDepth>
The result of the transformation
Type Parameters
TMapDepth
The depth type of
mapMatrix
, should be either float or double
WarpPerspective<TMapDepth>(Matrix<TMapDepth>, int, int, Inter, Warp, BorderType, TColor)
Transforms source image using the specified matrix
public Image<TColor, TDepth> WarpPerspective<TMapDepth>(Matrix<TMapDepth> mapMatrix, int width, int height, Inter interpolationType, Warp warpType, BorderType borderType, TColor backgroundColor) where TMapDepth : new()
Parameters
mapMatrix
Matrix<TMapDepth>3x3 transformation matrix
width
intThe width of the resulting image
height
intthe height of the resulting image
interpolationType
InterInterpolation type
warpType
WarpWarp type
borderType
BorderTypeBorder type
backgroundColor
TColorA value used to fill outliers
Returns
- Image<TColor, TDepth>
The result of the transformation
Type Parameters
TMapDepth
The depth type of
mapMatrix
, should be either float or double
Xor(Image<TColor, TDepth>)
Perform an elementwise XOR operation with another image and return the result
public Image<TColor, TDepth> Xor(Image<TColor, TDepth> img2)
Parameters
img2
Image<TColor, TDepth>The second image for the XOR operation
Returns
- Image<TColor, TDepth>
The result of the XOR operation
Xor(Image<TColor, TDepth>, Image<Gray, byte>)
Perform an elementwise XOR operation with another image, using a mask, and return the result
public Image<TColor, TDepth> Xor(Image<TColor, TDepth> img2, Image<Gray, byte> mask)
Parameters
img2
Image<TColor, TDepth>The second image for the XOR operation
mask
Image<Gray, byte>The mask for the XOR operation
Returns
- Image<TColor, TDepth>
The result of the XOR operation
Xor(TColor)
Perform an binary XOR operation with some color
[ExposableMethod(Exposable = true, Category = "Logic")]
public Image<TColor, TDepth> Xor(TColor val)
Parameters
val
TColorThe value for the XOR operation
Returns
- Image<TColor, TDepth>
The result of the XOR operation
Xor(TColor, Image<Gray, byte>)
Perform an binary XOR operation with some color using a mask
public Image<TColor, TDepth> Xor(TColor val, Image<Gray, byte> mask)
Parameters
Returns
- Image<TColor, TDepth>
The result of the XOR operation
_Dilate(int)
Dilates this image inplace using a 3x3 rectangular structuring element. Dilation are applied several (iterations) times
[ExposableMethod(Exposable = true, Category = "Morphology")]
public void _Dilate(int iterations)
Parameters
iterations
intThe number of dilate iterations
_EqualizeHist()
The algorithm inplace normalizes brightness and increases contrast of the image. For color images, a HSV representation of the image is first obtained and the V (value) channel is histogram normalized
[ExposableMethod(Exposable = true)]
public void _EqualizeHist()
_Erode(int)
Erodes this image inplace using a 3x3 rectangular structuring element. Erosion are applied several (iterations) times
[ExposableMethod(Exposable = true, Category = "Morphology")]
public void _Erode(int iterations)
Parameters
iterations
intThe number of erode iterations
_Flip(FlipType)
Inplace flip the image
[ExposableMethod(Exposable = true, Category = "Transform")]
public void _Flip(FlipType flipType)
Parameters
flipType
FlipTypeThe type of the flipping
_GammaCorrect(double)
Gamma corrects this image inplace. The image must have a depth type of Byte.
[ExposableMethod(Exposable = true)]
public void _GammaCorrect(double gamma)
Parameters
gamma
doubleThe gamma value
_MorphologyEx(MorphOp, IInputArray, Point, int, BorderType, MCvScalar)
Perform inplace advanced morphological transformations using erosion and dilation as basic operations.
public void _MorphologyEx(MorphOp operation, IInputArray kernel, Point anchor, int iterations, BorderType borderType, MCvScalar borderValue)
Parameters
operation
MorphOpType of morphological operation
kernel
IInputArrayStructuring element
anchor
PointAnchor position with the kernel. Negative values mean that the anchor is at the kernel center.
iterations
intNumber of times erosion and dilation are applied
borderType
BorderTypeBorder type
borderValue
MCvScalarBorder value
_SmoothGaussian(int)
Perform Gaussian Smoothing inplace for the current image
public void _SmoothGaussian(int kernelSize)
Parameters
kernelSize
intThe size of the Gaussian kernel (
kernelSize
xkernelSize
)
_SmoothGaussian(int, int, double, double)
Perform Gaussian Smoothing inplace for the current image
public void _SmoothGaussian(int kernelWidth, int kernelHeight, double sigma1, double sigma2)
Parameters
kernelWidth
intThe width of the Gaussian kernel
kernelHeight
intThe height of the Gaussian kernel
sigma1
doubleThe standard deviation of the Gaussian kernel in the horizontal dimension
sigma2
doubleThe standard deviation of the Gaussian kernel in the vertical dimension
_ThresholdBinary(TColor, TColor)
Threshold the image inplace such that: dst(x,y) = max_value, if src(x,y)>threshold; 0, otherwise
[ExposableMethod(Exposable = true, Category = "Threshold")]
public void _ThresholdBinary(TColor threshold, TColor maxValue)
Parameters
threshold
TColorThe threshold value
maxValue
TColorThe maximum value of the pixel on the result
_ThresholdBinaryInv(TColor, TColor)
Threshold the image inplace such that: dst(x,y) = 0, if src(x,y)>threshold; max_value, otherwise
[ExposableMethod(Exposable = true, Category = "Threshold")]
public void _ThresholdBinaryInv(TColor threshold, TColor maxValue)
Parameters
threshold
TColorThe threshold value
maxValue
TColorThe maximum value of the pixel on the result
_ThresholdToZero(TColor)
Threshold the image inplace such that: dst(x,y) = src(x,y), if src(x,y)>threshold; 0, otherwise
[ExposableMethod(Exposable = true, Category = "Threshold")]
public void _ThresholdToZero(TColor threshold)
Parameters
threshold
TColorThe threshold value
_ThresholdToZeroInv(TColor)
Threshold the image inplace such that: dst(x,y) = 0, if src(x,y)>threshold; src(x,y), otherwise
[ExposableMethod(Exposable = true, Category = "Threshold")]
public void _ThresholdToZeroInv(TColor threshold)
Parameters
threshold
TColorThe threshold value
_ThresholdTrunc(TColor)
Threshold the image inplace such that: dst(x,y) = threshold, if src(x,y)>threshold; src(x,y), otherwise
[ExposableMethod(Exposable = true, Category = "Threshold")]
public void _ThresholdTrunc(TColor threshold)
Parameters
threshold
TColorThe threshold value
Operators
operator +(Image<TColor, TDepth>, Image<TColor, TDepth>)
Element wise add img1
with img2
public static Image<TColor, TDepth> operator +(Image<TColor, TDepth> img1, Image<TColor, TDepth> img2)
Parameters
img1
Image<TColor, TDepth>The first image to be added
img2
Image<TColor, TDepth>The second image to be added
Returns
- Image<TColor, TDepth>
The sum of the two images
operator +(Image<TColor, TDepth>, double)
Element wise add image
with value
public static Image<TColor, TDepth> operator +(Image<TColor, TDepth> image, double value)
Parameters
Returns
- Image<TColor, TDepth>
The images plus the color
operator +(Image<TColor, TDepth>, TColor)
Element wise add image
with value
public static Image<TColor, TDepth> operator +(Image<TColor, TDepth> image, TColor value)
Parameters
image
Image<TColor, TDepth>The image to be added
value
TColorThe color to be added
Returns
- Image<TColor, TDepth>
The images plus the color
operator +(double, Image<TColor, TDepth>)
Element wise add img1
with val
public static Image<TColor, TDepth> operator +(double val, Image<TColor, TDepth> img1)
Parameters
Returns
- Image<TColor, TDepth>
The images plus the color
operator +(TColor, Image<TColor, TDepth>)
Element wise add image
with value
public static Image<TColor, TDepth> operator +(TColor value, Image<TColor, TDepth> image)
Parameters
value
TColorThe color to be added
image
Image<TColor, TDepth>The image to be added
Returns
- Image<TColor, TDepth>
The images plus the color
operator &(Image<TColor, TDepth>, Image<TColor, TDepth>)
Perform an element wise AND operation on the two images
public static Image<TColor, TDepth> operator &(Image<TColor, TDepth> img1, Image<TColor, TDepth> img2)
Parameters
img1
Image<TColor, TDepth>The first image to AND
img2
Image<TColor, TDepth>The second image to AND
Returns
- Image<TColor, TDepth>
The result of the AND operation
operator &(Image<TColor, TDepth>, double)
Perform an element wise AND operation using an images and a color
public static Image<TColor, TDepth> operator &(Image<TColor, TDepth> img1, double val)
Parameters
Returns
- Image<TColor, TDepth>
The result of the AND operation
operator &(Image<TColor, TDepth>, TColor)
Perform an element wise AND operation using an images and a color
public static Image<TColor, TDepth> operator &(Image<TColor, TDepth> img1, TColor val)
Parameters
img1
Image<TColor, TDepth>The first image to AND
val
TColorThe color to AND
Returns
- Image<TColor, TDepth>
The result of the AND operation
operator &(double, Image<TColor, TDepth>)
Perform an element wise AND operation using an images and a color
public static Image<TColor, TDepth> operator &(double val, Image<TColor, TDepth> img1)
Parameters
Returns
- Image<TColor, TDepth>
The result of the AND operation
operator &(TColor, Image<TColor, TDepth>)
Perform an element wise AND operation using an images and a color
public static Image<TColor, TDepth> operator &(TColor val, Image<TColor, TDepth> img1)
Parameters
val
TColorThe color to AND
img1
Image<TColor, TDepth>The first image to AND
Returns
- Image<TColor, TDepth>
The result of the AND operation
operator |(Image<TColor, TDepth>, Image<TColor, TDepth>)
Perform an element wise OR operation with another image and return the result
public static Image<TColor, TDepth> operator |(Image<TColor, TDepth> img1, Image<TColor, TDepth> img2)
Parameters
img1
Image<TColor, TDepth>The first image to apply bitwise OR operation
img2
Image<TColor, TDepth>The second image to apply bitwise OR operation
Returns
- Image<TColor, TDepth>
The result of the OR operation
operator |(Image<TColor, TDepth>, double)
Perform an binary OR operation with some color
public static Image<TColor, TDepth> operator |(Image<TColor, TDepth> img1, double val)
Parameters
Returns
- Image<TColor, TDepth>
The result of the OR operation
operator |(Image<TColor, TDepth>, TColor)
Perform an binary OR operation with some color
public static Image<TColor, TDepth> operator |(Image<TColor, TDepth> img1, TColor val)
Parameters
img1
Image<TColor, TDepth>The image to OR
val
TColorThe color to OR
Returns
- Image<TColor, TDepth>
The result of the OR operation
operator |(double, Image<TColor, TDepth>)
Perform an binary OR operation with some color
public static Image<TColor, TDepth> operator |(double val, Image<TColor, TDepth> img1)
Parameters
Returns
- Image<TColor, TDepth>
The result of the OR operation
operator |(TColor, Image<TColor, TDepth>)
Perform an binary OR operation with some color
public static Image<TColor, TDepth> operator |(TColor val, Image<TColor, TDepth> img1)
Parameters
val
TColorThe color to OR
img1
Image<TColor, TDepth>The image to OR
Returns
- Image<TColor, TDepth>
The result of the OR operation
operator /(Image<TColor, TDepth>, double)
image
/ scale
public static Image<TColor, TDepth> operator /(Image<TColor, TDepth> image, double scale)
Parameters
Returns
- Image<TColor, TDepth>
image
/scale
operator /(double, Image<TColor, TDepth>)
scale
/ image
public static Image<TColor, TDepth> operator /(double scale, Image<TColor, TDepth> image)
Parameters
Returns
- Image<TColor, TDepth>
scale
/image
operator *(Image<TColor, TDepth>, ConvolutionKernelF)
Perform the convolution with kernel
on image
public static Image<TColor, float> operator *(Image<TColor, TDepth> image, ConvolutionKernelF kernel)
Parameters
image
Image<TColor, TDepth>The image
kernel
ConvolutionKernelFThe kernel
Returns
operator *(Image<TColor, TDepth>, double)
image
* scale
public static Image<TColor, TDepth> operator *(Image<TColor, TDepth> image, double scale)
Parameters
Returns
- Image<TColor, TDepth>
image
*scale
operator *(double, Image<TColor, TDepth>)
scale
*image
public static Image<TColor, TDepth> operator *(double scale, Image<TColor, TDepth> image)
Parameters
Returns
- Image<TColor, TDepth>
scale
*image
operator ~(Image<TColor, TDepth>)
Compute the complement image
public static Image<TColor, TDepth> operator ~(Image<TColor, TDepth> image)
Parameters
image
Image<TColor, TDepth>The image to be inverted
Returns
- Image<TColor, TDepth>
The complement image
operator -(Image<TColor, TDepth>, Image<TColor, TDepth>)
Element wise subtract another image from the current image
public static Image<TColor, TDepth> operator -(Image<TColor, TDepth> image1, Image<TColor, TDepth> image2)
Parameters
image1
Image<TColor, TDepth>The image to be subtracted
image2
Image<TColor, TDepth>The second image to be subtracted from
image1
Returns
- Image<TColor, TDepth>
The result of element wise subtracting img2 from
image1
operator -(Image<TColor, TDepth>, double)
Element wise subtract another image from the current image
public static Image<TColor, TDepth> operator -(Image<TColor, TDepth> image, double value)
Parameters
Returns
- Image<TColor, TDepth>
image
-value
operator -(Image<TColor, TDepth>, TColor)
Element wise subtract another image from the current image
public static Image<TColor, TDepth> operator -(Image<TColor, TDepth> image, TColor value)
Parameters
image
Image<TColor, TDepth>The image to be subtracted
value
TColorThe color to be subtracted
Returns
- Image<TColor, TDepth>
The result of element wise subtracting
value
fromimage
operator -(double, Image<TColor, TDepth>)
value
- image
public static Image<TColor, TDepth> operator -(double value, Image<TColor, TDepth> image)
Parameters
Returns
- Image<TColor, TDepth>
value
-image
operator -(TColor, Image<TColor, TDepth>)
Element wise subtract another image from the current image
public static Image<TColor, TDepth> operator -(TColor value, Image<TColor, TDepth> image)
Parameters
value
TColorThe color to be subtracted
image
Image<TColor, TDepth>The image to be subtracted
Returns
- Image<TColor, TDepth>
value
-image