Skip to content

Commit ed7f706

Browse files
authored
VectorToImageTransform conversion to estimator/transformer (#2580)
* Convert VectorToImageTransform to estimator/transformer * Rename Schema, Row, etc. * Code review comments, and fix baseline of EntryPointCatalog test * Code review comments * Fix EntryPointCatalog baseline
1 parent eb60021 commit ed7f706

File tree

6 files changed

+459
-295
lines changed

6 files changed

+459
-295
lines changed

src/Microsoft.ML.ImageAnalytics/EntryPoints/ImageAnalytics.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public static CommonOutputs.TransformOutput ImageGrayscale(IHostEnvironment env,
6363
};
6464
}
6565

66-
[TlcModule.EntryPoint(Name = "Transforms.VectorToImage", Desc = VectorToImageTransform.Summary,
67-
UserName = VectorToImageTransform.UserName, ShortName = VectorToImageTransform.LoaderSignature)]
68-
public static CommonOutputs.TransformOutput VectorToImage(IHostEnvironment env, VectorToImageTransform.Arguments input)
66+
[TlcModule.EntryPoint(Name = "Transforms.VectorToImage", Desc = VectorToImageConvertingTransformer.Summary,
67+
UserName = VectorToImageConvertingTransformer.UserName, ShortName = VectorToImageConvertingTransformer.LoaderSignature)]
68+
public static CommonOutputs.TransformOutput VectorToImage(IHostEnvironment env, VectorToImageConvertingTransformer.Options input)
6969
{
7070
var h = EntryPointUtils.CheckArgsAndCreateHost(env, "VectorToImageTransform", input);
71-
var xf = new VectorToImageTransform(h, input, input.Data);
71+
var xf = VectorToImageConvertingTransformer.Create(h, input, input.Data);
7272
return new CommonOutputs.TransformOutput()
7373
{
7474
Model = new TransformModelImpl(h, xf, input.Data),

src/Microsoft.ML.ImageAnalytics/ExtensionsCatalog.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static ImagePixelExtractingEstimator ExtractPixels(this TransformsCatalog
7272

7373
/// <include file='doc.xml' path='doc/members/member[@name="ImagePixelExtractingEstimator"]/*' />
7474
/// <param name="catalog">The transform's catalog.</param>
75-
/// <param name="columns">The name of the columns containing the image paths, and per-column configurations.</param>
75+
/// <param name="columns">The name of the columns containing the images, and per-column configurations.</param>
7676
public static ImagePixelExtractingEstimator ExtractPixels(this TransformsCatalog catalog, params ImagePixelExtractingEstimator.ColumnInfo[] columns)
7777
=> new ImagePixelExtractingEstimator(CatalogUtils.GetEnvironment(catalog), columns);
7878

@@ -133,5 +133,33 @@ public static ImageResizingEstimator ResizeImages(this TransformsCatalog catalog
133133
/// </example>
134134
public static ImageResizingEstimator ResizeImages(this TransformsCatalog catalog, params ImageResizingEstimator.ColumnInfo[] columns)
135135
=> new ImageResizingEstimator(CatalogUtils.GetEnvironment(catalog), columns);
136+
137+
/// <summary>
138+
/// Converts vectors of pixels into <see cref="ImageType"/> representation.
139+
/// </summary>
140+
/// <param name="catalog">The transform's catalog.</param>
141+
/// <param name="columns">The name of the columns containing the pixels, and per-column configurations.</param>
142+
public static VectorToImageConvertingEstimator ConvertToImage(this TransformsCatalog catalog, params VectorToImageConvertingEstimator.ColumnInfo[] columns)
143+
=> new VectorToImageConvertingEstimator(CatalogUtils.GetEnvironment(catalog), columns);
144+
145+
/// <summary>
146+
/// Converts vectors of pixels into <see cref="ImageType"/> representation.
147+
/// </summary>
148+
/// <param name="catalog">The transforms' catalog.</param>
149+
/// <param name="height">The height of the output images.</param>
150+
/// <param name="width">The width of the output images.</param>
151+
/// <param name="outputColumnName"> Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param>
152+
/// <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>
153+
/// <param name="colors"> Specifies which <see cref="ImagePixelExtractingEstimator.ColorBits"/> are in the input pixel vectors. The order of colors is: Alpha, Red, Green Blue.</param>
154+
/// <param name="interleave">Whether the pixels are interleaved, meaning whether they are in `ARGB ARGB` order, or separated in the planar form, where the colors are specified one by one
155+
/// alpha, red, green, blue for all the pixels of the image. </param>
156+
/// <param name="scale">The values are scaled by this value before being converted to pixels.</param>
157+
/// <param name="offset">The offset is subtracted (before scaling) before converting the values to pixels.</param>
158+
public static VectorToImageConvertingEstimator ConvertToImage(this TransformsCatalog catalog, int height, int width, string outputColumnName, string inputColumnName = null,
159+
ImagePixelExtractingEstimator.ColorBits colors = VectorToImageConvertingTransformer.Defaults.Colors,
160+
bool interleave = VectorToImageConvertingTransformer.Defaults.InterleaveArgb,
161+
float scale = VectorToImageConvertingTransformer.Defaults.Scale,
162+
float offset = VectorToImageConvertingTransformer.Defaults.Offset)
163+
=> new VectorToImageConvertingEstimator(CatalogUtils.GetEnvironment(catalog), height, width, outputColumnName, inputColumnName, colors, interleave, scale, offset);
136164
}
137165
}

0 commit comments

Comments
 (0)