←Select platform

CodecsJpeg2000Options Class

Summary

Provides extra options for loading and saving JPEG 2000 and LEAD CMW images.

Syntax
C#
Objective-C
C++/CLI
Java
Python
public class CodecsJpeg2000Options 
@interface LTCodecsJpeg2000Options : NSObject 
public class CodecsJpeg2000Options 
public ref class CodecsJpeg2000Options  
class CodecsJpeg2000Options: 

Remarks

The JPEG2000 image format offers both superior compression performance and robust file handling. Some J2K options can have a direct impact on compression performance, while others primarily affect resulting file size. Notes on Advanced options continue below.

Main options (listed above) include:

  • Color Transforms
  • Compression Settings
  • Multiple resolution representation (Wavelet Decomposition Level)
  • Random codestream access and processing (Progression Order)
  • Progressive transmission (Advanced)
  • Tile Size
  • Error resilience for transmission in noisy environments, such as wireless and the Internet.
  • Region-of-Interest coding.

LEAD CMW (Cmw) or TIFF with LEAD Wavelet CMW compression (TifCmw)

When using this structure with Cmw or TifCmw files, only the following data properties are required:

The resulting file size/ compression ratio can be determined in several ways. Depending on the value set in the CompressionControl property, the user can set the size of the target file, the actual compression ratio to use during compression or the quality factor to use during compression. If the CompressionControl property is set to Ratio, then the compression used is based on the compression ratio in the CompressionRatio property. If the CompressionControl property is set to TargetSize, the compression used is based on the desired target file size in the TargetFileSize property. If the CompressionControl property is set to QualityFactor, then the compression used is based on the QualityFactor passed to the Save functions.

Lossless Compression

For lossless compression, set the CompressionControl property to Lossless.

Lossy Compression Quantization

There are two types of quantization for Lossy compression: Scalar Derived Quantization and Scalar Expounded Quantization.

The exponent/mantissa pairs are either signaled in the codestream for every sub-band (expounded quantization) or else signaled only for the Low Pass sub-band and derived for all other sub-bands (derived quantization). In the case of derived quantization, all exponent/mantissa pairs are derived from the single exponent/mantissa pair corresponding to the Low pass sub-band.

The quantization step size for a sub-band is calculated from the dynamic range of the sub-band using the following equation, where R = bpp for the sub-band:

Quantization Step = (2 (R - Exponent) ) * [1 + (Mantissa / 2048)]

If the value of the CompressionControl property is Ratio, QualityFactor or TargetSize, and the value of the AlphaChannelLossless property is true, the compressed J2K/JP2 file will have three lossy components (red, green and blue), in addition to the lossless alpha component.

If the value of the CompressionControl property is Lossless, the value of AlphaChannelLossless will be ignored and all the components will be lossless.

The alpha channel can be dithered using ColorResolutionCommand and DynamicBinaryCommand externally, and before saving a J2K/JP2 file, in case a better alpha channel quality is desired.

Tile and Canvas Settings

The values of the ImageAreaHorizontalOffset, ImageAreaVerticalOffset, ReferenceTileHeight, ReferenceTileWidth, TileHorizontalOffset and TileVerticalOffset properties are used to create tiles within the image. Arbitrary tile sizes are allowed. All tiles are the same size, except for the border tiles. Each tile can be compressed individually. This can decrease memory usage while the program is running, but can also generate artifacts at the edges of the tiles. Artifacts generally increase as the size of the tile decreases. By default, there is one tile that contains the entire image.

The reference grid is a rectangular grid of points with the indices from (0, 0) to (Xsiz-1, Ysiz-1). An "image area" is defined on the reference grid by the dimensional parameters, (Xsiz, Ysiz) and (XOsiz, YOsiz). The various parameters defining the reference grid appear in the figures below.

Specifically, the image area on the reference grid is defined by its upper left hand reference grid point at location (XOsiz, YOsiz), and its lower right hand reference grid point at location (Xsiz-1, Ysiz-1).

