ImageEstimatorsCatalog.ResizeImages 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
ImageResizingEstimator에 지정된 inputColumnName
열에서 새 outputColumnName
열로 이미지 크기를 조정하는 를 만듭니다.
public static Microsoft.ML.Transforms.Image.ImageResizingEstimator ResizeImages (this Microsoft.ML.TransformsCatalog catalog, string outputColumnName, int imageWidth, int imageHeight, string inputColumnName = default, Microsoft.ML.Transforms.Image.ImageResizingEstimator.ResizingKind resizing = Microsoft.ML.Transforms.Image.ImageResizingEstimator+ResizingKind.IsoCrop, Microsoft.ML.Transforms.Image.ImageResizingEstimator.Anchor cropAnchor = Microsoft.ML.Transforms.Image.ImageResizingEstimator+Anchor.Center);
static member ResizeImages : Microsoft.ML.TransformsCatalog * string * int * int * string * Microsoft.ML.Transforms.Image.ImageResizingEstimator.ResizingKind * Microsoft.ML.Transforms.Image.ImageResizingEstimator.Anchor -> Microsoft.ML.Transforms.Image.ImageResizingEstimator
<Extension()>
Public Function ResizeImages (catalog As TransformsCatalog, outputColumnName As String, imageWidth As Integer, imageHeight As Integer, Optional inputColumnName As String = Nothing, Optional resizing As ImageResizingEstimator.ResizingKind = Microsoft.ML.Transforms.Image.ImageResizingEstimator+ResizingKind.IsoCrop, Optional cropAnchor As ImageResizingEstimator.Anchor = Microsoft.ML.Transforms.Image.ImageResizingEstimator+Anchor.Center) As ImageResizingEstimator
매개 변수
- catalog
- TransformsCatalog
변환의 카탈로그입니다.
- outputColumnName
- String
의 변환에서 생성된 열의 이름입니다 inputColumnName
.
이 열의 데이터 형식은 입력 열의 데이터 형식과 동일합니다.
- imageWidth
- Int32
변환된 이미지 너비입니다.
- imageHeight
- Int32
변환된 이미지 높이입니다.
- resizing
- ImageResizingEstimator.ResizingKind
에 지정된 대로 이미지 크기 조정의 형식입니다 ImageResizingEstimator.ResizingKind.
- cropAnchor
- ImageResizingEstimator.Anchor
앵커를 배치하여 자르기를 시작할 위치입니다. 에 정의된 옵션 ImageResizingEstimator.Anchor
반환
예제
using System;
using System.IO;
using Microsoft.ML;
using Microsoft.ML.Data;
namespace Samples.Dynamic
{
public static class ResizeImages
{
// Example on how to load the images from the file system, and resize them.
public static void Example()
{
// Create a new ML context, for ML.NET operations. It can be used for
// exception tracking and logging, as well as the source of randomness.
var mlContext = new MLContext();
// Downloading a few images, and an images.tsv file, which contains a
// list of the files from the dotnet/machinelearning/test/data/images/.
// If you inspect the fileSystem, after running this line, an "images"
// folder will be created, containing 4 images, and a .tsv file
// enumerating the images.
var imagesDataFile = Microsoft.ML.SamplesUtils.DatasetUtils
.GetSampleImages();
// Preview of the content of the images.tsv file
//
// imagePath imageType
// tomato.bmp tomato
// banana.jpg banana
// hotdog.jpg hotdog
// tomato.jpg tomato
var data = mlContext.Data.CreateTextLoader(new TextLoader.Options()
{
Columns = new[]
{
new TextLoader.Column("ImagePath", DataKind.String, 0),
new TextLoader.Column("Name", DataKind.String, 1),
}
}).Load(imagesDataFile);
var imagesFolder = Path.GetDirectoryName(imagesDataFile);
// Image loading pipeline.
var pipeline = mlContext.Transforms.LoadImages("ImageObject",
imagesFolder, "ImagePath")
.Append(mlContext.Transforms.ResizeImages("ImageObjectResized",
inputColumnName: "ImageObject", imageWidth: 100, imageHeight: 100));
var transformedData = pipeline.Fit(data).Transform(data);
// The transformedData IDataView contains the resized images now.
// Preview the transformedData.
PrintColumns(transformedData);
// ImagePath Name ImageObject ImageObjectResized
// tomato.bmp tomato {Width=800, Height=534} {Width=100, Height=100}
// banana.jpg banana {Width=800, Height=288} {Width=100, Height=100}
// hotdog.jpg hotdog {Width=800, Height=391} {Width=100, Height=100}
// tomato.jpg tomato {Width=800, Height=534} {Width=100, Height=100}
}
private static void PrintColumns(IDataView transformedData)
{
Console.WriteLine("{0, -25} {1, -25} {2, -25} {3, -25}", "ImagePath",
"Name", "ImageObject", "ImageObjectResized");
using (var cursor = transformedData.GetRowCursor(transformedData
.Schema))
{
// Note that it is best to get the getters and values *before*
// iteration, so as to facilitate buffer sharing (if applicable), and
// column -type validation once, rather than many times.
ReadOnlyMemory<char> imagePath = default;
ReadOnlyMemory<char> name = default;
MLImage imageObject = null;
MLImage resizedImageObject = null;
var imagePathGetter = cursor.GetGetter<ReadOnlyMemory<char>>(cursor
.Schema["ImagePath"]);
var nameGetter = cursor.GetGetter<ReadOnlyMemory<char>>(cursor
.Schema["Name"]);
var imageObjectGetter = cursor.GetGetter<MLImage>(cursor.Schema[
"ImageObject"]);
var resizedImageGetter = cursor.GetGetter<MLImage>(cursor.Schema[
"ImageObjectResized"]);
while (cursor.MoveNext())
{
imagePathGetter(ref imagePath);
nameGetter(ref name);
imageObjectGetter(ref imageObject);
resizedImageGetter(ref resizedImageObject);
Console.WriteLine("{0, -25} {1, -25} {2, -25} {3, -25}",
imagePath, name,
$"Width={imageObject.Width}, Height={imageObject.Height}",
$"Width={resizedImageObject.Width}, Height={resizedImageObject.Height}");
}
// Dispose the image.
imageObject.Dispose();
resizedImageObject.Dispose();
}
}
}
}