LEADTOOLS (Leadtools assembly)

AddColorHsvRangeToRegion Method

Show in webframe
Example 







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.
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.
The action to take regarding the existing image region, if one is defined.
Creates or updates the image region by adding a region that consists of all the pixels that fall in the given HSV color range.
Syntax
public void AddColorHsvRangeToRegion( 
   RasterHsvColor lowerColor,
   RasterHsvColor upperColor,
   RasterRegionCombineMode combineMode
)
'Declaration
 
Public Sub AddColorHsvRangeToRegion( _
   ByVal lowerColor As RasterHsvColor, _
   ByVal upperColor As RasterHsvColor, _
   ByVal combineMode As RasterRegionCombineMode _
) 
'Usage
 
Dim instance As RasterImage
Dim lowerColor As RasterHsvColor
Dim upperColor As RasterHsvColor
Dim combineMode As RasterRegionCombineMode
 
instance.AddColorHsvRangeToRegion(lowerColor, upperColor, combineMode)
public void AddColorHsvRangeToRegion( 
   RasterHsvColor lowerColor,
   RasterHsvColor upperColor,
   RasterRegionCombineMode combineMode
)
-(BOOL)addColorHsvRangeToRegion:(LTRasterHsvColor*)lowerColor 
                     upperColor:(LTRasterHsvColor*)upperColor 
                    combineMode:(LTRasterRegionCombineMode)combineMode 
                          error:(NSError**)outError;
            
public void addColorHsvRangeToRegion(
  RasterHsvColor lowerColor, 
  RasterHsvColor upperColor, 
  RasterRegionCombineMode combineMode
)
            
 function Leadtools.RasterImage.AddColorHsvRangeToRegion( 
   lowerColor ,
   upperColor ,
   combineMode 
)
public:
void AddColorHsvRangeToRegion( 
   RasterHsvColor lowerColor,
   RasterHsvColor upperColor,
   RasterRegionCombineMode combineMode
) 

Parameters

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.
Remarks

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.

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.WinForms
Imports Leadtools.Dicom
Imports Leadtools.Drawing

Public Sub AddColorHsvRangeToRegionExample()
   Dim codecs As RasterCodecs = New RasterCodecs()

   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
   Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_AddColorHsvRangeToRegion.bmp")

   ' Load the image
   Dim image As RasterImage = codecs.Load(srcFileName)

   ' Add the region
   Dim lowerColor As RasterHsvColor = New RasterHsvColor(75, 40, 40)
   Dim upperColor As RasterHsvColor = New RasterHsvColor(95, 255, 255)

   image.AddColorHsvRangeToRegion(lowerColor, upperColor, RasterRegionCombineMode.Set)

   ' Draw something on the image
   Dim command As InvertCommand = New InvertCommand()
   command.Run(image)

   ' Save the image
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24)

   image.Dispose()
   codecs.Dispose()
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.WinForms;
using Leadtools.Dicom;
using Leadtools.Drawing;

      
public void AddColorHsvRangeToRegionExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");
   string destFileName = Path.Combine(ImagesPath.Path, "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();
}
RasterImageExamples.prototype.AddColorHsvRangeToRegionExample = function ( )
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();

         var srcFileName = "Assets\\Image1.cmp";
         var destFileName = "Image1_AddColorHsvRangeToRegion.bmp";
         var image;

         // Load the image
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
            .then(function (img) {
               image = img;

               // Add the region
               var lowerColor = RasterHsvColorHelper.create(75, 40, 40);
               var upperColor = RasterHsvColorHelper.create(95, 255, 255);

               image.addColorHsvRangeToRegion(lowerColor, upperColor, RasterRegionCombineMode.set);

               // Draw something on the image
               var command = new Leadtools.ImageProcessing.Color.InvertCommand();

               command.run(image);

               // Save the image
               return Tools.AppLocalFolder().createFileAsync(destFileName)
            })
            .then(function (saveFile) {
               var saveStream = LeadStreamFactory.create(saveFile);
               return codecs.saveAsync(image, saveStream, RasterImageFormat.bmp, 24)
            })
            .then(function () {

               image.close();
               codecs.close();
            });
      }
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;

      
public async Task AddColorHsvRangeToRegionExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Image1.cmp";
   string destFileName = @"Image1_AddColorHsvRangeToRegion.bmp";

   // Load the image
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // Add the region
   RasterHsvColor lowerColor = RasterHsvColorHelper.Create(75, 40, 40);
   RasterHsvColor upperColor = RasterHsvColorHelper.Create(95, 255, 255);

   image.AddColorHsvRangeToRegion(lowerColor, upperColor, RasterRegionCombineMode.Set);

   // Draw something on the image
   InvertCommand command = new InvertCommand();
   command.Run(image);

   // Save the image
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
   await codecs.SaveAsync(image, saveStream, RasterImageFormat.Bmp, 24);

   image.Dispose();
   codecs.Dispose();
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Dicom;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Examples;
using Leadtools.Windows.Media;

public void AddColorHsvRangeToRegionExample(RasterImage image, Stream destStream)
{
   // 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
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, destStream, RasterImageFormat.Png, 24);

   image.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Dicom
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Windows.Media

Public Sub AddColorHsvRangeToRegionExample(ByVal image As RasterImage, ByVal destStream As Stream)
   ' Add the region
   Dim lowerColor As RasterHsvColor = New RasterHsvColor(75, 40, 40)
   Dim upperColor As RasterHsvColor = New RasterHsvColor(95, 255, 255)
   image.AddColorHsvRangeToRegion(lowerColor, upperColor, RasterRegionCombineMode.Set)

   ' Draw something on the image
   Dim command As InvertCommand = New InvertCommand()
   command.Run(image)

   ' Save the image
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, destStream, RasterImageFormat.Png, 24)

   image.Dispose()
End Sub
Requirements

Target Platforms

See Also

Reference

RasterImage Class
RasterImage Members
Gray Scale Images
Introduction: Bits Per Pixel and Related Ideas
Using Color Values in LEADTOOLS

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.