CreateMaskFromRegion Method (original) (raw)

Summary

Creates a 1-bit mask image from the region that is defined in the image.

Syntax

C#

Objective-C

C++/CLI

Java

Python

- (nullable LTRasterImage *)createMaskFromRegion:(NSError **)error 
def CreateMaskFromRegion(self): 

Return Value

The newly created RasterImage which will be updated with a 1-bit, black-and-white image, where pixels from the region are white, and all others are black.

Example

This example will load an image, sets a color region using black, and then creates a 1-bit mask image from that image and saves it to disk.

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(LEAD_VARS.ImagesDir, "Image1.cmp"); string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "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(); } static class LEAD_VARS { public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; }

Leadtools Assembly

Convert(byte[],int,int,int,int,RasterByteOrder,RasterByteOrder,RasterColor[],RasterColor[],int,int,int,RasterConvertBufferFlags) Method

Convert(byte[],int,int,int,int,RasterByteOrder,RasterByteOrder,RasterColor[],RasterColor[],RasterColor16[],RasterColor16[],int,int,int,RasterConvertBufferFlags) Method

Convert(IntPtr,int,int,int,RasterByteOrder,RasterByteOrder,RasterColor[],RasterColor[],int,int,int,RasterConvertBufferFlags) Method

Convert(IntPtr,int,int,int,RasterByteOrder,RasterByteOrder,RasterColor[],RasterColor[],RasterColor16[],RasterColor16[],int,int,int,RasterConvertBufferFlags) Method