jj2000.j2k.roi.encoder
Class ROIScaler

java.lang.Object
  |
  +--jj2000.j2k.image.ImgDataAdapter
        |
        +--jj2000.j2k.roi.encoder.ROIScaler
All Implemented Interfaces:
CBlkQuantDataSrcEnc, ForwWTDataProps, ImgData

public class ROIScaler
extends ImgDataAdapter
implements CBlkQuantDataSrcEnc

This class deals with the ROI functionality.

The ROI method is the Maxshift method. The ROIScaler works by scaling the quantized wavelet coefficients that do not affect the ROI (i.e background coefficients) so that these samples get a lower significance than the ROI ones. By scaling the coefficients sufficiently, the ROI coefficients can be recognized by their amplitude alone and no ROI mask needs to be generated at the decoder side.

The source module must be a quantizer and code-block's data is exchange with thanks to CBlkWTData instances.

See Also:
Quantizer, CBlkWTData

Field Summary
private  boolean blockAligned
          Flag indicating if block aligned ROIs are used
private  int[][] maxMagBits
          The maximum number of magnitude bit-planes in any subband.
private  ROIMaskGenerator mg
          The class generating the ROI mask
static char OPT_PREFIX
          The prefix for ROI Scaler options: 'R'
private static java.lang.String[][] pinfo
          The list of parameters that are accepted for ROI coding.
private  boolean roi
          Flag indicating the presence of ROIs
private  DataBlkInt roiMask
          The ROI mask
private  Quantizer src
          The source of quantized wavelet transform coefficients
private  int useStartLevel
          Number of resolution levels to include in ROI mask
 
Fields inherited from class jj2000.j2k.image.ImgDataAdapter
imgdatasrc, tIdx
 
Constructor Summary
ROIScaler(Quantizer src, ROIMaskGenerator mg, boolean roi, int sLev, boolean uba, EncoderSpecs encSpec)
          Constructor of the ROI scaler, takes a Quantizer as source of data to scale.
 
Method Summary
private  void calcMaxMagBits(EncoderSpecs encSpec)
          Calculates the maximum amount of magnitude bits for each tile-component, and stores it in the 'maxMagBits' array.
static ROIScaler createInstance(Quantizer src, ParameterList pl, EncoderSpecs encSpec)
          Creates a ROIScaler object.
 SubbandAn getAnSubbandTree(int t, int c)
          Returns a reference to the subband tree structure representing the subband decomposition for the specified tile-component.
 boolean getBlockAligned()
          This function returns the blockAligned flag
 int getCbULX()
          Returns the horizontal offset of the code-block partition.
 int getCbULY()
          Returns the vertical offset of the code-block partition.
 CBlkWTData getNextCodeBlock(int c, CBlkWTData cblk)
          This function gets a datablk from the entropy coder.
 CBlkWTData getNextInternCodeBlock(int c, CBlkWTData cblk)
          This function gets a datablk from the entropy coder.
static java.lang.String[][] getParameterInfo()
          Returns the parameters that are used in this class and implementing classes.
 ROIMaskGenerator getROIMaskGenerator()
          This function returns the ROI mask generator.
 boolean isReversible(int t, int c)
          Since ROI scaling is always a reversible operation, it calls isReversible() method of it source (the quantizer module).
 void nextTile()
          Advances to the next tile, in standard scan-line order (by rows then columns).
protected static java.util.Vector parseROIs(java.lang.String roiopt, int nc, java.util.Vector roiVector)
          This function parses the values given for the ROIs with the argument -Rroi.
 void setTile(int x, int y)
          Changes the current tile, given the new indexes.
 boolean useRoi()
          This function returns the flag indicating if any ROI functionality used
 
