Java Code Examples for java.awt.image.renderable.ParameterBlock#addSource()

The following examples show how to use java.awt.image.renderable.ParameterBlock#addSource() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public static PlanarImage adjustBrightness(PlanarImage src, final double b) {
    final double[][] matrixRGB = {
            {1d, 0D, 0D, b},
            {0D, 1d, 0D, b},
            {0, 0D, 1d, b}

    };


    final double[][] matrixGrey = {
            {1d, b}
    };

    double[][] matrix;
    if (src.getSampleModel().getNumBands() > 1)
        matrix = matrixRGB;
    else matrix = matrixGrey;


    ParameterBlock pb = new ParameterBlock();
    pb.addSource(src);
    pb.add(matrix);
    return JAI.create("bandcombine", pb);
}
 
Example 2
public PlanarImage process() {
    if (!parameterSet) throw new IllegalStateException("parameters not set");
    PlanarImage pi = source;
    //   for (int i=0; i<numIter; i++) {
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(pi);
    pb.add(MedianFilterDescriptor.MEDIAN_MASK_SQUARE);
    pb.add(radius);
    pi = JAI.create("MedianFilter", pb);
    //  }
    return pi;

}
 
Example 3
private PlanarImage makeTiledImage(PlanarImage img, int tileWidth, int tileHeight) {
    ImageLayout tileLayout = new ImageLayout(img);
    tileLayout.setTileWidth(tileWidth);
    tileLayout.setTileHeight(tileHeight);
    tileLayout.setSampleModel(img.getColorModel().createCompatibleSampleModel(tileWidth,tileHeight));
    tileLayout.setColorModel(img.getColorModel());
    RenderingHints tileHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, tileLayout);
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(img);
    PlanarImage pi = JAI.create("format", pb, tileHints);
    pi.getWidth();
    return pi;
}
 
Example 4
private PlanarImage activeChannels(PlanarImage source, boolean redActive, boolean greenActive, boolean blueActive) {
    final double[][] matrix = {
            {redActive ? 1D : 0D, 0D, 0D, 0d},
            {0D, greenActive ? 1D : 0D, 0D, 0d},
            {0D, 0D, blueActive ? 1D : 0D, 0d}
    };
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(source);
    pb.add(matrix);
    return JAI.create("bandcombine", pb, null);
}
 
Example 5
private RenderedOp convertColorToGray(PlanarImage src, double r, double g, double b) {
    final double[][] matrix = {
            {r, g, b, 0d} // .114D, 0.587D, 0.299D
    };
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(src);
    pb.add(matrix);
    return JAI.create("bandcombine", pb, /*ManipulationUtils.getRenderingHints(image)*/null);
}
 
Example 6
private RenderedOp convertColorToGray(PlanarImage src) {
    final double[][] matrix = {
            //  { 0.114D, 0.587D, 0.299D, 0d } // .114D, 0.587D, 0.299D
            {0.333D, 0.333D, 0.333D, 0d} // .114D, 0.587D, 0.299D
    };
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(src);
    pb.add(matrix);
    return JAI.create("bandcombine", pb, /*ManipulationUtils.getRenderingHints(image)*/null);
}
 
Example 7
public void loadImageSpecial(RawDataFile rdf, int level) throws OrbitImageServletException, SQLException {
    int num = level;
    if (num < 1000)
        num++;   // +1 because orbit file system starts with 1 and not 0 (id, id.1, id.2, ...)  - but not for special layers like slide overview or label (>=1000)
    origImage = null;
    try {
        switch (level) {
            case RawUtilsCommon.LEVEL_LABEL: {
                origImage = new OrbitTiledImagePlanarImage(PlanarImage.wrapRenderedImage(DALConfig.getImageProvider().getLabelImage(rdf)));
                break;
            }
            case RawUtilsCommon.LEVEL_OVERVIEW: {
                origImage = new OrbitTiledImagePlanarImage(PlanarImage.wrapRenderedImage(DALConfig.getImageProvider().getOverviewImage(rdf)));
                break;
            }
            default: {
                origImage = new OrbitTiledImageIOrbitImage(wrapImage(DALConfig.getImageProvider().createOrbitImage(rdf, level)));
                break;
            }
        }
        if (origImage == null) return; // not available
        if (level == RawUtilsCommon.LEVEL_LABEL) {
            float centerX = (float) origImage.getWidth() / 2;
            float centerY = (float) origImage.getHeight() / 2;
            ParameterBlock pb = new ParameterBlock();
            pb.addSource(origImage);
            pb.add(centerX);
            pb.add(centerY);
            pb.add(new Float(Math.toRadians(90)));
            pb.add(new javax.media.jai.InterpolationBicubic(10));
            origImage = JAI.create("rotate", pb);
        }

        setImage(origImage);
        imageName = rdf.toString();
        imageAdjustments = OrbitUtils.getAndParseImageAdjustments(rdf.getRawDataFileId());
    } catch (Exception e) {
        logger.error("Special layer not available for this image.");
    }
}
 
