javax.media.jai.InterpolationNearest Java Examples

The following examples show how to use javax.media.jai.InterpolationNearest. 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: RasterDataAdapter.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected static byte interpolationToByte(final Interpolation interpolation) {
  // this is silly because it seems like a translation JAI should provide,
  // but it seems its not provided and its the most efficient approach
  // (rather than serializing class names)
  if (interpolation instanceof InterpolationNearest) {
    return Interpolation.INTERP_NEAREST;
  }
  if (interpolation instanceof InterpolationBilinear) {
    return Interpolation.INTERP_BILINEAR;
  }
  if (interpolation instanceof InterpolationBicubic2) {
    return Interpolation.INTERP_BICUBIC_2;
  }

  return Interpolation.INTERP_BICUBIC;
}
 
Example #2
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 #3
Source File: InterpolationValues.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Populate interpolation map. */
private static synchronized void populateInterpolation() {
    if (interpolationMap == null) {
        interpolationMap = new LinkedHashMap<>();
        interpolationMap.put(InterpolationNearest.class, "Nearest Neighbour");
        interpolationMap.put(InterpolationBicubic.class, "Bicubic");
        interpolationMap.put(InterpolationBicubic2.class, "Bicubic2");
        interpolationMap.put(InterpolationBilinear.class, "Bilinear");
    }
}
 
Example #4
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 #5
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 #6
Source File: TestImage3.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
public TestImage3()
{
    JFrame frame = new JFrame(getClass().getName());
    Container pane = frame.getContentPane();
    pane.setLayout(new BorderLayout());

    pane.add(this);

    image = decodeImage(new String[] {
            "#-###############",
            "-----------------",
            "#################",
            "-----------------",
            "#################",
            "-----------------",
            "#################",
            "-----------------",
            "#################",
            "-----------------",
            "#################",
            "-----------------",
            "-----------------",
            "-----------------",
            "---####----------",
            "-------##--------",
            "---------####----",
            "-------------#---",
            "-------------#---",
            "-----------------",
            "--#############--",
            "--#############--",
            "--#############--",
            "--#############--",
            "--#############--",
            "--#############--",
            "--#############--",
            "--#############--",
            "--#############--",
            "--#############--",
            "--#############--",
            "-----------------",
            "-----------------",
            "---####----------",
            "-------##--------",
            "---------####----",
            "-------------#---",
            "-------------#---",
            "-----------------",
            "--#############--",
            "--#############--",
            "-----------------",
            "-----------------"
    });

    //        checkImageFormat();

    ImageInfo.print(image);

    // Scaling
    final float scale = 1f;
    ParameterBlock pb = new ParameterBlock()
        .addSource(image)
        .add(scale)
        .add(scale)
        .add(0f)
        .add(0f)
        .add(new InterpolationNearest());
    image = JAI.create("scale", pb);
    dumpPixels(0, 0, 5, 7);

    if (false) {
        System.out.println("\nBand Selection");
        image = JAI.create("bandselect",image,new int[] {0, 1, 2});
        ImageInfo.print(image);
        dumpPixels(0, 0, 5, 7);
    }

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocation(100, 100);
    frame.pack();
    frame.setSize(100, 250);
    frame.setVisible(true);
}
 
Example #7
Source File: DistributedRenderOptions.java    From geowave with Apache License 2.0 4 votes vote down vote up
public DistributedRenderOptions(
    final WMS wms,
    final WMSMapContent mapContent,
    final Style style) {
  optimizeLineWidth = DefaultWebMapService.isLineWidthOptimizationEnabled();
  maxFilters = DefaultWebMapService.getMaxFilterRules();

  transparent = mapContent.isTransparent();
  buffer = mapContent.getBuffer();
  angle = mapContent.getAngle();
  mapWidth = mapContent.getMapWidth();
  mapHeight = mapContent.getMapHeight();
  bgColor = mapContent.getBgColor();
  palette = mapContent.getPalette();
  renderScaleMethodAccurate =
      StreamingRenderer.SCALE_ACCURATE.equals(mapContent.getRendererScaleMethod());
  wmsIterpolationOrdinal = wms.getInterpolation().ordinal();
  maxErrors = wms.getMaxRenderingErrors();
  this.style = style;
  envelope = mapContent.getRenderingArea();

  final GetMapRequest request = mapContent.getRequest();
  final Object timeoutOption = request.getFormatOptions().get("timeout");
  int localMaxRenderTime = 0;
  if (timeoutOption != null) {
    try {
      // local render time is in millis, while WMS max render time is
      // in seconds
      localMaxRenderTime = Integer.parseInt(timeoutOption.toString()) / 1000;
    } catch (final NumberFormatException e) {
      LOGGER.warn("Could not parse format_option \"timeout\": " + timeoutOption, e);
    }
  }
  maxRenderTime = getMaxRenderTime(localMaxRenderTime, wms);
  isMetatile = request.isTiled() && (request.getTilesOrigin() != null);
  final Object antialiasObj = request.getFormatOptions().get("antialias");
  if (antialiasObj != null) {
    antialias = antialiasObj.toString();
  }

  if (request.getFormatOptions().get("kmplacemark") != null) {
    kmlPlacemark = ((Boolean) request.getFormatOptions().get("kmplacemark")).booleanValue();
  }
  // turn on advanced projection handling
  advancedProjectionHandlingEnabled = wms.isAdvancedProjectionHandlingEnabled();
  final Object advancedProjectionObj =
      request.getFormatOptions().get(WMS.ADVANCED_PROJECTION_KEY);
  if ((advancedProjectionObj != null)
      && "false".equalsIgnoreCase(advancedProjectionObj.toString())) {
    advancedProjectionHandlingEnabled = false;
    continuousMapWrapping = false;
  }
  final Object mapWrappingObj = request.getFormatOptions().get(WMS.ADVANCED_PROJECTION_KEY);
  if ((mapWrappingObj != null) && "false".equalsIgnoreCase(mapWrappingObj.toString())) {
    continuousMapWrapping = false;
  }
  final List<Interpolation> interpolations = request.getInterpolations();
  if ((interpolations == null) || interpolations.isEmpty()) {
    interpolationOrdinals = Collections.emptyList();
  } else {
    interpolationOrdinals =
        Lists.transform(interpolations, new Function<Interpolation, Integer>() {

          @Override
          public Integer apply(final Interpolation input) {
            if (input instanceof InterpolationNearest) {
              return Interpolation.INTERP_NEAREST;
            } else if (input instanceof InterpolationNearest) {
              return Interpolation.INTERP_NEAREST;
            } else if (input instanceof InterpolationNearest) {
              return Interpolation.INTERP_NEAREST;
            } else if (input instanceof InterpolationNearest) {
              return Interpolation.INTERP_NEAREST;
            }
            return Interpolation.INTERP_NEAREST;
          }
        });
  }
}