LEADTOOLS(Leadtoolsアセンブリ)

フレームを表示

CreateMaskFromRegionメソッド








imageで定義されるリージョンから、1-ビットマスク画像を作成します。
構文
public RasterImage CreateMaskFromRegion()
'Declaration
 
Public Function CreateMaskFromRegion() As RasterImage
'Usage
 
Dim instance As RasterImage
Dim value As RasterImage
 
value = instance.CreateMaskFromRegion()
public RasterImage CreateMaskFromRegion()
- (nullable LTRasterImage *)createMaskFromRegion:(NSError **)error
public RasterImage createMaskFromRegion()
 function Leadtools.RasterImage.CreateMaskFromRegion()
public:
RasterImage^ CreateMaskFromRegion(); 

戻り値

1ビット、白黒のimage(リージョンからのピクセルは白いです)とすべての他で更新される新しく作成されたRasterImageは、黒いです。
解説

詳細については、「透明度の実装」を参照してください。

詳細については、「リージョンの作成」を参照してください。

詳細については、「リージョンの保存」を参照してください。

詳細については、「既存のリージョンの操作」を参照してください。

サンプル

このサンプルはimageをロードして、黒を使用してカラーリージョンを設定して、そして、そのimageから1-ビットマスク画像を作成して、ディスクにそれを保存します。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Controls
Imports Leadtools.Dicom
Imports Leadtools.Drawing
Imports Leadtools.Svg

      
Public Sub CreateMaskFromRegionExample()
   Dim codecs As RasterCodecs = New RasterCodecs()
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
   Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_CreateMaskFromRegion.bmp")

   ' Load the image
   Dim image As RasterImage = codecs.Load(srcFileName)

   ' Posterize the image to decrease the number of colors
   Dim posterize As PosterizeCommand = New PosterizeCommand(16)
   posterize.Run(image)

   ' Specify a pixel in the upper left of the displayed image
   Dim pt As LeadPoint = New LeadPoint(image.ImageWidth \ 8, image.ImageHeight \ 8)

   ' Adjust the point in case the view perspective is not TopLeft
   pt = image.PointToImage(RasterViewPerspective.TopLeft, pt)

   ' Get the color of the specified pixel
   Dim regionColor As RasterColor = image.GetPixelColor(pt.Y, pt.X)

   ' Create a region that includes all pixels of that color
   image.AddColorToRegion(regionColor, RasterRegionCombineMode.Set)

   Dim maskImage As RasterImage = image.CreateMaskFromRegion()

   codecs.Save(maskImage, destFileName, RasterImageFormat.Bmp, 1)

   maskImage.Dispose()
   image.Dispose()
   codecs.Dispose()
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;
using Leadtools.Drawing;
using Leadtools.Controls;
using Leadtools.Svg;

      
public void CreateMaskFromRegionExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");
   string destFileName = Path.Combine(ImagesPath.Path, "Image1_CreateMaskFromRegion.bmp");

   // Load the image
   RasterImage image = codecs.Load(srcFileName);

   // Posterize the image to decrease the number of colors
   PosterizeCommand posterize = new PosterizeCommand(16);
   posterize.Run(image);

   // Specify a pixel in the upper left of the displayed image
   LeadPoint pt = new LeadPoint(image.ImageWidth / 8, image.ImageHeight / 8);

   // Adjust the point in case the view perspective is not TopLeft
   pt = image.PointToImage(RasterViewPerspective.TopLeft, pt);

   // Get the color of the specified pixel
   RasterColor regionColor = image.GetPixelColor(pt.Y, pt.X);

   // Create a region that includes all pixels of that color
   image.AddColorToRegion(regionColor, RasterRegionCombineMode.Set);

   RasterImage maskImage = image.CreateMaskFromRegion();

   codecs.Save(maskImage, destFileName, RasterImageFormat.Bmp, 1);

   maskImage.Dispose();
   image.Dispose();
   codecs.Dispose();
}
RasterImageExamples.prototype.CreateMaskFromRegionExample = function ( )
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();

         var srcFileName = "Assets\\Image1.cmp";
         var destFileName = "Image1_CreateMaskFromRegion.bmp";
         var image;
         var maskImage;
         // Load the image
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
               .then(function (img) {
                  image = img;

                  // Posterize the image to decrease the number of colors
                  var posterize = new Leadtools.ImageProcessing.Color.PosterizeCommand(16);
                  posterize.run(image);

                  // Specify a pixel in the upper left of the displayed image
                  var pt = LeadPointHelper.create(image.imageWidth / 8, image.imageHeight / 8);

                  // Adjust the point in case the view perspective is not TopLeft
                  pt = image.pointToImage(RasterViewPerspective.topLeft, pt);

                  // Get the color of the specified pixel
                  var regionColor = image.getPixelColor(pt.Y, pt.X);

                  // Create a region that includes all pixels of that color
                  image.addColorToRegion(regionColor, RasterRegionCombineMode.set);

                  maskImage = image.createMaskFromRegion();

                  return Tools.AppLocalFolder().createFileAsync(destFileName)
               })
               .then(function (saveFile) {
                  var saveStream = LeadStreamFactory.create(saveFile);
                  return codecs.saveAsync(image, saveStream, RasterImageFormat.bmp, 24)
               })
               .then(function () {

                  maskImage.close();
                  image.close();
                  codecs.close();
               });
      }
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;

      
public async Task CreateMaskFromRegionExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Image1.cmp";
   string destFileName = @"Image1_CreateMaskFromRegion.bmp";

   // Load the image
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // Posterize the image to decrease the number of colors
   PosterizeCommand posterize = new PosterizeCommand(16);
   posterize.Run(image);

   // Specify a pixel in the upper left of the displayed image
   LeadPoint pt = LeadPointHelper.Create(image.ImageWidth / 8, image.ImageHeight / 8);

   // Adjust the point in case the view perspective is not TopLeft
   pt = image.PointToImage(RasterViewPerspective.TopLeft, pt);

   // Get the color of the specified pixel
   RasterColor regionColor = image.GetPixelColor(pt.Y, pt.X);

   // Create a region that includes all pixels of that color
   image.AddColorToRegion(regionColor, RasterRegionCombineMode.Set);

   RasterImage maskImage = image.CreateMaskFromRegion();

   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
   await codecs.SaveAsync(image, saveStream, RasterImageFormat.Bmp, 24);

   maskImage.Dispose();
   image.Dispose();
   codecs.Dispose();
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Dicom;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Examples;
using Leadtools.Windows.Media;

