←Select platform

AddColorRgbRangeToRegion Method

Summary
Creates or updates the image region by adding a region that consists of all the pixels that fall in the given RGB color range.
Syntax
C#
Objective-C
C++/CLI
Java
Python
- (BOOL)addColorRgbRangeToRegion:(LTRasterColor *)lowerColor  
                      upperColor:(LTRasterColor *)upperColor  
                     combineMode:(LTRasterRegionCombineMode)combineMode  
                           error:(NSError **)error 
public void addColorRgbRangeToRegion( 
  RasterColor lowerColor,  
  RasterColor upperColor,  
  RasterRegionCombineMode combineMode 
) 
def AddColorRgbRangeToRegion(self,lowerColor,upperColor,combineMode): 

Parameters

lowerColor
Specifies the minimum (inclusive) R, G and B values. A pixel must have R,G, and B 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 R,G, and B 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.

Remarks

This method uses the RGB color model to set a region based on a color range.

To be added to the region a color must fall in the range  lowerColor.. upperColor. To set a region for all pure red, specify  lowerColor and  upperColor as follows:

lowerColor RGB(1,0,0) upperColor RGB(255,0,0)

Note that this would fail to include many colors that look red to the eye (like RGB(255,4,4)).

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 supports signed/unsigned data images.

The AddColorRgbRangeToRegion function can use the Extended Grayscale mask. For more information, refer to Grayscale 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.

In the Document and Medical toolkits, the COLORREF value can represent a 16 bit grayscale value if RasterImage is a 12 or 16-bit grayscale bitmap. To avoid confusion with an RGB value, set the COLORREF_GRAY16 mask (0x04000000). In this case (0x0400YYYY), the lower 16 bits (0xYYYY) of the COLORREF value represent the 16-bit grayscale value. (0x0400FFFF is 16-bit white and 0x04000000 is 16-bit black.) This is not a standard Windows value. Therefore, although LEADTOOLS methods will recognize a COLORREF having this format, but Windows methods will not.

Example

This example will load an image, add a region corresponding to all colors that have an RGB that includes green but no red and no blue, and run the InvertCommand to show the affected area before saving the image back to disk.

C#
Java
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 AddColorRgbRangeToRegionExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_AddColorRgbRangeToRegion.bmp"); 
 
   // Load the image 
   RasterImage image = codecs.Load(srcFileName); 
 
   // Add the region 
   RasterColor lowerColor = new RasterColor(0, 1, 0); 
   RasterColor upperColor = new RasterColor(0, 255, 0); 
 
   image.AddColorRgbRangeToRegion(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 addColorRgbRangeToRegionExample() { 
   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_AddColorRgbRangeToRegion.bmp"); 
 
   // Load the image 
   RasterImage image = codecs.load(srcFileName); 
 
   // Add the region 
   RasterColor lowerColor = new RasterColor(0, 1, 0); 
   RasterColor upperColor = new RasterColor(0, 255, 0); 
 
   image.addColorRgbRangeToRegion(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); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.5.22
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.