Methods inherited from class jj2000.j2k.image.ImgDataAdapter
getCompImgHeight, getCompImgWidth, getCompSubsX, getCompSubsY, getCompULX, getCompULY, getImgHeight, getImgULX, getImgULY, getImgWidth, getNomRangeBits, getNomTileHeight, getNomTileWidth, getNumComps, getNumTiles, getNumTiles, getTile, getTileCompHeight, getTileCompWidth, getTileHeight, getTileIdx, getTilePartULX, getTilePartULY, getTileWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jj2000.j2k.image.ImgData
getCompImgHeight, getCompImgWidth, getCompSubsX, getCompSubsY, getCompULX, getCompULY, getImgHeight, getImgULX, getImgULY, getImgWidth, getNomRangeBits, getNomTileHeight, getNomTileWidth, getNumComps, getNumTiles, getNumTiles, getTile, getTileCompHeight, getTileCompWidth, getTileHeight, getTileIdx, getTilePartULX, getTilePartULY, getTileWidth
 

Field Detail

OPT_PREFIX

public static final char OPT_PREFIX
The prefix for ROI Scaler options: 'R'

See Also:
Constant Field Values

pinfo

private static final java.lang.String[][] pinfo
The list of parameters that are accepted for ROI coding. Options for ROI Scaler start with 'R'.


maxMagBits

private int[][] maxMagBits
The maximum number of magnitude bit-planes in any subband. One value for each tile-component


roi

private boolean roi
Flag indicating the presence of ROIs


blockAligned

private boolean blockAligned
Flag indicating if block aligned ROIs are used


useStartLevel

private int useStartLevel
Number of resolution levels to include in ROI mask


mg

private ROIMaskGenerator mg
The class generating the ROI mask


roiMask

private DataBlkInt roiMask
The ROI mask


src

private Quantizer src
The source of quantized wavelet transform coefficients

Constructor Detail

ROIScaler

public ROIScaler(Quantizer src,
                 ROIMaskGenerator mg,
                 boolean roi,
                 int sLev,
                 boolean uba,
                 EncoderSpecs encSpec)
Constructor of the ROI scaler, takes a Quantizer as source of data to scale.

Parameters:
src - The quantizer that is the source of data.
mg - The mask generator that will be used for all components
roi - Flag indicating whether there are rois specified.
sLev - The resolution levels that belong entirely to ROI
uba - Flag indicating whether block aligning is used.
encSpec - The encoder specifications for addition of roi specs
Method Detail

isReversible

public boolean isReversible(int t,
                            int c)
Since ROI scaling is always a reversible operation, it calls isReversible() method of it source (the quantizer module).

Specified by:
isReversible in interface ForwWTDataProps
Parameters:
t - The tile to test for reversibility
c - The component to test for reversibility
Returns:
True if the quantized data is reversible, false if not.

getAnSubbandTree

public SubbandAn getAnSubbandTree(int t,
                                  int c)
Returns a reference to the subband tree structure representing the subband decomposition for the specified tile-component.

Specified by:
getAnSubbandTree in interface ForwWTDataProps
Parameters:
t - The index of the tile.
c - The index of the component.
Returns:
The subband tree structure, see SubbandAn.
See Also:
SubbandAn, Subband

getCbULX

public int getCbULX()
Returns the horizontal offset of the code-block partition. Allowable values are 0 and 1, nothing else.

Specified by:
getCbULX in interface ForwWTDataProps

getCbULY

public int getCbULY()
Returns the vertical offset of the code-block partition. Allowable values are 0 and 1, nothing else.

Specified by:
getCbULY in interface ForwWTDataProps

createInstance

public static ROIScaler createInstance(Quantizer src,
                                       ParameterList pl,
                                       EncoderSpecs encSpec)
Creates a ROIScaler object. The Quantizer is the source of data to scale.

The ROI Scaler creates a ROIMaskGenerator depending on what ROI information is in the ParameterList. If only rectangular ROI are used, the fast mask generator for rectangular ROI can be used.

Parameters:
src - The source of data to scale
pl - The parameter list (or options).
encSpec - The encoder specifications for addition of roi specs
Throws:
java.lang.IllegalArgumentException - If an error occurs while parsing the options in 'pl'

parseROIs

protected static java.util.Vector parseROIs(java.lang.String roiopt,
                                            int nc,
                                            java.util.Vector roiVector)
This function parses the values given for the ROIs with the argument -Rroi. Currently only circular and rectangular ROIs are supported.

