←Select platform

GrayScaleToMultitoneCommand Class

Summary
Converts a grayscale image into a colored one by mixing or replacing the original values of the pixels with one or more new colors. This class is available in the Imaging and above toolkits.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public class GrayScaleToMultitoneCommand : RasterCommand 
@interface LTGrayscaleToMultitoneCommand : LTRasterCommand 
public class GrayScaleToMultitoneCommand 
    extends RasterCommand 
public ref class GrayScaleToMultitoneCommand : public RasterCommand   
class GrayScaleToMultitoneCommand(RasterCommand): 
Remarks
  • This class was designed for use with grayscale images. If the image being used is not grayscale, this class only affects those pixels or areas of the image where Red = Green = Blue.
  • Monotone conversion is possible by setting Type to Replace, which clears the palette.
  • This class gives you the option of having the toolkit generate the array of colors to use or creating the array of colors to use yourself.
  • To have the toolkit generate the array of colors:

    • If the image is binary, call GrayScaleToMultitoneCommand with Tone set to GrayScaleToMultitoneCommandToneType.MonoTone, Distribution set to GrayScaleToMultitoneCommandDistributionType.Linear and the color you wish to use set in Color. The GrayscaleMode property will be set by GrayScaleToDuotoneCommand class object to determine the kind of grayscale palette being used. If the GrayscaleMode property is GrayscaleMode.OrderedInverse or GrayscaleMode.NotOrdered, then the color set in the Color property for the GrayScaleToMultitoneCommand class object will become the first color in the array generated by the toolkit, and the toolkit will create the second color in the array. The Color array will be updated with these two colors. If the GrayscaleMode property is a value other than GrayscaleMode.OrderedInverse or GrayscaleMode.NotOrdered, then the color set in the Color property for the GrayScaleToMultitoneCommand class object will become the second color in the array generated by the toolkit, and the toolkit will create the first color in the array. The Color property will be updated with these two colors.
    • If the image is grayscale (not binary) call the GrayScaleToMultitoneCommand with Distribution set to GrayScaleToMultitoneCommandDistributionType.Linear. The GrayScaleToMultitoneCommand will take the color(s) set in the Color property and generate a 256 color gradient for each color.

      1. If the Tone is set to GrayScaleToMultitoneCommandToneType.Duotone, set two colors in the Color property. The toolkit will create a 256 color array for each color.
      2. If the Tone is set to GrayScaleToMultitoneCommandToneType.Tritone, set three colors in the Color property. The toolkit will create a 256 color array for each color.
      3. If the Tone is set to GrayScaleToMultitoneCommandToneType.Quadtone, set four colors in the Color property. The toolkit will create a 256 color array for each color.
    • If the image is not grayscale (it is color) call the GrayScaleToMultitoneCommand with Distribution set to GrayScaleToMultitoneCommandDistributionType.Linear. The GrayScaleToMultitoneCommand will take the color(s) set in the Color property and generate a 256 color gradient for each color. These colors will be used to change only those pixels in the color image for which Red = Green = Blue.

  • To use a user-defined array of colors:

  • This class 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 toolkits.
  • This class does not support signed data images.
  • This command does not support 32-bit grayscale images.

For more information, refer to Introduction to Image Processing With LEADTOOLS. For more information, refer to Grayscale Images.

Gray Scale to Multitone Function - Before

Gray Scale to Multitone Function - Before

Gray Scale to Multitone Function - After

Gray Scale to Multitone Function - After

View additional platform support for this Gray Scale to Multitone function.

Example

Run the GrayScaleToMultitoneCommand on an image.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing.Color; 
 
 
public void GrayScaleToMultitoneCommandExample() 
{ 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, @"ImageProcessingDemo\Beauty16.jpg")); 
 
   // Prepare the command 
   GrayScaleToMultitoneCommand command = new GrayScaleToMultitoneCommand(); 
   command.Colors = new RasterColor[2]; 
   command.Colors[0].R = 255; 
   command.Colors[0].G = 255; 
   command.Colors[0].B = 0; 
   command.Colors[1].R = 255; 
   command.Colors[1].G = 0; 
   command.Colors[1].B = 0; 
   command.Gradient = null; 
   command.Distribution = GrayScaleToMultitoneCommandDistributionType.Linear; 
   command.Tone = GrayScaleToMultitoneCommandToneType.Duotone; 
   command.Type = GrayScaleToDuotoneCommandMixingType.ReplaceOldWithNew; 
   command.Run(image); 
   codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24); 
 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.assertTrue; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.color.*; 
 
 
public void grayScaleToMultitoneCommandExample() { 
 
    final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
 
    // Load an image 
    RasterCodecs codecs = new RasterCodecs(); 
    codecs.setThrowExceptionsOnInvalidImages(true); 
 
    RasterImage image = codecs.load(combine(LEAD_VARS_IMAGES_DIR, "Beauty16.jpg")); 
 
    // Prepare the command 
    GrayScaleToMultitoneCommand command = new GrayScaleToMultitoneCommand(); 
 
    command.setColors(new RasterColor[2]); 
    RasterColor[] colors = command.getColors(); 
    for (int i = 0; i < colors.length; i++) { 
        colors[i] = new RasterColor(); 
    } 
 
    command.getColors()[0].r(255); 
    command.getColors()[0].g(255); 
    command.getColors()[0].b(0); 
    command.getColors()[1].r(255); 
    command.getColors()[1].g(0); 
    command.getColors()[1].b(0); 
    command.setGradient(null); 
    command.setDistribution(GrayScaleToMultitoneCommandDistributionType.LINEAR); 
    command.setTone(GrayScaleToMultitoneCommandToneType.DUOTONE); 
    command.setType(GrayScaleToDuotoneCommandMixingType.REPLACE_OLD_WITH_NEW); 
 
    command.run(image); 
    codecs.save(image, combine(LEAD_VARS_IMAGES_DIR, "Result.jpg"), RasterImageFormat.JPEG, 24); 
 
    System.out.println("Command run and image saved to " + combine(LEAD_VARS_IMAGES_DIR, "Result.jpg")); 
    assertTrue(new File(combine(LEAD_VARS_IMAGES_DIR, "Result.jpg")).exists()); 
 
} 
Requirements

Target Platforms

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

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