Example 8
Source Project: qaf   File: ImageCompareUtil.java    License: MIT License 5 votes vote down vote up
private RenderedImage rescale(RenderedImage i) {
	float scaleW = ((float) baseSize) / i.getWidth();
	float scaleH = ((float) baseSize) / i.getHeight();
	// Scales the original image
	ParameterBlock pb = new ParameterBlock();
	pb.addSource(i);
	pb.add(scaleW);
	pb.add(scaleH);
	pb.add(0.0F);
	pb.add(0.0F);
	pb.add(new InterpolationNearest());
	// Creates a new, scaled image and uses it on the DisplayJAI component
	return JAI.create("scale", pb);
}
 
Example 9
public static RenderedImage resizeImage(RenderedImage image, int width, int height)
      throws InconsistentImageScale
{
   RenderedImage resizedImage=image;
   // Computes ratio and scale
   float scale=getScale(image.getWidth(),image.getHeight(),width,height);
   
   // Processing resize process
   ParameterBlock pb = new ParameterBlock();
   // The source image
   pb.addSource(resizedImage);
   // The xScale
   pb.add(scale);
   // The yScale
   pb.add(scale);
   // The x translation
   pb.add(0.0F);
   // The y translation
   pb.add(0.0F);
   // The interpolation
   pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
   resizedImage = JAI.create("scale", pb, null);
   
   LOGGER.debug("Image resized to : " + resizedImage.getWidth() + "x"
      + resizedImage.getHeight());
   
   return resizedImage;
}
 
Example 10
public RenderedImage dewarpImage ()
{
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(Picture.invert(sheet.getPicture().getImage()));
    pb.add(dewarpGrid);
    pb.add(new InterpolationBilinear());

    RenderedImage dewarpedImage = Picture.invert(JAI.create("warp", pb));
    ((PlanarImage) dewarpedImage).getTiles();

    return dewarpedImage;
}
 
Example 11
/**
 * Creates a new TestWarp object.
 */
public TestWarp (String path)
{
    srcImage = JAI.create("fileload", new ParameterBlock().add(path), null);
    //        srcImage = PictureLoader.loadImages(new File(path), null)
    //                                .get(1);
    //        srcImage = buildPattern(20, 10, 50, 50);
    dimension = new Dimension(srcImage.getWidth(), srcImage.getHeight());
    setPreferredSize(dimension);

    //        float[]        xCoeffs = new float[] { 0f, 1.25f, 0.04f };
    //        float[]        yCoeffs = new float[] { 0f, -0.02f, 1.5f };
    //        Warp           warp = new WarpAffine(xCoeffs, yCoeffs);
    //
    int            xStep = 500;
    int            xNumCells = 2;
    int            yStep = 500;
    int            yNumCells = 1;
    float[]        warpPositions = new float[] {
                                       -100f, 0f, 500f, 100f, 1000f, 0f, // top line
    0f, 500f, 500f, 500f, 1000f, 500f
                                   }; // bot line
    Warp           warp = new WarpGrid(
        0,
        xStep,
        xNumCells,
        0,
        yStep,
        yNumCells,
        warpPositions);
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(invert(srcImage));
    pb.add(warp);
    pb.add(new InterpolationBilinear());
    dstImage = invert(JAI.create("warp", pb));
    ((PlanarImage) dstImage).getTiles();
}
 