A rectangular ROI is indicated by a 'R' followed the coordinates for the upper left corner of the ROI and then its width and height.

A circular ROI is indicated by a 'C' followed by the coordinates of the circle center and then the radius.

Before the R and C values, the component that are affected by the ROI are indicated.

Parameters:
roiopt - The info on the ROIs
nc - number of components
roiVector - The vcector containing the ROI parsed from the cmd line
Returns:
The ROIs specified in roiopt

getNextCodeBlock

public CBlkWTData getNextCodeBlock(int c,
                                   CBlkWTData cblk)
This function gets a datablk from the entropy coder. The sample sin the block, which consists of the quantized coefficients from the quantizer, are scaled by the values given for any ROIs specified.

The function calls on a ROIMaskGenerator to get the mask for scaling the coefficients in the current block.

The data returned by this method is a copy of the orignal data. Therfore it can be modified "in place" without any problems after being returned. The 'offset' of the returned data is 0, and the 'scanw' is the same as the code-block width. See the 'CBlkWTData' class.

Specified by:
getNextCodeBlock in interface CBlkQuantDataSrcEnc
Parameters:
c - The component for which to return the next code-block.
cblk - If non-null this object will be used to return the new code-block. If null a new one will be allocated and returned. If the "data" array of the object is non-null it will be reused, if possible, to return the data.
Returns:
The next code-block in the current tile for component 'n', or null if all code-blocks for the current tile have been returned.
See Also:
CBlkWTData

getNextInternCodeBlock

public CBlkWTData getNextInternCodeBlock(int c,
                                         CBlkWTData cblk)
This function gets a datablk from the entropy coder. The sample sin the block, which consists of the quantized coefficients from the quantizer, are scaled by the values given for any ROIs specified.

The function calls on a ROIMaskGenerator to get the mask for scaling the coefficients in the current block.

Specified by:
getNextInternCodeBlock in interface CBlkQuantDataSrcEnc
Parameters:
c - The component for which to return the next code-block.
cblk - If non-null this object will be used to return the new code-block. If null a new one will be allocated and returned. If the "data" array of the object is non-null it will be reused, if possible, to return the data.
Returns:
The next code-block in the current tile for component 'n', or null if all code-blocks for the current tile have been returned.
See Also:
CBlkWTData

getROIMaskGenerator

public ROIMaskGenerator getROIMaskGenerator()
This function returns the ROI mask generator.

Returns:
The roi mask generator

getBlockAligned

public boolean getBlockAligned()
This function returns the blockAligned flag

Returns:
Flag indicating whether the ROIs were block aligned

useRoi

public boolean useRoi()
This function returns the flag indicating if any ROI functionality used

Returns:
Flag indicating whether there are ROIs in the image

getParameterInfo

public static java.lang.String[][] getParameterInfo()
Returns the parameters that are used in this class and implementing classes. It returns a 2D String array. Each of the 1D arrays is for a different option, and they have 3 elements. The first element is the option name, the second one is the synopsis, the third one is a long description of what the parameter is and the fourth is its default value. The synopsis or description may be 'null', in which case it is assumed that there is no synopsis or description of the option, respectively. Null may be returned if no options are supported.

Returns:
the options name, their synopsis and their explanation, or null if no options are supported.

setTile

public void setTile(int x,
                    int y)
Changes the current tile, given the new indexes. An IllegalArgumentException is thrown if the indexes do not correspond to a valid tile.

Specified by:
setTile in interface ImgData
Overrides:
setTile in class ImgDataAdapter
Parameters:
x - The horizontal index of the tile.
y - The vertical index of the new tile.

nextTile

public void nextTile()
Advances to the next tile, in standard scan-line order (by rows then columns). An NoNextElementException is thrown if the current tile is the last one (i.e. there is no next tile).

Specified by:
nextTile in interface ImgData
Overrides:
nextTile in class ImgDataAdapter

calcMaxMagBits

private void calcMaxMagBits(EncoderSpecs encSpec)
Calculates the maximum amount of magnitude bits for each tile-component, and stores it in the 'maxMagBits' array. This is called by the constructor

Parameters:
encSpec - The encoder specifications for addition of roi specs