j2kcanvas.gif
j2ktile.gif
Property Name Label In Diagram
ImageAreaHorizontalOffset XOsiz
ImageAreaVerticalOffset YOsiz
ReferenceTileHeight XTsiz
ReferenceTileWidth YTsiz
TileHorizontalOffset XTOsiz
TileVerticalOffset YTOsiz

Progression Order

For a given tile-part, the packets contain all compressed image data from a specific layer, a specific component, a specific resolution level, and a specific precinct. The order in which these packets are found in the codestream is called the progression order. Use the ProgressingOrder property to set the progression order. The ProgressingOrder property uses the CodecsJpeg2000ProgressionsOrder enumeration to specify the progression The ordering of the packets can progress along four axes: layer, component, resolution and position. The following progressions can be specified:

  1. LayerResolutionComponentPosition. A progression of this type might be useful when low sample accuracy is most desirable, but information is needed for all components.
  2. ResolutionLayerComponentPosition. A progression of this type might be useful in providing low-resolution level versions of all image components.
  3. ResolutionPositionComponentLayer. A progression of this type might be useful in providing low-resolution level versions of all image components at a particular spatial location.
  4. PositionComponentResolutionLayer. A progression of this type might be useful in providing high sample accuracy for a particular spatial location in all components.
  5. ComponentPositionResolutionLayer. A progression of this type might be useful in providing high accuracy for a particular spatial location in a particular image component.

Example

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.ImageProcessing.Core; 
using Leadtools.Pdf; 
 