Example 12
private PlanarImage mergeChannels(final OrbitTiledImage2 redChannel, final OrbitTiledImage2 greenChannel, final PlanarImage blueChannel, int tileX, int tileY, boolean redActive, boolean greenActive, boolean blueActive) {

        PlanarImage red = redChannel == null ? null : PlanarImage.wrapRenderedImage(createImage(redChannel.getTile(tileX, tileY), null, redChannel.getSampleModel(), redChannel.getColorModel()));
        PlanarImage green = greenChannel == null ? null : PlanarImage.wrapRenderedImage(createImage(greenChannel.getTile(tileX, tileY), null, greenChannel.getSampleModel(), greenChannel.getColorModel()));
        PlanarImage blue = blueChannel == null ? null : PlanarImage.wrapRenderedImage(createImage(blueChannel.getTile(tileX, tileY), null, blueChannel.getSampleModel(), blueChannel.getColorModel()));

        PlanarImage nullImage = null;
        if (red != null) nullImage = getNullImage(red);
        else if (green != null) nullImage = getNullImage(green);
        else if (blue != null) nullImage = getNullImage(blue);

        red = red == null ? nullImage : red;
        green = green == null ? nullImage : green;
        blue = blue == null ? nullImage : blue;

        red = redActive ? red : nullImage;
        green = greenActive ? green : nullImage;
        blue = blueActive ? blue : nullImage;

        if (red.getSampleModel().getNumBands() > 1)
            red = convertColorToGray(red, 1, 0, 0);
        if (green.getSampleModel().getNumBands() > 1)
            green = convertColorToGray(green, 0, 1, 0);
        if (blue.getSampleModel().getNumBands() > 1)
            blue = convertColorToGray(blue, 0, 0, 1);


        try {

            ParameterBlock pb = new ParameterBlock();
            if (originalWasGrayScale) {  // bgr fix
                pb.addSource(blue); // b
                pb.addSource(green); // g
                pb.addSource(red); // r
            } else { // rgb
                pb.addSource(red); // r
                pb.addSource(green); // g
                pb.addSource(blue); // b
            }
            PlanarImage merged = JAI.create("bandmerge", pb);

            return merged;
        } catch (Throwable e) {
            e.printStackTrace();
            return null;
        }


    }
 
Example 13
public static PlanarImage adjustContrast(PlanarImage src, double red, double green, double blue, double contrast, double brightness, OrbitUtils.ImageAdjustCachedParams cachedParams, TiledImagePainter tipForStats) {

        if (!cachedParams.isContrastAverageSet()) {

            PlanarImage statImg = loadImageForStats(src, tipForStats);

            final int numScan = 200;
            int skipW = Math.max(1, src.getWidth() / numScan);
            int skipH = Math.max(1, src.getHeight() / numScan);

            ParameterBlock mpb = new ParameterBlock();
            mpb.addSource(statImg); // The source image
            mpb.add(null); // null ROI means whole image
            mpb.add(skipW); // 1 check every pixel horizontally
            mpb.add(skipH); // 1 check every pixel vertically

            // Perform the mean operation on the source image
            PlanarImage meanImage = JAI.create("mean", mpb, null);
            // Retrieve the mean pixel value
            double[] mean = (double[]) meanImage.getProperty("mean");
            // Average the mean of all bands
            double sum = 0.0D;
            for (int i = 0; i < mean.length; i++) {
                sum += mean[i];
            }
            cachedParams.setContrastAverage(sum / (double) mean.length);
            cachedParams.setContrastAverageSet(true);
        }
        double average = cachedParams.getContrastAverage();

        // Create the lookup table based on the average mean
        byte[][] lut = new byte[3][256];
        for (int i = 0; i < 256; i++) {
            lut[0][i] = ManipulationUtils.clamp((int) ((average + (i - average) * contrast) + red + brightness));
            lut[1][i] = ManipulationUtils.clamp((int) ((average + (i - average) * contrast) + green + brightness));
            lut[2][i] = ManipulationUtils.clamp((int) ((average + (i - average) * contrast) + blue + brightness));
        }


        LookupTableJAI lookup = new LookupTableJAI(lut);
        PlanarImage result = JAI.create("lookup", src, lookup);
        result = makeCompatibleSamplemodel(src, result);
        return result;

    }
 
Example 14
Source Project: qaf   File: ImageCompareUtil.java    License: MIT License 4 votes vote down vote up
public boolean contains(String reference, String template, Point start) throws Exception {
	RenderedImage ref = (ImageIO.read(new File(reference)));

	// Calculate the signature vector for the reference.
	// Now we need a component to store X images in a stack, where X is the
	// number of images in the same directory as the original one.
	// For each image, calculate its signature and its distance from the
	// reference signature.
	RenderedImage other = ImageIO.read(new File(template));

	int x, y, h, w, th, tw;
	double distance = Double.MAX_VALUE;
	h = ref.getHeight();
	w = ref.getWidth();
	System.out.println("px width: " + ref.getData().getWidth() + "px height: " + ref.getData().getHeight());
	System.out.println("width: " + ref.getWidth() + "height: " + ref.getHeight());
	System.out.println("min x: " + ref.getData().getMinX() + " y: " + ref.getData().getMinY());

	th = other.getHeight();
	tw = other.getWidth();

	for (int r = 0; r <= (h - th); r += 5) {
		for (int c = 0; c <= (w - tw); c += 5) {
			ParameterBlock pb = new ParameterBlock();
			pb.addSource(ref);
			pb.add((float) c);
			pb.add((float) r);
			pb.add((float) tw);
			pb.add((float) th);
			pb.add(new InterpolationNearest());
			// Creates a new, scaled image and uses it on the DisplayJAI
			// component

			try {
				double tdistance = calcDistance(rescale(JAI.create("crop", pb)), rescale(other));
				if ((tdistance < distance)) {
					distance = tdistance;
				}

				if (distance == 0) {
					break;
				}
				System.out.println("distance" + distance + " x: " + r + " y: " + c);
			} catch (Exception e) {
				System.out.print("Error: " + e.toString());
				e.printStackTrace();
			}
		}

		if (distance == 0) {
			break;
		}
	}
	return distance < maxDiff;
}
 
