public void SegmentImage(
RasterImage image,
MrcSegmentImageOptions options
)
image
The image that will be segmented.
options
structure that controls the automatic segmentation process.
This method is available only in the Document/Medical Toolkits. Call this method to segment the image automatically. LEAD will process the image and break it into appropriate picture, grayscale, text and background segments. For more information, refer to Programming with LEADTOOLS MRC.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Mrc;
private bool MrcEnumerateSegmentInfoCallback(MrcSegmenter segmentHandle, MrcSegmentData data, int iD)
{
if (iD == 0)
{
MessageBox.Show("Segment ID : " + iD.ToString());
MessageBox.Show("Left : " + data.ImageSegment.Left.ToString() +
"\nTop : " + data.ImageSegment.Top.ToString() +
"\nRight : " + data.ImageSegment.Right.ToString() +
"\nBottom : " + data.ImageSegment.Bottom.ToString());
}
return true;
}
public void MrcSegmenterExample()
{
// Load an image
RasterCodecs codecs = new RasterCodecs();
codecs.ThrowExceptionsOnInvalidImages = true;
RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "PDFSegmentation.pdf"));
MrcSegmentImageOptions segmentImageOptions = MrcSegmentImageOptions.Empty;
segmentImageOptions.CleanSize = 5;
segmentImageOptions.SegmentQuality = 50;
segmentImageOptions.ColorThreshold = 25;
segmentImageOptions.BackgroundThreshold = 10;
segmentImageOptions.CombineThreshold = 75;
segmentImageOptions.Flags = MrcSegmentImageFlags.FavorOneBit | MrcSegmentImageFlags.SegmentWithBackground;
MrcSegmenter segmenter = new MrcSegmenter(image, RasterColor.FromKnownColor(RasterKnownColor.White), RasterColor.FromKnownColor(RasterKnownColor.Black));
segmenter.SegmentImage(image, segmentImageOptions);
MrcEnumerateSegmentsInfo callBack = new MrcEnumerateSegmentsInfo(MrcEnumerateSegmentInfoCallback);
segmenter.EnumerateSegments(callBack);
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}