List of usage examples for java.awt.image RenderedImage getHeight
int getHeight();
From source file:fr.gael.dhus.datastore.processing.impl.ProcessingUtils.java
/** * Cut the quicklook that have a big width/height ratio. * Each sub-part is dispatched on multiple bands. * * @param quick_look the quick_look to be cut * @param max_ratio the maximum ratio between quick_look width and height. * @param margin the margin between each band. default 5. *//*from w w w . ja v a 2s . c om*/ public static RenderedImage cutQuickLook(RenderedImage input_image, double max_ratio, int margin) { ColorModel color_model = input_image.getColorModel(); if ((color_model == null) && (input_image.getSampleModel() != null)) { color_model = ColorRenderer.createColorModel(input_image.getSampleModel()); } BufferedImage quick_look; try { quick_look = PlanarImage.wrapRenderedImage(input_image).getAsBufferedImage( new Rectangle(input_image.getWidth(), input_image.getHeight()), color_model); } catch (Exception e) { logger.error("Problem getting buffered image.", e); throw new IllegalArgumentException("Problem getting buffered image", e); } if ((quick_look != null) && ((quick_look.getWidth() > 0) && (quick_look.getHeight() > 0))) { //Compute width/height ratio int ql_width = quick_look.getWidth(); int ql_height = quick_look.getHeight(); int ratio = (int) Math.sqrt(Math.max(ql_width, ql_height) / Math.min(ql_width, ql_height)); //Check if the quicklook has a strong width/height ratio if ((ratio < max_ratio) || (ratio <= 1)) return PlanarImage.wrapRenderedImage(quick_look); /** * Cut the wider side (width or height) into "ratio" bands. * Ex: If height = 3 * width then we cut 3 bands along columns * So height' = height / 3 (extract 1 band / 3 from height) * width' = width * 3 (dispatch 3 bands along lines) */ int width = ql_width; //width of the bands int height = ql_height; //height of the bands if (ql_width < ql_height) //cut along height { width = (ql_width + margin) * ratio; height = ql_height / ratio; } else //cut along width { width = ql_width / ratio; height = (ql_height + margin) * ratio; } //Dispatch the sub-parts BufferedImage quick_look_cut = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = quick_look_cut.createGraphics(); for (int k = 0; k < ratio; k++) { BufferedImage ql_band = null; //Dispatch on columns if (ql_width < ql_height) { ql_band = quick_look.getSubimage(0, (k * ql_height) / ratio, ql_width, ql_height / ratio); g2.drawImage(ql_band, null, k * (ql_width + margin), 0); } //Dispatch on lines else { ql_band = quick_look.getSubimage((k * ql_width) / ratio, 0, ql_width / ratio, ql_height); g2.drawImage(ql_band, null, 0, k * (ql_height + margin)); } } //for each band g2.dispose(); return PlanarImage.wrapRenderedImage(quick_look_cut); } return PlanarImage.wrapRenderedImage(quick_look); }
From source file:com.bc.ceres.jai.opimage.ReinterpretOpImage.java
private static ImageLayout createTargetImageLayout(RenderedImage source, SampleModel sampleModel) { final int w = source.getWidth(); final int h = source.getHeight(); final ImageLayout imageLayout = new ImageLayout(); imageLayout.setWidth(w);/*w ww . j a va 2 s.c om*/ imageLayout.setHeight(h); imageLayout.setSampleModel(sampleModel); return imageLayout; }
From source file:fr.gael.dhus.datastore.processing.impl.ProcessingUtils.java
public static RenderedImage ResizeImage(RenderedImage image, int width, int height, float max_ratio, boolean can_cut) { RenderedImage resizedImage = image; /*/*from w ww . j a v a 2s . c o m*/ // Select the displayable bands if (resizedImage.getNumBands () <= 2) { logger.debug("Grayscale image case"); resizedImage = JAI.create("bandselect", resizedImage, new int[] { 0 }); } else { logger.debug("RGB image case: [1 2 3]"); resizedImage = JAI.create("bandselect", resizedImage, new int[] {0, 1, 2}); } */ // Cut image if necessary if (can_cut == true) { resizedImage = ProcessingUtils.cutQuickLook(resizedImage, 2.0, 2); logger.debug("Image resized and cutted in band : " + resizedImage.getWidth() + "x" + resizedImage.getHeight()); } // Computes ratio and scale float scale = 1; if (resizedImage.getWidth() >= resizedImage.getHeight()) { scale = (float) ((double) width / (double) resizedImage.getWidth()); } else { scale = (float) ((double) height / (double) resizedImage.getHeight()); } // 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()); if ((width != resizedImage.getWidth()) && (height != resizedImage.getHeight())) { logger.debug("Final resize to complete expected image output"); resizedImage = ResizeImage(resizedImage, width, height, 0, false); } else { pb = new ParameterBlock().addSource(resizedImage); pb.add(new float[] { 0.002f }); // normalize factor 0.02% pb.add(null); // visible region pb.add(4); // x period pb.add(4); // y period resizedImage = JAI.create("normalize", pb); /* Does not work because of color model issue resizedImage = ColorQuantizerDescriptor.create( resizedImage, ColorQuantizerDescriptor.OCTTREE, new Integer(255), new Integer(300), null, new Integer(4), new Integer(4), null); */ } return resizedImage; }
From source file:it.geosolutions.imageio.plugins.nitronitf.NITFImageWriter.java
/** * /* www. ja v a 2 s . com*/ * @param imageWrapper * @param subheader * @param compression * @param fis * @return * @throws IOException * @throws NITFException */ private static double initImageSubHeader(final ImageWrapper imageWrapper, final ImageSubheader subheader, final WriteCompression compression, final FileImageInputStreamExt fis) throws IOException, NITFException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Populating ImageSubHeader"); } final RenderedImage ri = imageWrapper.getImage(); final List<String> comments = imageWrapper.getComments(); // Setting up rows, cols, blocks, bits properties final boolean isJP2 = compression != null && compression != WriteCompression.UNCOMPRESSED; final int nCols = ri.getWidth(); final int nRows = ri.getHeight(); final int nBits = ri.getSampleModel().getSampleSize(0); final String numBlocksPerRow = isJP2 ? String.valueOf((int) Math.ceil((double) nCols / NITFUtilities.DEFAULT_TILE_WIDTH)) : String.valueOf(1); final String numBlocksPerCol = isJP2 ? String.valueOf((int) Math.ceil((double) nRows / NITFUtilities.DEFAULT_TILE_HEIGHT)) : String.valueOf(1); final String numPixelsPerVertBlock = isJP2 ? String.valueOf(NITFUtilities.DEFAULT_TILE_HEIGHT) : "0000"; // As per specification final String numPixelsPerHorizBlock = isJP2 ? String.valueOf(NITFUtilities.DEFAULT_TILE_WIDTH) : "0000"; // As per specification double ratio = Double.NaN; NITFUtilities.setField("IM", subheader.getFilePartType(), "IM"); NITFUtilities.setField("IID1", subheader.getImageId(), imageWrapper.getId()); NITFUtilities.setField("IDATIM", subheader.getImageDateAndTime(), imageWrapper.getDateTime()); NITFUtilities.setField("IID2", subheader.getImageTitle(), imageWrapper.getTitle()); NITFUtilities.setField("ISCLAS", subheader.getImageSecurityClass(), imageWrapper.getSecurityClassification()); NITFUtilities.setField("ISCLSY", subheader.getSecurityGroup().getClassificationSystem(), imageWrapper.getSecurityClassificationSystem()); NITFUtilities.setField("ENCRYP", subheader.getEncrypted(), Integer.toString(imageWrapper.getEncrypted())); NITFUtilities.setField("ISORCE", subheader.getImageSource(), imageWrapper.getSource()); NITFUtilities.setField("NROWS", subheader.getNumRows(), String.valueOf(nRows)); NITFUtilities.setField("NCOLS", subheader.getNumCols(), String.valueOf(nCols)); NITFUtilities.setField("PVTYPE", subheader.getPixelValueType(), NITFUtilities.Consts.DEFAULT_PVTYPE); NITFUtilities.setField("IREP", subheader.getImageRepresentation(), imageWrapper.getRepresentation().toString()); NITFUtilities.setField("ICAT", subheader.getImageCategory(), imageWrapper.getImageCategory().toString()); NITFUtilities.setField("ABPP", subheader.getActualBitsPerPixel(), Integer.toString(nBits)); NITFUtilities.setField("PJUST", subheader.getPixelJustification(), imageWrapper.getPixelJustification()); NITFUtilities.setField("ICORDS", subheader.getImageCoordinateSystem(), imageWrapper.getImageCoordinateSystem()); NITFUtilities.setField("IGEOLO", subheader.getCornerCoordinates(), imageWrapper.getIgeolo()); if (comments != null && !comments.isEmpty()) { int i = 0; for (String comment : comments) { subheader.insertImageComment(comment, i++); } } ratio = setImageCompression(subheader, compression, ri, fis); setImageBands(subheader, imageWrapper); NITFUtilities.setField("ISYNC", subheader.getImageSyncCode(), NITFUtilities.Consts.ZERO); NITFUtilities.setField("IMODE", subheader.getImageMode(), NITFUtilities.Consts.DEFAULT_IMODE); NITFUtilities.setField("NBPR", subheader.getNumBlocksPerRow(), numBlocksPerRow); NITFUtilities.setField("NBPC", subheader.getNumBlocksPerCol(), numBlocksPerCol); NITFUtilities.setField("NPPBH", subheader.getNumPixelsPerHorizBlock(), numPixelsPerHorizBlock); NITFUtilities.setField("NPPBV", subheader.getNumPixelsPerVertBlock(), numPixelsPerVertBlock); NITFUtilities.setField("NBPP", subheader.getNumBitsPerPixel(), Integer.toString(nBits)); NITFUtilities.setField("IDLVL", subheader.getImageDisplayLevel(), NITFUtilities.Consts.ONE); NITFUtilities.setField("IALVL", subheader.getImageAttachmentLevel(), NITFUtilities.Consts.ZERO); NITFUtilities.setField("ILOC", subheader.getImageLocation(), NITFUtilities.Consts.ZERO); NITFUtilities.setField("IMAG", subheader.getImageMagnification(), imageWrapper.getImageMagnification()); return ratio; }
From source file:org.geopublishing.atlasStyler.classification.RasterClassification.java
/** * This is where the magic happens. Here the attributes of the features are * summarized in a {@link DynamicBin1D} class. * /*from w ww . ja v a 2s . c o m*/ * @throws IOException */ @Override synchronized public DynamicBin1D getStatistics() throws InterruptedException, IOException { cancelCalculation.set(false); if (stats == null) { GridCoverage2D coverage = getStyledRaster().getGeoObject().read(null); stats = new DynamicBin1D(); noDataValuesCount.set(0); final RenderedImage rim = coverage.getRenderedImage(); long size = Long.valueOf(rim.getHeight()) * Long.valueOf(rim.getWidth()); long maxPixels = 3000000l; if (size > maxPixels) { setSubsampling((int) (size / maxPixels)); LOGGER.info("Subsampling to every " + getSubsampling() + " pixel"); } for (int row = 0; row < rim.getHeight(); row++) { if (row % getSubsampling() != 0) { // Skipping this line for Subsampling continue; } else { // DO // System.out.println(""); } int x1 = 0; int w = rim.getWidth(); int y1 = row; int h = 1; Raster data = rim.getData(new Rectangle(x1, y1, w, h)); double[] values = data.getSamples(0, y1, w, h, getBand(), (double[]) null); final DoubleArrayList doubleArrayList = new DoubleArrayList(values); if (getStyledRaster().getNodataValue() != null) { int sizewithNodata = doubleArrayList.size(); doubleArrayList .removeAll(new DoubleArrayList(new double[] { getStyledRaster().getNodataValue() })); noDataValuesCount.addAndGet(sizewithNodata - doubleArrayList.size()); } stats.addAllOf(doubleArrayList); // LOGGER.debug("Added "+doubleArrayList.size()+" to statistics"); // LOGGER.debug(stats.size()+" in stats"); doubleArrayList.clear(); } } return stats; }
From source file:fr.gael.dhus.datastore.processing.ProcessingUtils.java
public static RenderedImage resizeImage(RenderedImage image, int width, int height, float max_ratio, boolean can_cut) { RenderedImage resizedImage = image; /*//from w w w.j ava2s . co m // Select the displayable bands if (resizedImage.getNumBands () <= 2) { logger.debug("Grayscale image case"); resizedImage = JAI.create("bandselect", resizedImage, new int[] { 0 }); } else { logger.debug("RGB image case: [1 2 3]"); resizedImage = JAI.create("bandselect", resizedImage, new int[] {0, 1, 2}); } */ // Cut image if necessary if (can_cut == true) { resizedImage = ProcessingUtils.cutQuickLook(resizedImage, 2.0, 2); logger.debug("Image resized and cutted in band : " + resizedImage.getWidth() + "x" + resizedImage.getHeight()); } // Computes ratio and scale float scale = 1; if (resizedImage.getWidth() >= resizedImage.getHeight()) { scale = (float) ((double) width / (double) resizedImage.getWidth()); } else { scale = (float) ((double) height / (double) resizedImage.getHeight()); } // 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()); if ((width != resizedImage.getWidth()) && (height != resizedImage.getHeight())) { logger.debug("Final resize to complete expected image output"); resizedImage = resizeImage(resizedImage, width, height, 0, false); } else { pb = new ParameterBlock().addSource(resizedImage); pb.add(new float[] { 0.002f }); // normalize factor 0.02% pb.add(null); // visible region pb.add(4); // x period pb.add(4); // y period resizedImage = JAI.create("normalize", pb); /* Does not work because of color model issue resizedImage = ColorQuantizerDescriptor.create( resizedImage, ColorQuantizerDescriptor.OCTTREE, new Integer(255), new Integer(300), null, new Integer(4), new Integer(4), null); */ } return resizedImage; }
From source file:it.geosolutions.imageio.plugins.nitronitf.NITFImageWriter.java
/** * Setup Image Compression related fields depending on the compression properties. * /*from w w w. jav a2 s . c om*/ * @param subheader the {@link ImageSubheader} to be set * @param compression the specified {@link WriteCompression} * @param isJP2 whether a JP2 * @param ri the renderedImage * @param fis * @return * @throws IOException */ private static double setImageCompression(final ImageSubheader subheader, final WriteCompression compression, final RenderedImage ri, final FileImageInputStreamExt fis) throws IOException { double ratio = Double.NaN; final int numBits = ri.getSampleModel().getSampleSize(0); if (compression != null && compression != WriteCompression.UNCOMPRESSED) { // Setting up compression type and compression ratio NITFUtilities.setField("IC", subheader.getImageCompression(), NITFUtilities.Consts.COMPRESSION_JP2); if (fis != null) { final long codeStreamSize = fis.length(); final long imageSize = ri.getWidth() * ri.getHeight() * ri.getSampleModel().getNumBands(); ratio = codeStreamSize / (double) (imageSize / (double) numBits); } String comrat = ""; if (compression.getCompression() == Compression.NUMERICALLY_LOSSLESS) { String ratioString = Double.toString(ratio); ratioString = ratioString.replace(".", ""); ratioString = ratioString.replace(",", ""); ratioString = "N0" + ratioString.substring(0, 2); // ImproveMe comrat = ratioString; } else if (compression == WriteCompression.RATIO_15_1) { // Wait for NGA feedbacks to fix this value comrat = NITFUtilities.Consts.COMPRESSION_L005; } else if (compression.toString().endsWith("VL")) { // Visually lossless uses a static value comrat = NITFUtilities.Consts.COMPRESSION_V039; } NITFUtilities.setField("COMRAT", subheader.getCompressionRate(), comrat); } else { NITFUtilities.setField("IC", subheader.getImageCompression(), NITFUtilities.Consts.COMPRESSION_NONE); } return ratio; }
From source file:org.geomajas.plugin.rasterizing.layer.RasterDirectLayer.java
/** * Converts an image to a RGBA direct color model using a workaround via buffered image directly calling the * ColorConvert operation fails for unknown reasons ?! * // ww w.j a va 2s . c o m * @param img image to convert * @return converted image */ public PlanarImage toDirectColorModel(RenderedImage img) { BufferedImage dest = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); BufferedImage source = new BufferedImage(img.getColorModel(), (WritableRaster) img.getData(), img.getColorModel().isAlphaPremultiplied(), null); ColorConvertOp op = new ColorConvertOp(null); op.filter(source, dest); return PlanarImage.wrapRenderedImage(dest); }
From source file:com.alibaba.simpleimage.util.ImageLog.java
protected String formatMsg(Object action, RenderedImage img) { String msgFmt = action + ": {0}={1} DataType={2} Width={3} Height={4}"; String clazz = img.getColorModel().getColorSpace().getClass().getSimpleName(); int type = img.getColorModel().getColorSpace().getType(); int dataType = img.getData().getDataBuffer().getDataType(); int w = img.getWidth(); int h = img.getHeight(); String msg = MessageFormat.format(msgFmt, clazz, getColorSpaceName(type), getDataTypeName(dataType), w, h); return msg;//from w ww . j a v a 2 s. c o m }
From source file:com.enonic.vertical.adminweb.handlers.xmlbuilders.ContentEnhancedImageXMLBuilder.java
private int[] generateCustomSize(RenderedImage origImage, SizeData sd) throws VerticalAdminException { float[] customSize = new float[2]; String type = sd.customType;/*from w w w .java 2 s. c om*/ String value = null; if (value == null) { value = String.valueOf(sd.customValue); } if ("max".equals(type)) { if (origImage.getWidth() > origImage.getHeight()) { type = "width"; } else { type = "height"; } } if (type.equals("width")) { customSize[0] = Float.parseFloat(value); double ratio = customSize[0] / origImage.getWidth(); customSize[1] = Math.round(ratio * origImage.getHeight()); } else if (type.equals("height")) { customSize[1] = Float.parseFloat(value); double ratio = customSize[1] / origImage.getHeight(); customSize[0] = Math.round(ratio * origImage.getWidth()); } return new int[] { (int) customSize[0], (int) customSize[1] }; }