Example 15
public static RenderedImage process1BImage (DrbCollectionImage source, 
   int bands, int horizontal_padding, int vertical_padding)
{
   // Prepare output mosaic layout
   ImageLayout layout = new ImageLayout();
   boolean isLayoutTileSet = false;

   // Prepare variables for building output strip mosaic
   int currentWidth = horizontal_padding;
   int currentHeight = vertical_padding;
   
   ParameterBlockJAI mosaicParameters = 
      new ParameterBlockJAI("Mosaic", "rendered");
   
   mosaicParameters.setParameter("mosaicType",
      javax.media.jai.operator.MosaicDescriptor.MOSAIC_TYPE_BLEND);
   
   Collection<DrbImage>images = source.getChildren();
   Iterator<DrbImage> image_it = images.iterator();
   while (image_it.hasNext())
   {
      RenderedImage current_image = null;

      // Select the working bands
      ParameterBlock pb = new ParameterBlock();
      DrbImage fmt = null;
      if (bands>1)
      {
         for (int i=0; i<bands; i++)
         {
            fmt = image_it.next();
            ParameterBlock fmt_pb = new ParameterBlock();
            fmt_pb.addSource(fmt);
            fmt_pb.add(DataBuffer.TYPE_BYTE);
            RenderedOp op = JAI.create("Format", fmt_pb);
         
            pb.addSource(op);
         }
         current_image = JAI.create("bandMerge", pb);
      }
      else
      {
         //Probably PVI image
         current_image = image_it.next();
      }
      
      // Set layout tile size if not already done
      if (!isLayoutTileSet)
      {
         layout.setTileWidth(current_image.getTileWidth());
         layout.setTileHeight(current_image.getTileHeight());
         layout.setColorModel(current_image.getColorModel());
         layout.setSampleModel(current_image.getSampleModel());

         isLayoutTileSet = true;
      }

      // Translate strip to the output coordinate (vertical shift)
      ParameterBlock translateParameters = new ParameterBlock();

      translateParameters.addSource(current_image);
      translateParameters.add((float) currentWidth);
      translateParameters.add((float) currentHeight);
      translateParameters.add(new InterpolationNearest());

      current_image = JAI.create("translate", translateParameters,
         new RenderingHints(JAI.KEY_IMAGE_LAYOUT,layout));

      // TODO: find a way to retrieves the granules position within
      // the mosaic. 
      // Update following strip translation
      /*
      if ((source_index%13)==0)
      {*/
         currentWidth=horizontal_padding;
         currentHeight += current_image.getHeight() + vertical_padding;
         /*
      }
      else
      {
         currentWidth += current_image.getWidth() + horizontal_padding;
      }*/

      // Add current strip to the output mosaic
      mosaicParameters.addSource(current_image);
      // Go to the next image
   }
   double [] backgroundValues = new double [bands];
   for (int j = 0; j < bands; j++) {
       backgroundValues[j] = 0.0D;
   }        
   mosaicParameters.setParameter("backgroundValues", backgroundValues);
   // Create output mosaic
   return JAI.create("mosaic", mosaicParameters,
      new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
}
 
Example 16
Source Project: pdfxtk   File: Utils.java    License: Apache License 2.0 4 votes vote down vote up
public static BufferedImage convertToBinary(BufferedImage sourceImg){

    	double[][] matrix = {{ 0.3D, 0.59D, 0.11D, 0D }};

    	ParameterBlock pb = new ParameterBlock();

    	pb.addSource(sourceImg);

    	pb.add(matrix);

    	PlanarImage src = JAI.create("BandCombine", pb, null);

    	// Generate a histogram.

    	Histogram histogram = (Histogram)JAI.create("histogram", src).getProperty("histogram");

    	// Get a threshold equal to the median.

    	double[] threshold = histogram.getPTileThreshold(0.5);

    	// Binarize the image.

    	PlanarImage dst = JAI.create("binarize", src, new Double(threshold[0]));

    	return dst.getAsBufferedImage(); 
    }