public void AddMaskToRegion(
RasterRegionXForm xform,
RasterImage maskImage,
RasterRegionCombineMode combineMode
)
- (BOOL)addMaskToRegion:(nullable LTRasterRegionXForm *)xform
maskImage:(LTRasterImage *)mask
combineMode:(LTRasterRegionCombineMode)combineMode
error:(NSError **)error
public void addMaskToRegion(
RasterRegionXForm xform,
RasterImage maskImage,
RasterRegionCombineMode combineMode
)
public:
void AddMaskToRegion(
RasterRegionXForm^ xform,
RasterImage^ maskImage,
RasterRegionCombineMode combineMode
)
def AddMaskToRegion(self,xform,maskImage,combineMode):
xform
RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates.
maskImage
The 1-bit black-and-white RasterImage used as a mask.
combineMode
The action to take regarding the existing image region, if one is defined.
To update an existing region, you specify how the new region is to be combined with the existing one using the combineMode parameter. For more information, refer to RasterRegionCombineMode.
For more information, refer to Creating a Region.
For more information, refer to Saving A Region.
For more information, refer to Working with the Existing Region.
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:\LEADTOOLS23\Resources\Images";
}
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;
import leadtools.*;
import leadtools.codecs.*;
import leadtools.imageprocessing.core.*;
import leadtools.svg.*;
import leadtools.imageprocessing.CloneCommand;
import leadtools.imageprocessing.FillCommand;
import leadtools.imageprocessing.FlipCommand;
import leadtools.imageprocessing.GrayscaleCommand;
import leadtools.imageprocessing.color.InvertCommand;
import leadtools.imageprocessing.color.PosterizeCommand;
public void createMaskFromRegionExample() {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
RasterCodecs codecs = new RasterCodecs();
String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.cmp");
String destFileName = combine(LEAD_VARS_IMAGES_DIR, "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);
assertTrue(posterize.getLevels() == 16);
// Specify a pixel in the upper left of the displayed image
LeadPoint pt = new LeadPoint(image.getImageWidth() / 8, image.getImageHeight() / 8);
// Adjust the point in case the view perspective is not TopLeft
pt = image.pointToImage(RasterViewPerspective.TOP_LEFT, pt);
// Get the color of the specified pixel
RasterColor regionColor = image.getPixelColor(pt.getY(), pt.getX());
// Create a region that includes all pixels of that color
image.addColorToRegion(regionColor, RasterRegionCombineMode.SET);
RasterImage maskImage = image.createMaskFromRegion();
// Save it
codecs.save(maskImage, destFileName, RasterImageFormat.BMP, 1);
// Clean up
maskImage.dispose();
image.dispose();
codecs.dispose();
assertTrue("file unsuccessfully saved to " + destFileName, (new File(destFileName)).exists());
System.out.printf("File saved successfully to %s%n", destFileName);
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document