public void CreateMaskFromRegionExample(RasterImage image, Stream destStream)
{
   // Posterize the image to decrease the number of colors
   PosterizeCommand posterize = new PosterizeCommand(16);
   posterize.Run(image);
   // Specify a pixel in the upper left of the displayed image
   LeadPoint pt = new LeadPoint(image.ImageWidth / 8, image.ImageHeight / 8);

   // Adjust the point in case the view perspective is not TopLeft
   pt = image.PointToImage(RasterViewPerspective.TopLeft, pt);

   // Get the color of the specified pixel
   RasterColor regionColor = image.GetPixelColor(pt.Y, pt.X);

   // Create a region that includes all pixels of that color
   image.AddColorToRegion(regionColor, RasterRegionCombineMode.Set);

   RasterImage maskImage = image.CreateMaskFromRegion();

   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(maskImage, destStream, RasterImageFormat.Png, 0);

   maskImage.Dispose();
   image.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Dicom
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Windows.Media

Public Sub CreateMaskFromRegionExample(ByVal image As RasterImage, ByVal destStream As Stream)
   ' Posterize the image to decrease the number of colors
   Dim posterize As PosterizeCommand = New PosterizeCommand(16)
   posterize.Run(image)
   ' Specify a pixel in the upper left of the displayed image
   Dim pt As LeadPoint = New LeadPoint(image.ImageWidth / 8, image.ImageHeight / 8)

   ' Adjust the point in case the view perspective is not TopLeft
   pt = image.PointToImage(RasterViewPerspective.TopLeft, pt)

   ' Get the color of the specified pixel
   Dim regionColor As RasterColor = image.GetPixelColor(pt.Y, pt.X)

   ' Create a region that includes all pixels of that color
   image.AddColorToRegion(regionColor, RasterRegionCombineMode.Set)

   Dim maskImage As RasterImage = image.CreateMaskFromRegion()

   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(maskImage, destStream, RasterImageFormat.Png, 0)

   maskImage.Dispose()
   image.Dispose()
End Sub
必要条件

ターゲットプラットホーム

参照

参照

RasterImageクラス
RasterImageメンバ