Examples of LookupTableJAI


Examples of javax.media.jai.LookupTableJAI

/* 258 */     createLUT();
/* 259 */     setProperty("LUT", this.colorMap);
/*     */   }
/*     */
/*     */   private void createLUT() {
/* 263 */     this.colorMap = new LookupTableJAI(new byte[3][this.maxColorNum]);
/* 264 */     byte[][] map = this.colorMap.getByteData();
/* 265 */     int[] index = new int[this.maxColorNum];
/* 266 */     for (int i = 0; i < this.maxColorNum; i++)
/* 267 */       index[this.network[i][3]] = i;
/* 268 */     for (int i = 0; i < this.maxColorNum; i++) {
View Full Code Here

Examples of javax.media.jai.LookupTableJAI

/*    */
/* 58 */     if (!MediaLibAccessor.isMediaLibCompatible(args)) {
/* 59 */       return null;
/*    */     }
/*    */
/* 63 */     LookupTableJAI table = (LookupTableJAI)args.getObjectParameter(0);
/* 64 */     if ((table.getNumBands() > 4) || (table.getDataType() == 1))
/*    */     {
/* 66 */       return null;
/*    */     }
/*    */
/* 69 */     return new MlibLookupOpImage(args.getRenderedSource(0), hints, layout, table);
View Full Code Here

Examples of javax.media.jai.LookupTableJAI

/* 126 */     Cube cube = new Cube(getSourceImage(0), this.maxColorNum);
/* 127 */     cube.constructTree();
/* 128 */     cube.reduction();
/* 129 */     cube.assignment();
/*     */
/* 131 */     this.colorMap = new LookupTableJAI(cube.colormap);
/* 132 */     setProperty("LUT", this.colorMap);
/*     */   }
View Full Code Here

Examples of javax.media.jai.LookupTableJAI

/* 252 */         table[value] = ImageUtil.clampRoundByte(binarySearch(x, yL, yH, a, b, value));
/*     */       }
/*     */
/*     */     }
/*     */
/* 258 */     this.lut = new LookupTableJAI(data);
/*     */   }
View Full Code Here

