/// <include file='doc.xml' path='doc/members/member[@name="ImagePixelExtractingEstimator"]/*' /> /// <param name="catalog">The transform's catalog.</param> /// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param> /// <param name="inputColumnName">Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param> /// <param name="colorsToExtract">The colors to extract from the image.</param> /// <param name="orderOfExtraction">The order in which to extract colors from pixel.</param> /// <param name="interleavePixelColors">Whether to interleave the pixels colors, meaning keep them in the <paramref name="orderOfExtraction"/> order, or leave them in the plannar form: /// all the values for one color for all pixels, then all the values for another color, and so on.</param> /// <param name="offsetImage">Offset each pixel's color value by this amount. Applied to color value before <paramref name="scaleImage"/>.</param> /// <param name="scaleImage">Scale each pixel's color value by this amount. Applied to color value after <paramref name="offsetImage"/>.</param> /// <param name="outputAsFloatArray">Output array as float array. If false, output as byte array and ignores <paramref name="offsetImage"/> and <paramref name="scaleImage"/>.</param> /// <example> /// <format type="text/markdown"> /// <![CDATA[ /// [!code-csharp[ExtractPixels](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/ExtractPixels.cs)] /// ]]></format> /// </example> public static ImagePixelExtractingEstimator ExtractPixels(this TransformsCatalog catalog, string outputColumnName, string inputColumnName = null, ImagePixelExtractingEstimator.ColorBits colorsToExtract = ImagePixelExtractingEstimator.Defaults.Colors, ImagePixelExtractingEstimator.ColorsOrder orderOfExtraction = ImagePixelExtractingEstimator.Defaults.Order, bool interleavePixelColors = false, float offsetImage = ImagePixelExtractingEstimator.Defaults.Offset, float scaleImage = ImagePixelExtractingEstimator.Defaults.Scale, bool outputAsFloatArray = ImagePixelExtractingEstimator.Defaults.Convert) => new ImagePixelExtractingEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, inputColumnName, colorsToExtract, orderOfExtraction, interleavePixelColors, offsetImage, scaleImage, outputAsFloatArray);
/// <summary> /// Converts vectors of pixels into <see cref="ImageType"/> representation. /// </summary> /// <param name="catalog">The transforms' catalog.</param> /// <param name="imageHeight">The height of the output images.</param> /// <param name="imageWidth">The width of the output images.</param> /// <param name="outputColumnName"> Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param> /// <param name="inputColumnName"> Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param> /// <param name="colorsPresent">Specifies which <see cref="ImagePixelExtractingEstimator.ColorBits"/> are in present the input pixel vectors. The order of colors is specified in <paramref name="orderOfColors"/>.</param> /// <param name="orderOfColors">The order in which colors are presented in the input vector.</param> /// <param name="interleavedColors">Whether the pixels are interleaved, meaning whether they are in <paramref name="orderOfColors"/> order, or separated in the planar form: /// all the values for one color for all pixels, then all the values for another color and so on.</param> /// <param name="scaleImage">The values are scaled by this value before being converted to pixels. Applied to vector value before <paramref name="offsetImage"/>.</param> /// <param name="offsetImage">The offset is subtracted before converting the values to pixels. Applied to vector value after <paramref name="scaleImage"/>.</param> /// <param name="defaultAlpha">Default value for alpha color, would be overriden if <paramref name="colorsPresent"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Alpha"/>.</param> /// <param name="defaultRed">Default value for red color, would be overriden if <paramref name="colorsPresent"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Red"/>.</param> /// <param name="defaultGreen">Default value for grenn color, would be overriden if <paramref name="colorsPresent"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Green"/>.</param> /// <param name="defaultBlue">Default value for blue color, would be overriden if <paramref name="colorsPresent"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Blue"/>.</param> public static VectorToImageConvertingEstimator ConvertToImage(this TransformsCatalog catalog, int imageHeight, int imageWidth, string outputColumnName, string inputColumnName = null, ImagePixelExtractingEstimator.ColorBits colorsPresent = ImagePixelExtractingEstimator.Defaults.Colors, ImagePixelExtractingEstimator.ColorsOrder orderOfColors = ImagePixelExtractingEstimator.Defaults.Order, bool interleavedColors = ImagePixelExtractingEstimator.Defaults.Interleave, float scaleImage = VectorToImageConvertingEstimator.Defaults.Scale, float offsetImage = VectorToImageConvertingEstimator.Defaults.Offset, int defaultAlpha = VectorToImageConvertingEstimator.Defaults.DefaultAlpha, int defaultRed = VectorToImageConvertingEstimator.Defaults.DefaultRed, int defaultGreen = VectorToImageConvertingEstimator.Defaults.DefaultGreen, int defaultBlue = VectorToImageConvertingEstimator.Defaults.DefaultBlue) => new VectorToImageConvertingEstimator(CatalogUtils.GetEnvironment(catalog), imageHeight, imageWidth, outputColumnName, inputColumnName, colorsPresent, orderOfColors, interleavedColors, scaleImage, offsetImage);
///<summary> /// Extract pixels values from image and produce array of values. ///</summary> /// <param name="env">The host environment.</param> /// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param> /// <param name="inputColumnName">Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param> /// <param name="colorsToExtract">What colors to extract.</param> /// <param name="orderOfExtraction">In which order to extract colors from pixel.</param> /// <param name="interleavePixelColors">Whether to interleave the pixels colors, meaning keep them in the <paramref name="orderOfExtraction"/> order, or leave them in the plannar form: /// all the values for one color for all pixels, then all the values for another color and so on.</param> /// <param name="offsetImage">Offset each pixel's color value by this amount. Applied to color value first.</param> /// <param name="scaleImage">Scale each pixel's color value by this amount. Applied to color value second.</param> /// <param name="outputAsFloatArray">Output array as float array. If false, output as byte array and ignores <paramref name="offsetImage"/> and <paramref name="scaleImage"/>.</param> internal ImagePixelExtractingTransformer(IHostEnvironment env, string outputColumnName, string inputColumnName = null, ImagePixelExtractingEstimator.ColorBits colorsToExtract = ImagePixelExtractingEstimator.Defaults.Colors, ImagePixelExtractingEstimator.ColorsOrder orderOfExtraction = ImagePixelExtractingEstimator.Defaults.Order, bool interleavePixelColors = ImagePixelExtractingEstimator.Defaults.Interleave, float offsetImage = ImagePixelExtractingEstimator.Defaults.Offset, float scaleImage = ImagePixelExtractingEstimator.Defaults.Scale, bool outputAsFloatArray = ImagePixelExtractingEstimator.Defaults.Convert) : this(env, new ImagePixelExtractingEstimator.ColumnOptions(outputColumnName, inputColumnName, colorsToExtract, orderOfExtraction, interleavePixelColors, offsetImage, scaleImage, outputAsFloatArray)) { }
///<summary> /// Extract pixels values from image and produce array of values. ///</summary> /// <param name="env">The host environment.</param> /// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param> /// <param name="inputColumnName">Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param> /// <param name="colors">What colors to extract.</param> /// <param name="order">In which order to extract colors from pixel.</param> /// <param name="interleave">Whether to interleave the pixels colors, meaning keep them in the <paramref name="order"/> order, or leave them in the plannar form: /// all the values for one color for all pixels, then all the values for another color and so on.</param> /// <param name="offset">Offset pixel's color value by this amount. Applied to color value first.</param> /// <param name="scale">Scale pixel's color value by this amount. Applied to color value second.</param> /// <param name="asFloat">Output array as float array. If false, output as byte array and ignores <paramref name="offset"/> and <paramref name="scale"/>.</param> internal ImagePixelExtractingTransformer(IHostEnvironment env, string outputColumnName, string inputColumnName = null, ImagePixelExtractingEstimator.ColorBits colors = ImagePixelExtractingEstimator.Defaults.Colors, ImagePixelExtractingEstimator.ColorsOrder order = ImagePixelExtractingEstimator.Defaults.Order, bool interleave = ImagePixelExtractingEstimator.Defaults.Interleave, float offset = ImagePixelExtractingEstimator.Defaults.Offset, float scale = ImagePixelExtractingEstimator.Defaults.Scale, bool asFloat = ImagePixelExtractingEstimator.Defaults.Convert) : this(env, new ImagePixelExtractingEstimator.ColumnInfo(outputColumnName, inputColumnName, colors, order, interleave, offset, scale, asFloat)) { }
/// <param name="env">The host environment.</param> /// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param> /// <param name="imageHeight">The height of the output images.</param> /// <param name="imageWidth">The width of the output images.</param> /// <param name="inputColumnName">Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param> /// <param name="colorsPresent">Specifies which <see cref="ImagePixelExtractingEstimator.ColorBits"/> are in present the input pixel vectors. The order of colors is specified in <paramref name="orderOfColors"/>.</param> /// <param name="orderOfColors">The order in which colors are presented in the input vector.</param> /// <param name="interleavedColors">Whether the pixels are interleaved, meaning whether they are in <paramref name="orderOfColors"/> order, or separated in the planar form, where the colors are specified one by one /// for all the pixels of the image. </param> /// <param name="scaleImage">Scale each pixel's color value by this amount.</param> /// <param name="offsetImage">Offset each pixel's color value by this amount.</param> /// <param name="defaultAlpha">Default value for alpha color, would be overriden if <paramref name="colorsPresent"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Alpha"/>.</param> /// <param name="defaultRed">Default value for red color, would be overriden if <paramref name="colorsPresent"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Red"/>.</param> /// <param name="defaultGreen">Default value for grenn color, would be overriden if <paramref name="colorsPresent"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Green"/>.</param> /// <param name="defaultBlue">Default value for blue color, would be overriden if <paramref name="colorsPresent"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Blue"/>.</param> internal VectorToImageConvertingTransformer(IHostEnvironment env, string outputColumnName, int imageHeight, int imageWidth, string inputColumnName = null, ImagePixelExtractingEstimator.ColorBits colorsPresent = ImagePixelExtractingEstimator.Defaults.Colors, ImagePixelExtractingEstimator.ColorsOrder orderOfColors = ImagePixelExtractingEstimator.Defaults.Order, bool interleavedColors = ImagePixelExtractingEstimator.Defaults.Interleave, float scaleImage = VectorToImageConvertingEstimator.Defaults.Scale, float offsetImage = VectorToImageConvertingEstimator.Defaults.Offset, int defaultAlpha = VectorToImageConvertingEstimator.Defaults.DefaultAlpha, int defaultRed = VectorToImageConvertingEstimator.Defaults.DefaultRed, int defaultGreen = VectorToImageConvertingEstimator.Defaults.DefaultGreen, int defaultBlue = VectorToImageConvertingEstimator.Defaults.DefaultBlue) : this(env, new VectorToImageConvertingEstimator.ColumnOptions(outputColumnName, imageHeight, imageWidth, inputColumnName, colorsPresent, orderOfColors, interleavedColors, scaleImage, offsetImage, defaultAlpha, defaultRed, defaultGreen, defaultBlue)) { }
/// <param name="env">The host environment.</param> /// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param> /// <param name="height">The height of the output images.</param> /// <param name="width">The width of the output images.</param> /// <param name="inputColumnName">Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param> /// <param name="colors">What colors to extract.</param> /// <param name="order">In which order extracted colors presented in array.</param> /// <param name="interleave">Whether the pixels are interleaved, meaning whether they are in <paramref name="order"/> order, or separated in the planar form, where the colors are specified one by one /// for all the pixels of the image. </param> /// <param name="scale">Scale color pixel value by this amount.</param> /// <param name="offset">Offset color pixel value by this amount.</param> /// <param name="defaultAlpha">Default value for alpha color, would be overriden if <paramref name="colors"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Alpha"/>.</param> /// <param name="defaultRed">Default value for red color, would be overriden if <paramref name="colors"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Red"/>.</param> /// <param name="defaultGreen">Default value for grenn color, would be overriden if <paramref name="colors"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Green"/>.</param> /// <param name="defaultBlue">Default value for blue color, would be overriden if <paramref name="colors"/> contains <see cref="ImagePixelExtractingEstimator.ColorBits.Blue"/>.</param> internal VectorToImageConvertingTransformer(IHostEnvironment env, string outputColumnName, int height, int width, string inputColumnName = null, ImagePixelExtractingEstimator.ColorBits colors = ImagePixelExtractingEstimator.Defaults.Colors, ImagePixelExtractingEstimator.ColorsOrder order = ImagePixelExtractingEstimator.Defaults.Order, bool interleave = ImagePixelExtractingEstimator.Defaults.Interleave, float scale = VectorToImageConvertingEstimator.Defaults.Scale, float offset = VectorToImageConvertingEstimator.Defaults.Offset, int defaultAlpha = VectorToImageConvertingEstimator.Defaults.DefaultAlpha, int defaultRed = VectorToImageConvertingEstimator.Defaults.DefaultRed, int defaultGreen = VectorToImageConvertingEstimator.Defaults.DefaultGreen, int defaultBlue = VectorToImageConvertingEstimator.Defaults.DefaultBlue) : this(env, new VectorToImageConvertingEstimator.ColumnInfo(outputColumnName, height, width, inputColumnName, colors, order, interleave, scale, offset, defaultAlpha, defaultRed, defaultGreen, defaultBlue)) { }
/// <summary> /// Vectorizes the image as the numeric byte values of its pixels. /// The output vector is output in height then width major order, with the channels being the most minor (if /// <paramref name="interleave"/> is true) or major (if <paramref name="interleave"/> is false) dimension. /// </summary> /// <param name="input">The input image to extract</param> /// <param name="useAlpha">Whether the alpha channel should be extracted</param> /// <param name="useRed">Whether the red channel should be extracted</param> /// <param name="useGreen">Whether the green channel should be extracted</param> /// <param name="useBlue">Whether the blue channel should be extracted</param> /// <param name="order">In which order extract channels.</param> /// <param name="interleave">Whether the pixel values should be interleaved, as opposed to being separated by channel</param> /// <returns>The vectorized image</returns> /// <seealso cref="ImagePixelExtractingEstimator"/> public static Vector <byte> ExtractPixelsAsBytes(this Custom <Bitmap> input, bool useAlpha = false, bool useRed = true, bool useGreen = true, bool useBlue = true, ImagePixelExtractingEstimator.ColorsOrder order = ImagePixelExtractingEstimator.Defaults.Order, bool interleave = false) { var colParams = new ImagePixelExtractingTransformer.Column { UseAlpha = useAlpha, UseRed = useRed, UseGreen = useGreen, UseBlue = useBlue, Interleave = interleave, Convert = false }; return(new ImagePixelExtractingStaticExtensions.OutPipelineColumn <byte>(input, colParams)); }
/// <summary> /// Vectorizes the image as the numeric values of its pixels converted and possibly transformed to floating point values. /// The output vector is output in height then width major order, with the channels being the most minor (if /// <paramref name="interleave"/> is true) or major (if <paramref name="interleave"/> is false) dimension. /// </summary> /// <param name="input">The input image to extract</param> /// <param name="useAlpha">Whether the alpha channel should be extracted</param> /// <param name="useRed">Whether the red channel should be extracted</param> /// <param name="useGreen">Whether the green channel should be extracted</param> /// <param name="useBlue">Whether the blue channel should be extracted</param> /// <param name="order">In which order extract channels.</param> /// <param name="interleave">Whether the pixel values should be interleaved, as opposed to being separated by channel</param> /// <param name="scale">Scale the normally 0 through 255 pixel values by this amount</param> /// <param name="offset">Add this amount to the pixel values, before scaling</param> /// <returns>The vectorized image</returns> /// <seealso cref="ImagePixelExtractingEstimator"/> public static Vector <float> ExtractPixels(this Custom <Bitmap> input, bool useAlpha = false, bool useRed = true, bool useGreen = true, bool useBlue = true, ImagePixelExtractingEstimator.ColorsOrder order = ImagePixelExtractingEstimator.Defaults.Order, bool interleave = false, float scale = 1.0f, float offset = 0.0f) { var colParams = new ImagePixelExtractingTransformer.Column { UseAlpha = useAlpha, UseRed = useRed, UseGreen = useGreen, UseBlue = useBlue, Interleave = interleave, Scale = scale, Offset = offset, Convert = true }; return(new ImagePixelExtractingStaticExtensions.OutPipelineColumn <float>(input, colParams)); }