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

The following examples show how to use java.awt.image.renderable.ParameterBlock#add() . 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 check out the related API usage on the sidebar.
Example 1
Source File: OrbitTiledImage2.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: MedianFilter.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: OrbitTiledImage2.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
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 4
Source File: OrbitTiledImage2.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
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 5
Source File: OrbitTiledImage2.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
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 6
Source File: TiledImagePainter.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: ImageCompareUtil.java    From qaf with 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 8
Source File: ProcessingUtils.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
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 9
Source File: ImageUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private BufferedImage privateReadFromFile(final File file, final boolean forOpenGL) throws IOException {
	// DEBUG.OUT("READING " + file.getName());
	BufferedImage result = getNoImage();
	if (file == null) { return result; }
	final String name = file.getName();
	String ext = null;
	if (name.contains(".")) {
		ext = name.substring(file.getName().lastIndexOf('.'));
	}
	if (tiffExt.contains(ext)) {
		try (FileSeekableStream stream = new FileSeekableStream(file.getAbsolutePath())) {
			/**
			 * AD TODO : decodeParam is not used ...
			 */
			// final TIFFDecodeParam decodeParam = new TIFFDecodeParam();
			// decodeParam.setDecodePaletteAsShorts(true);
			final ParameterBlock params = new ParameterBlock();
			params.add(stream);
			final RenderedOp image1 = JAI.create("tiff", params);
			return image1.getAsBufferedImage();
		}
	} else if (gifExt.contains(ext)) {
		final GifDecoder d = new GifDecoder();
		d.read(new FileInputStream(file.getAbsolutePath()));
		return d.getImage();
	}

	try {
		result = forOpenGL ? ImageIO.read(file) : toCompatibleImage(ImageIO.read(file));
	} catch (final Exception e) {
		return getNoImage();
	}
	return result;
}
 
Example 10
Source File: JaiDewarper.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
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
Source File: TestWarp.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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
Source File: OrbitTiledImage2.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
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 13
Source File: ImageCompareUtil.java    From qaf with 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 14
Source File: Sentinel2Image.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
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 15
Source File: Utils.java    From pdfxtk with 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(); 
    }