Examples of javax.media.jai.LookupTableJAI

        if (cm instanceof ComponentColorModel) {
            return coverage;
        }
        final int dataType;
        final ColorSpace cs;
        final LookupTableJAI lookup;
        /*
         * If the color model is indexed. Converts to RGB or gray scale using a single "Lookup"
         * operation. Color space will be RGB or GRAY, and type will be DataBuffer.TYPE_BYTE.
         */
        if (cm instanceof IndexColorModel) {
            final IndexColorModel icm = (IndexColorModel) cm;
            final int mapSize = icm.getMapSize();
            final byte data[][];
            if (ColorUtilities.isGrayPalette(icm, false)) {
                final byte[] gray = new byte[mapSize];
                icm.getGreens(gray);
                if (icm.hasAlpha()) {
                    final byte[] alpha = new byte[mapSize];
                    icm.getAlphas(alpha);
                    data = new byte[][] { gray, alpha };
                } else {
                    data = new byte[][] { gray };
                }
                cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
            } else {
                data = new byte[cm.getNumComponents()][mapSize];
                switch (data.length) {
                    default: // Should not occurs, but keep as a paranoiac check.
                    case 4:  icm.getAlphas(data[3]);
                    case 3:  icm.getBlues (data[2]);
                    case 2:  icm.getGreens(data[1]);
                    case 1:  icm.getReds  (data[0]);
                    case 0break;
                }
                cs = icm.getColorSpace();
            }
            dataType = DataBuffer.TYPE_BYTE;
            lookup = new LookupTableJAI(data);
        } else {
            lookup = null;
            cs = cm.getColorSpace();
            dataType = (cm instanceof DirectColorModel) ? DataBuffer.TYPE_BYTE :
                        image.getSampleModel().getTransferType();
View Full Code Here

Examples of javax.media.jai.LookupTableJAI

         *          LookupTableFactory.create(...) to returns null.
         */
        if (transforms != null) try {
            final int sourceType = sourceModel.getDataType();
            final int targetType = targetModel.getDataType();
            LookupTableJAI table = LookupTableFactory.create(sourceType, targetType, transforms);
            if (table != null) {
                operation = "Lookup";
                param = param.add(table);
            }
        } catch (TransformException exception) {
View Full Code Here

Examples of javax.media.jai.LookupTableJAI

          final byte[] lut = new byte[256];
          for (int i = 1; i < lut.length; i++)
            lut[i] = (byte) (scale * i + offset + 0.5d);

          //do the actual lookup
          final LookupTableJAI lookup = new LookupTableJAI(lut);
          final ParameterBlock pb = new ParameterBlock();
          pb.addSource(inputImage);
          pb.add(lookup);
          return JAI.create("lookup", pb, hints);         
        }
       
        ////
        //
        // General case, we use the rescale in order to stretch the values to highest and lowest dim
        //
        ////
        //get the correct dim for this data type
        final double maximum=ColorUtilities.getMaximum(dataType);
        final double minimum=ColorUtilities.getMinimum(dataType);
        if (extrema[1][0] == maximum && extrema[0][0] == minimum)
          return inputImage;
        //compute the scale factors
        final double delta = extrema[1][0] - extrema[0][0];
        final double scale = (maximum -minimum)/ delta;
        final double offset =  minimum - scale * extrema[0][0];

        //do the actual rescale
        final ParameterBlock pb = new ParameterBlock();
        pb.addSource(inputImage);
        pb.add(new double []{scale});
        pb.add(new double []{offset});
        return JAI.create("rescale", pb, hints);

      }
     
     
      // /////////////////////////////////////////////////////////////////////
      //
      // EXPONENTIAL Normalization
      //
      //
      //
      // /////////////////////////////////////////////////////////////////////     
      if (type.equalsIgnoreCase("EXPONENTIAL")) {

        if(dataType==DataBuffer.TYPE_BYTE){
          ////
          //
          // Optimisation for byte images
          //
          ////
          final byte lut[] = new byte[256];
          final double normalizationFactor=255.0;
          final double correctionFactor=255.0/(Math.E-1);
          for (int i = 1; i < lut.length; i++)
            lut[i] = (byte) (0.5f + correctionFactor * (Math.exp(i / normalizationFactor) - 1.0));
          return LookupDescriptor.create(inputImage,
              new LookupTableJAI(lut), hints);
        }
        ////
        //
        // General case, we use the piecewise1D transform
        //
        ////
        //
        // STEP 1 do the extrema
        //
        ////
        //step 1 do the extrema to get the statistics for this image
        final RenderedOp statistics = ExtremaDescriptor.create(inputImage,
            null, Integer.valueOf(1), Integer.valueOf(1), null,
            Integer.valueOf(1), null);
        final double[] minimum=(double[]) statistics.getProperty("minimum");
        final double[] maximum=(double[]) statistics.getProperty("maximum");
        final double normalizationFactor=maximum[0];
        final double correctionFactor=normalizationFactor/(Math.E-1);
       
        ////
        //
        // STEP 2 do the gamma correction by using generic piecewise
        //
        ////
        final DefaultPiecewiseTransform1DElement mainElement = DefaultPiecewiseTransform1DElement.create(
            "exponential-contrast-enhancement-transform", NumberRange.create(minimum[0],maximum[0]),
            new MathTransform1DAdapter() {

                  /*
                   * (non-Javadoc)
                   * @see org.opengis.referencing.operation.MathTransform1D#derivative(double)
                   */
                  public double derivative(double value)
                      throws TransformException {
                   
                    throw new UnsupportedOperationException(Errors.format(ErrorKeys.UNSUPPORTED_OPERATION_$1));
                  }
                  public boolean isIdentity() {
                    return false;
                  }
                  /*
                   * (non-Javadoc)
                   * @see org.opengis.referencing.operation.MathTransform1D#transform(double)
                   */
                  public double transform(double value)
                      throws TransformException {
                    value = correctionFactor*(Math.exp(value/normalizationFactor)-1);
                    return value;
                  }

            });
       
        final PiecewiseTransform1D<DefaultPiecewiseTransform1DElement> transform = new DefaultPiecewiseTransform1D<DefaultPiecewiseTransform1DElement> (
            new DefaultPiecewiseTransform1DElement[] {mainElement},0);

          final ParameterBlockJAI pbj = new ParameterBlockJAI(
              GenericPiecewise.OPERATION_NAME);
          pbj.addSource(inputImage);
          pbj.setParameter("Domain1D", transform);
          pbj.setParameter("bandIndex", Integer.valueOf(0));
          return JAI.create(
              GenericPiecewise.OPERATION_NAME, pbj);
      }     
      if (type.equalsIgnoreCase("LOGARITHMIC")) {
        // /////////////////////////////////////////////////////////////////////
        //
        // Logarithm Normalization
        //
        //
        //
        // /////////////////////////////////////////////////////////////////////
        if(dataType==DataBuffer.TYPE_BYTE){
          ////
          //
          // Optimisation for byte images m we use lookup
          //
          ////
          final byte lut[] = new byte[256];
          final double normalizationFactor=255.0;
          final double correctionFactor=100.0;
          for (int i = 1; i < lut.length; i++)
            lut[i] = (byte) (0.5f + normalizationFactor * Math.log((i * correctionFactor / normalizationFactor+ 1.0)));
          return LookupDescriptor.create(inputImage,
              new LookupTableJAI(lut), hints);       
        }
        ////
        //
        // General case
        //
        ////
        //define a specific piecewise for the logarithm

        ////
        //
        // STEP 1 do the extrema
        //
        ////
        //step 1 do the extrema to get the statistics for this image
        final RenderedOp statistics = ExtremaDescriptor.create(inputImage,
            null, Integer.valueOf(1), Integer.valueOf(1), null,
            Integer.valueOf(1), null);
        final double[] minimum=(double[]) statistics.getProperty("minimum");
        final double[] maximum=(double[]) statistics.getProperty("maximum");
        final double normalizationFactor=maximum[0];
        final double correctionFactor=100.0;
       
        ////
        //
        // STEP 2 do the gamma correction by using generic piecewise
        //
        ////
        final DefaultPiecewiseTransform1DElement mainElement = DefaultPiecewiseTransform1DElement.create(
            "logarithmic-contrast-enhancement-transform", NumberRange.create(minimum[0],maximum[0]),
            new MathTransform1DAdapter() {

                  /*
                   * (non-Javadoc)
                   * @see org.opengis.referencing.operation.MathTransform1D#derivative(double)
                   */
                  public double derivative(double value)
                      throws TransformException {
                   
                    throw new UnsupportedOperationException(Errors.format(ErrorKeys.UNSUPPORTED_OPERATION_$1));
                  }
                  public boolean isIdentity() {
                    return false;
                  }
                  /*
                   * (non-Javadoc)
                   * @see org.opengis.referencing.operation.MathTransform1D#transform(double)
                   */
                  public double transform(double value)
                      throws TransformException {
                    value =normalizationFactor*Math.log(1+(value*correctionFactor/normalizationFactor));
                    return value;
                  }

                 
            });
       
        final PiecewiseTransform1D<DefaultPiecewiseTransform1DElement>  transform = new DefaultPiecewiseTransform1D<DefaultPiecewiseTransform1DElement> (
            new DefaultPiecewiseTransform1DElement[] {mainElement},0);

          final ParameterBlockJAI pbj = new ParameterBlockJAI(
              GenericPiecewise.OPERATION_NAME);
          pbj.addSource(inputImage);
          pbj.setParameter("Domain1D", transform);
          pbj.setParameter("bandIndex", Integer.valueOf(0));
          return JAI.create(
              GenericPiecewise.OPERATION_NAME, pbj);
      }     
      if (type.equalsIgnoreCase("HISTOGRAM")) {
        // /////////////////////////////////////////////////////////////////////
        //
        // Histogram Equalization
        //
        // IT WORKS ONLY ON BYTE DATA TYPE!!!
        //
        // /////////////////////////////////////////////////////////////////////

        //convert the input image to 8 bit
        inputImage=new ImageWorker(inputImage).rescaleToBytes().getRenderedImage();
        // compute the histogram
        final RenderedOp hist = HistogramDescriptor.create(inputImage,
            null, Integer.valueOf(1), Integer.valueOf(1),
            new int[] { 256 }, new double[] { 0 },
            new double[] { 256 }, null);
        final Histogram h = (Histogram) hist.getProperty("histogram");

        // now compute the PDF and the CDF for the original image
        final byte[] cumulative = new byte[h.getNumBins(0)];

        // sum of bins (we might have excluded 0 hence we cannot really
        // optimise)
        float totalBinSum = 0;
        for (int i = 0; i < cumulative.length; i++) {
          totalBinSum += h.getBinSize(0, i);
        }

        // this is the scale factor for the histogram equalization
        // process
        final float scale = (float) (h.getHighValue(0) - 1 - h.getLowValue(0))/ totalBinSum;
        float sum = 0;
        for (int i = 1; i < cumulative.length; i++) {
          sum += h.getBinSize(0, i - 1);
          cumulative[i] = (byte) ((sum * scale + h.getLowValue(0)) + .5F);
        }

        final LookupTableJAI lookup = new LookupTableJAI(cumulative);
        final ParameterBlock pb = new ParameterBlock();
        pb.addSource(hist);
        pb.add(lookup);
        return JAI.create("lookup", pb, hints);
      }
