Пример #1
0
 ///<summary>
 /// Resize image.
 ///</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="imageWidth">Width of resized image.</param>
 /// <param name="imageHeight">Height of resized image.</param>
 /// <param name="inputColumnName">Name of the input column.</param>
 /// <param name="resizing">What <see cref="ImageResizingEstimator.ResizingKind"/> to use.</param>
 /// <param name="cropAnchor">If <paramref name="resizing"/> set to <see cref="ImageResizingEstimator.ResizingKind.IsoCrop"/> what anchor to use for cropping.</param>
 internal ImageResizingTransformer(IHostEnvironment env, string outputColumnName,
                                   int imageWidth, int imageHeight, string inputColumnName = null,
                                   ImageResizingEstimator.ResizingKind resizing            = ImageResizingEstimator.ResizingKind.IsoCrop,
                                   ImageResizingEstimator.Anchor cropAnchor = ImageResizingEstimator.Anchor.Center)
     : this(env, new ImageResizingEstimator.ColumnOptions(outputColumnName, imageWidth, imageHeight, inputColumnName, resizing, cropAnchor))
 {
 }
 /// <summary>
 /// Resizes the images to a new width and height.
 /// </summary>
 /// <remarks>
 /// In image processing pipelines, often machine learning practitioner make use of<a href= "https://blogs.msdn.microsoft.com/mlserver/2017/04/12/image-featurization-with-a-pre-trained-deep-neural-network-model/">
 /// pre-trained DNN featurizers</a> to extract features for usage in the machine learning algorithms.
 /// Those pre-trained models have a defined width and height for their input images, so often, after getting loaded, the images will need to get resized before
 /// further processing.
 /// The new width and height can be specified in the <paramref name="imageWidth"/> and <paramref name="imageHeight"/>
 /// <seealso cref = "ImageEstimatorsCatalog" />
 /// <seealso cref= "ImageLoadingEstimator" />
 /// </remarks >
 /// <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="imageWidth">The transformed image width.</param>
 /// <param name="imageHeight">The transformed image height.</param>
 /// <param name="resizing"> The type of image resizing as specified in <see cref="ImageResizingEstimator.ResizingKind"/>.</param>
 /// <param name="cropAnchor">Where to place the anchor, to start cropping. Options defined in <see cref="ImageResizingEstimator.Anchor"/></param>
 /// <example>
 /// <format type="text/markdown">
 /// <![CDATA[
 ///  [!code-csharp[ResizeImages](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/ImageAnalytics/ResizeImages.cs)]
 /// ]]></format>
 /// </example>
 public static ImageResizingEstimator ResizeImages(this TransformsCatalog catalog,
                                                   string outputColumnName,
                                                   int imageWidth,
                                                   int imageHeight,
                                                   string inputColumnName = null,
                                                   ImageResizingEstimator.ResizingKind resizing = ImageResizingEstimator.ResizingKind.IsoCrop,
                                                   ImageResizingEstimator.Anchor cropAnchor     = ImageResizingEstimator.Anchor.Center)
 => new ImageResizingEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, imageWidth, imageHeight, inputColumnName, resizing, cropAnchor);
        /// <summary>
        /// Given a column of images, resize them to a new fixed size.
        /// </summary>
        /// <param name="input">The input images</param>
        /// <param name="width">The width to resize to</param>
        /// <param name="height">The height to resize to</param>
        /// <param name="resizing">The type of resizing to do</param>
        /// <param name="cropAnchor">If cropping is necessary, at what </param>
        /// <returns>The resized images</returns>
        /// <seealso cref="ImageResizingEstimator"/>
        public static Custom <Bitmap> Resize(this Custom <Bitmap> input, int width, int height,
                                             ImageResizingEstimator.ResizingKind resizing = ImageResizingEstimator.ResizingKind.IsoCrop,
                                             ImageResizingEstimator.Anchor cropAnchor     = ImageResizingEstimator.Anchor.Center)
        {
            Contracts.CheckValue(input, nameof(input));
            Contracts.CheckParam(width > 0, nameof(width), "Must be positive");
            Contracts.CheckParam(height > 0, nameof(height), "Must be positive");
            Contracts.CheckParam(Enum.IsDefined(typeof(ImageResizingEstimator.ResizingKind), resizing), nameof(resizing), "Undefined value detected");
            Contracts.CheckParam(Enum.IsDefined(typeof(ImageResizingEstimator.Anchor), cropAnchor), nameof(cropAnchor), "Undefined value detected");

            return(new ImageResizingStaticExtensions.OutPipelineColumn(input, width, height, resizing, cropAnchor));
        }