public void AddColorHsvRangeToRegion(
RasterHsvColor lowerColor,
RasterHsvColor upperColor,
RasterRegionCombineMode combineMode
)
- (BOOL)addColorHsvRangeToRegion:(LTRasterHsvColor *)lowerColor
upperColor:(LTRasterHsvColor*)upperColor
combineMode:(LTRasterRegionCombineMode)combineMode
error:(NSError **)error
public void addColorHsvRangeToRegion(
RasterHsvColor lowerColor,
RasterHsvColor upperColor,
RasterRegionCombineMode combineMode
)
public:
void AddColorHsvRangeToRegion(
RasterHsvColor lowerColor,
RasterHsvColor upperColor,
RasterRegionCombineMode combineMode
)
def AddColorHsvRangeToRegion(self,lowerColor,upperColor,combineMode):
lowerColor
Specifies the minimum (inclusive) R, G and B values. A pixel must have H,S, and V all greater than or equal to lowerColor and less than or equal to upperColor to be included in the region.
upperColor
Specifies the maximum (inclusive) R, G and B values. A pixel must have H,S, and V all greater than or equal to lowerColor and less than or equal to upperColor to be included in the region.
combineMode
The action to take regarding the existing image region, if one is defined.
This method uses the HSV color model to set a region based on a color range.
It is useful for identifying all shades of a certain color. For example, this method could be used to set a region of all green colors including:
RGB(0,1,0) | ||
RGB(0,2,0) | RGB(1,2,1) | |
RGB(0,1,0) | - | |
RGB(0,3,0) | RGB(1,3,1) | RGB(2,3,2) |
RGB(0,255,0) | RGB(1,255,1) | RGB(2,255,2) |
The diagram below shows how S and V affect the color green (H = 85):
To be added to the region a color must fall in the range lowerColor... upperColor. If you want to set a region for all red (and colors near red), you could specify lowerColor and upperColor as follows:
lowerColor (250,1,1) upperColor (5,255,255)
The hue for the lowerColor is 250 and the hue for the upperColor is 5. For the hue to fall in this range it must be 250, 251, 252, 253, 254, 255, 1, 2, 3, 4, or 5. Note that the values for hue wrap from 255 to 1.
This method supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available only in the Document/Medical Imaging editions.
This method does not support signed data images.
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.
This example will load an image, adds a region corresponding to all pure green (Hue = 85) and colors near green (+/- 10), run the InvertCommand to show the affected area before saving the image back 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 AddColorHsvRangeToRegionExample()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_AddColorHsvRangeToRegion.bmp");
// Load the image
RasterImage image = codecs.Load(srcFileName);
// Add the region
RasterHsvColor lowerColor = new RasterHsvColor(75, 40, 40);
RasterHsvColor upperColor = new RasterHsvColor(95, 255, 255);
image.AddColorHsvRangeToRegion(lowerColor, upperColor, RasterRegionCombineMode.Set);
// Draw something on the image
InvertCommand command = new InvertCommand();
command.Run(image);
// Save the image
codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24);
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 addColorHsvRangeToRegionExample() {
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_AddColorHsvRangeToRegion.bmp");
// Load the image
RasterImage image = codecs.load(srcFileName);
// Add the region
RasterHsvColor lowerColor = new RasterHsvColor(75, 40, 40, 0);
RasterHsvColor upperColor = new RasterHsvColor(95, 255, 255, 0);
image.addColorHsvRangeToRegion(lowerColor, upperColor, RasterRegionCombineMode.SET);
// Draw something on the image
InvertCommand command = new InvertCommand();
command.run(image);
// Save the image
codecs.save(image, destFileName, RasterImageFormat.BMP, 24);
// Clean up
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