public void CodecsJpeg2000OptionsExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.j2k"); 
 
   CodecsJpeg2000PrecinctSize[] precintSizes = (CodecsJpeg2000PrecinctSize[])Enum.GetValues(typeof(CodecsJpeg2000PrecinctSize)); 
   foreach (var precinctSize in precintSizes) 
   { 
      Console.WriteLine($"PrecinctSize types: {precinctSize}"); 
   } 
 
   //Setting the Jpeg2000 load options. CodecsJpeg2000Options & CodecsJpeg2000LoadOptions reference 
   codecs.Options.Jpeg2000.Load.J2kResolution = new LeadSize(800, 800); 
   codecs.Options.Jpeg2000.Load.Jp2Resolution = new LeadSize(800, 800); 
   codecs.Options.Jpeg2000.Load.CmwResolution = new LeadSize(0, 0); 
 
   //loading a Jpeg2000 image. 
   RasterImage srcImage = codecs.Load(srcFileName); 
 
   //Setting the Jpeg2000 save options. CodecsJpeg2000SaveOptions reference 
   codecs.Options.Jpeg2000.Save.AlphaChannelActiveBits = 16; 
   codecs.Options.Jpeg2000.Save.AlphaChannelLossless = false; 
   codecs.Options.Jpeg2000.Save.CompressionControl = CodecsJpeg2000CompressionControl.Ratio; 
   codecs.Options.Jpeg2000.Save.CompressionRatio = 15.0f; 
   codecs.Options.Jpeg2000.Save.DecompositionLevels = 5; 
   codecs.Options.Jpeg2000.Save.DerivedQuantization = true; 
   codecs.Options.Jpeg2000.Save.ImageAreaHorizontalOffset = 0; 
   codecs.Options.Jpeg2000.Save.ImageAreaVerticalOffset = 0; 
   codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.PositionComponentResolutionLayer; 
   codecs.Options.Jpeg2000.Save.PrecinctSize = CodecsJpeg2000PrecinctSize.HierarchicalOne64; 
   codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 240; 
   codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 480; 
   codecs.Options.Jpeg2000.Save.RegionOfInterest = CodecsJpeg2000RegionOfInterest.UseLeadRegion; 
   codecs.Options.Jpeg2000.Save.RegionOfInterestRectangle = new LeadRect(0, 0, 0, 0); 
   codecs.Options.Jpeg2000.Save.TargetFileSize = 10240; 
   codecs.Options.Jpeg2000.Save.TileHorizontalOffset = 0; 
   codecs.Options.Jpeg2000.Save.TileVerticalOffset = 0; 
   codecs.Options.Jpeg2000.Save.UseColorTransform = true; 
   codecs.Options.Jpeg2000.Save.UseEphMarker = false; 
   codecs.Options.Jpeg2000.Save.UseRegionOfInterest = false; 
   codecs.Options.Jpeg2000.Save.UseSopMarker = false; 
 
   //Save the first sample. 
   codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "Image1_test.j2k"), RasterImageFormat.J2k, srcImage.BitsPerPixel); 
   codecs.Options.Jpeg2000.Save.Reset(); 
 
   //changing some of the Jpeg2000 save options 
   codecs.Options.Jpeg2000.Save.CompressionRatio = 23.0f; 
   codecs.Options.Jpeg2000.Save.DecompositionLevels = 6; 
   codecs.Options.Jpeg2000.Save.ReferenceTileHeight = 320; 
   codecs.Options.Jpeg2000.Save.ReferenceTileWidth = 320; 
   codecs.Options.Jpeg2000.Save.UseEphMarker = true; 
   codecs.Options.Jpeg2000.Save.ProgressingOrder = CodecsJpeg2000ProgressionsOrder.ResolutionPositionComponentLayer; 
   codecs.Options.Jpeg2000.Save.UseSopMarker = true; 
   codecs.Options.Jpeg2000.Save.TargetFileSize = 102400; 
 
   var maximumComponentsNumber = CodecsJpeg2000SaveOptions.MaximumComponentsNumber; 
   var maximumDecompressionLevels = CodecsJpeg2000SaveOptions.MaximumDecompressionLevels; 
   Console.WriteLine("MaximumComponents: {0}, MaximumDecompressionLevels: {1}", maximumComponentsNumber, maximumDecompressionLevels); 
 
   //Save the first sample. 
   codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "Image1_test.jp2"), RasterImageFormat.J2k, srcImage.BitsPerPixel); 
 
   // Clean up 
   srcImage.Dispose(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.nio.file.Paths; 
 
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.MinMaxBitsCommand; 
 
 
public void codecsJpeg2000OptionsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.j2k"); 
   CodecsJpeg2000PrecinctSize[] precinctSizes = CodecsJpeg2000PrecinctSize.values(); 
   System.out.println(precinctSizes.toString()); 
 
   // Setting the Jpeg2000 load options. CodecsJpeg2000Options & 
   // CodecsJpeg2000LoadOptions reference 
   codecs.getOptions().getJpeg2000().getLoad().setJ2kResolution(new LeadSize(800, 800)); 
   codecs.getOptions().getJpeg2000().getLoad().setJp2Resolution(new LeadSize(800, 800)); 
   codecs.getOptions().getJpeg2000().getLoad().setCmwResolution(new LeadSize(0, 0)); 
 
   // loading a Jpeg2000 image. 
   RasterImage srcImage = codecs.load(srcFileName); 
 
   // Setting the Jpeg2000 save options. CodecsJpeg2000SaveOptions reference 
   codecs.getOptions().getJpeg2000().getSave().setAlphaChannelActiveBits(16); 
   codecs.getOptions().getJpeg2000().getSave().setAlphaChannelLossless(false); 
   codecs.getOptions().getJpeg2000().getSave().setCompressionControl(CodecsJpeg2000CompressionControl.RATIO); 
   codecs.getOptions().getJpeg2000().getSave().setCompressionRatio(15.0f); 
   codecs.getOptions().getJpeg2000().getSave().setDecompositionLevels(5); 
   codecs.getOptions().getJpeg2000().getSave().setDerivedQuantization(true); 
   codecs.getOptions().getJpeg2000().getSave().setImageAreaHorizontalOffset(0); 
   codecs.getOptions().getJpeg2000().getSave().setImageAreaVerticalOffset(0); 
   codecs.getOptions().getJpeg2000().getSave() 
         .setProgressingOrder(CodecsJpeg2000ProgressionsOrder.POSITION_COMPONENT_RESOLUTION_LAYER); 
   codecs.getOptions().getJpeg2000().getSave().setPrecinctSize(CodecsJpeg2000PrecinctSize.HIERARCHICAL_ONE_64); 
   codecs.getOptions().getJpeg2000().getSave().setReferenceTileHeight(240); 
   codecs.getOptions().getJpeg2000().getSave().setReferenceTileWidth(480); 
   codecs.getOptions().getJpeg2000().getSave().setRegionOfInterest(CodecsJpeg2000RegionOfInterest.USE_LEAD_REGION); 
   codecs.getOptions().getJpeg2000().getSave().setRegionOfInterestRectangle(new LeadRect(0, 0, 0, 0)); 
   codecs.getOptions().getJpeg2000().getSave().setTargetFileSize(10240); 
   codecs.getOptions().getJpeg2000().getSave().setTileHorizontalOffset(0); 
   codecs.getOptions().getJpeg2000().getSave().setTileVerticalOffset(0); 
   codecs.getOptions().getJpeg2000().getSave().setUseColorTransform(true); 
   codecs.getOptions().getJpeg2000().getSave().setUseEphMarker(false); 
   codecs.getOptions().getJpeg2000().getSave().setUseRegionOfInterest(false); 
   codecs.getOptions().getJpeg2000().getSave().setUseSopMarker(false); 
 
   // Save the first sample. 
   codecs.save(srcImage, combine(LEAD_VARS_IMAGES_DIR, "Image1_test.j2k"), RasterImageFormat.J2K, 
         srcImage.getBitsPerPixel()); 
   codecs.getOptions().getJpeg2000().getSave().reset(); 
 
   // changing some of the Jpeg2000 save options 
   codecs.getOptions().getJpeg2000().getSave().setCompressionRatio(23.0f); 
   codecs.getOptions().getJpeg2000().getSave().setDecompositionLevels(6); 
   codecs.getOptions().getJpeg2000().getSave().setReferenceTileHeight(320); 
   codecs.getOptions().getJpeg2000().getSave().setReferenceTileWidth(320); 
   codecs.getOptions().getJpeg2000().getSave().setUseEphMarker(true); 
   codecs.getOptions().getJpeg2000().getSave() 
         .setProgressingOrder(CodecsJpeg2000ProgressionsOrder.RESOLUTION_POSITION_COMPONENT_LAYER); 
   codecs.getOptions().getJpeg2000().getSave().setUseSopMarker(true); 
   codecs.getOptions().getJpeg2000().getSave().setTargetFileSize(102400); 
   CodecsJpeg2000SaveOptions csSaveOptions = new CodecsJpeg2000SaveOptions(null); 
   var maximumComponentsNumber = csSaveOptions.getMaximumComponentsNumber(); 
   var maximumDecompressionLevels = csSaveOptions.getMaximumDecompressionLevels(); 
   System.out.println("MaximumComponents: " + maximumComponentsNumber + ", MaximumDecompressionLevels: " 
         + maximumDecompressionLevels); 
 
   // Save the first sample. 
   String outputFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1_test.jp2"); 
   codecs.save(srcImage, outputFileName, RasterImageFormat.J2K, srcImage.getBitsPerPixel()); 
 
   assertTrue("File unsuccessfully saved to " + outputFileName, (new File(outputFileName)).exists()); 
   System.out.printf("File successfully saved to %s%n", outputFileName); 
 
   // Clean up 
   srcImage.dispose(); 
   codecs.dispose(); 
} 

Requirements

Target Platforms

See Also

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

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