View Full Code Here

Examples of javax.media.jai.LookupTableJAI

        final byte[] lut = new byte[256];
        for (int i = 1; i < lut.length; i++)
          lut[i] = (byte) (255.0 * Math.pow(i / 255.0, gammaValue) + 0.5d);

        // apply the operation now
        final LookupTableJAI lookup = new LookupTableJAI(lut);
        final ParameterBlock pb = new ParameterBlock();
        pb.addSource(inputImage);
        pb.add(lookup);
        result = JAI.create("lookup", pb, hints);
      }
View Full Code Here

Examples of javax.media.jai.LookupTableJAI

            /*
             * Checks if a table is already available in the cache. Since tables may be 64 kb big,
             * sharing tables may save a significant amount of memory if there is many images.
             */
            final LookupTableFactory key = new LookupTableFactory(sourceType, targetType, transforms);
            LookupTableJAI table = pool.get(key);
            if (table != null) {
                return table;
            }
            /*
             * Computes the table's size according the source datatype. For datatype 'short' (signed
             * or unsigned), we will create the table only if the target datatype is 'byte' in order
             * to avoid to use too much memory for the table. The memory consumed for a table from
             * source datatype 'short' to target datatype 'byte' is 64 ko.
             */
            final int length;
            final int offset;
            switch (sourceType) {
                default: {
                    return null;
                }
                case DataBuffer.TYPE_BYTE: {
                    length = 0x100;
                    offset = 0;
                    break;
                }
                case DataBuffer.TYPE_SHORT:
                case DataBuffer.TYPE_USHORT: {
                    if (targetType != DataBuffer.TYPE_BYTE) {
                        // Avoid to use too much memory for the table.
                        return null;
                    }
                    length = 0x10000;
                    offset = (sourceType == DataBuffer.TYPE_SHORT) ? Short.MIN_VALUE : 0;
                    break;
                }
            }
            /*
             * Builds the table according the target datatype.
             */
            switch (targetType) {
                default: {
                    return null;
                }
                case DataBuffer.TYPE_DOUBLE: {
                    final double[][]  data = new double[nbands][];
                    final double[]  buffer = new double[length];
                    for (int i=length; --i>=0;) {
                        buffer[i] = i;
                    }
                    for (int i=nbands; --i>=0;) {
                        final double[] array = (i==0) ? buffer : buffer.clone();
                        transforms[i].transform(array, 0, array, 0, array.length);
                        data[i] = array;
                    }
                    table = new LookupTableJAI(data, offset);
                    break;
                }
                case DataBuffer.TYPE_FLOAT: {
                    final float[][]  data = new float[nbands][];
                    final float[]  buffer = new float[length];
                    for (int i=length; --i>=0;) {
                        buffer[i] = i;
                    }
                    for (int i=transforms.length; --i>=0;) {
                        final float[] array = (i == 0) ? buffer : buffer.clone();
                        transforms[i].transform(array, 0, array, 0, length);
                        data[i] = array;
                    }
                    table = new LookupTableJAI(data, offset);
                    break;
                }
                case DataBuffer.TYPE_INT: {
                    final int[][] data = new int[nbands][];
                    for (int i=nbands; --i>=0;) {
                        final MathTransform1D tr = transforms[i];
                        final int[] array = new int[length];
                        for (int j=length; --j>=0;) {
                            array[j] = (int) min(max(round(tr.transform(j+offset)),
                                    Integer.MIN_VALUE), Integer.MAX_VALUE);
                        }
                        data[i] = array;
                    }
                    table = new LookupTableJAI(data, offset);
                    break;
                }
                case DataBuffer.TYPE_SHORT:
                case DataBuffer.TYPE_USHORT: {
                    final int minimum, maximum;
                    if (targetType == DataBuffer.TYPE_SHORT) {
                        minimum = Short.MIN_VALUE;
                        maximum = Short.MAX_VALUE;
                    } else {
                        minimum = 0;
                        maximum = 0xFFFF;
                    }
                    final short[][] data = new short[nbands][];
                    for (int i=nbands; --i>=0;) {
                        final MathTransform1D tr = transforms[i];
                        final short[] array = new short[length];
                        for (int j=length; --j>=0;) {
                            array[j] = (short) min(max(round(tr.transform(j+offset)), minimum), maximum);
                        }
                        data[i] = array;
                    }
                    table = new LookupTableJAI(data, offset, minimum!=0);
                    break;
                }
                case DataBuffer.TYPE_BYTE: {
                    final byte[][] data = new byte[nbands][];
                    for (int i=nbands; --i>=0;) {
                        final MathTransform1D tr = transforms[i];
                        final byte[] array = new byte[length];
                        for (int j=length; --j>=0;) {
                            array[j] = (byte) min(max(round(tr.transform(j+offset)), 0), 0xFF);
                        }
                        data[i] = array;
                    }
                    table = new LookupTableJAI(data, offset);
                    break;
                }
            }
            pool.put(key, table);
            return table;
View Full Code Here

Examples of javax.media.jai.LookupTableJAI

            // layout.setColorModel(temp.getColorModel());
            // hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT,layout));

            // error diffusion
            final KernelJAI ditherMask = KernelJAI.ERROR_FILTER_FLOYD_STEINBERG;
            final LookupTableJAI colorMap = ColorCube.BYTE_496;
            // (LookupTableJAI) temp.getProperty("JAI.LookupTable");
            image = ErrorDiffusionDescriptor.create(image, colorMap, ditherMask, hints);
        } else {
            // ordered dither
            final KernelJAI[] ditherMask = KernelJAI.DITHER_MASK_443;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.