Java Code Examples for java.awt.image.DataBufferUShort.getData()

The following are Jave code examples for showing how to use getData() of the java.awt.image.DataBufferUShort class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: sumo   File: Sentinel1GRD.java   Source Code and License Vote up 6 votes
/**
* 
* @param x
* @param y
* @param width
* @param height
* @param band
* @return
*/
 public int readTileXY(int x, int y, int band) {
     Rectangle rect = new Rectangle(x, y, 1, 1);
     int val=0;

     	if (y < 0||y>this.getHeight()||x<0||x>this.getWidth()) {
           val= 0;
     	}else{
        TIFF tiff=(TIFF)getImage(band);
        try {
        	BufferedImage bi=null;
       		bi=tiff.read(0, rect);
       		DataBufferUShort raster=(DataBufferUShort)bi.getRaster().getDataBuffer();
       		short[] b=raster.getData();
        	//short[] data=(short[])raster.getDataElements(0, 0, width,height, null);
        	val=b[0];
        } catch (Exception ex) {
            logger.error(ex.getMessage(),ex);
        }
     	}  
     
     return val;
 }
 
Example 2
Project: sumo   File: Alos.java   Source Code and License Vote up 6 votes
/**
*
* @param x
* @param y
* @param width
* @param height
* @param band
* @return
*/
public int[] read(int x, int y,int w,int h, int band) {
 TIFF tiff=(TIFF)getImage(band);
    Rectangle rect = new Rectangle(x, y, w, h);
    rect = rect.intersection(tiff.getBounds());
    int data[]=null;

     try {
      	BufferedImage bi=null;
  		bi=tiff.read(0, rect);
  		DataBufferUShort raster=(DataBufferUShort)bi.getRaster().getDataBuffer();
  		short[] b=raster.getData();
  		data=new int[b.length];
      	for(int i=0;i<b.length;i++)
      		data[i]=b[i];

     } catch (Exception ex) {
         logger.warn(ex.getMessage());
     }

    return data;
}
 
Example 3
Project: sumo   File: AlosGeoTiff.java   Source Code and License Vote up 6 votes
/**
*
* @param x
* @param y
* @param width
* @param height
* @param band
* @return
*/
public int[] read(int x, int y,int w,int h, int band) {
    Rectangle rect = new Rectangle(x, y, w, h);
    rect = rect.intersection(getImage(band).getBounds());
    int data[]=null;

     TIFF tiff=getImage(band);
     try {
     	BufferedImage bi=null;
 		bi=tiff.read(0, rect);
 		DataBufferUShort raster=(DataBufferUShort)bi.getRaster().getDataBuffer();
 		short[] b=raster.getData();
 		data=new int[b.length];
     	for(int i=0;i<b.length;i++)
     		data[i]=b[i];

     } catch (Exception ex) {
         logger.warn(ex.getMessage());
     }finally{
     }

    return data;
}
 
Example 4
Project: sumo   File: Sentinel1.java   Source Code and License Vote up 5 votes
/**
*
* @param x
* @param y
* @param width
* @param height
* @param band
* @return
*/
public int[] read(int x, int y,int w,int h, int band) {
    Rectangle rect = new Rectangle(x, y, w, h);
    rect = rect.intersection(getImage(band).getBounds());
    int data[]=null;

     TIFF tiff=(TIFF)getImage(band);
     BufferedImage bi=null;
     try {
     	bi=tiff.read(0, rect);
     } catch (Exception ex) {
     	try {
     		//try again
     		Thread.sleep(100);
	bi=tiff.read(0, rect);
} catch (IOException | InterruptedException e) {
	logger.warn(ex.getMessage());
}
     }finally{
     }
     if(bi!=null){
DataBufferUShort raster=(DataBufferUShort)bi.getRaster().getDataBuffer();
short[] b=raster.getData();
data=new int[b.length];
  	for(int i=0;i<b.length;i++)
  		data[i]=b[i];
     }
    return data;
}
 
Example 5
Project: sambox   File: JPXFilter.java   Source Code and License Vote up 5 votes
@Override
public DecodeResult decode(InputStream encoded, OutputStream decoded, COSDictionary parameters,
        int index) throws IOException
{
    DecodeResult result = new DecodeResult(new COSDictionary());
    result.getParameters().addAll(parameters);
    BufferedImage image = readJPX(encoded, result);

    WritableRaster raster = image.getRaster();
    switch (raster.getDataBuffer().getDataType())
    {
    case DataBuffer.TYPE_BYTE:
        DataBufferByte byteBuffer = (DataBufferByte) raster.getDataBuffer();
        decoded.write(byteBuffer.getData());
        return result;

    case DataBuffer.TYPE_USHORT:
        DataBufferUShort wordBuffer = (DataBufferUShort) raster.getDataBuffer();
        for (short w : wordBuffer.getData())
        {
            decoded.write(w >> 8);
            decoded.write(w);
        }
        return result;

    default:
        throw new IOException(
                "Data type " + raster.getDataBuffer().getDataType() + " not implemented");
    }
}
 
Example 6
Project: mochadoom   File: MenuMisc.java   Source Code and License Vote up 5 votes
public static void WritePNGfile(String imagename, short[] linear, int width, int height) {
    BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_555_RGB);
    DataBufferUShort sh = (DataBufferUShort) buf.getRaster().getDataBuffer();
    short[] shd = sh.getData();
    System.arraycopy(linear, 0, shd, 0, Math.min(linear.length, shd.length));
    try {
        ImageIO.write(buf, "PNG", new File(imagename));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 7
Project: MikuMikuStudio   File: AWTLoader.java   Source Code and License Vote up 5 votes
private Object extractImageData(BufferedImage img){
    DataBuffer buf = img.getRaster().getDataBuffer();
    switch (buf.getDataType()){
        case DataBuffer.TYPE_BYTE:
            DataBufferByte byteBuf = (DataBufferByte) buf;
            return byteBuf.getData();
        case DataBuffer.TYPE_USHORT:
            DataBufferUShort shortBuf = (DataBufferUShort) buf;
            return shortBuf.getData();
    }
    return null;
}
 
Example 8
Project: viskit   File: AddGridToDcmImageApp.java   Source Code and License Vote up 4 votes
public static void main(String[] args) throws Exception {
    RawDicomImageReader.registerWithImageIO();

    String fileName = args[0];
    Iterator it = ImageIO.getImageReadersByFormatName("RAWDICOM");
    ImageReader reader = (ImageReader) it.next();
    ImageInputStream iis = ImageIO.createImageInputStream(new FileInputStream(fileName));
    if (null == iis) {
        throw new IllegalStateException("The DICOM image I/O filter (from dcm4che1) must be available to read images.");
    }
    reader.setInput(iis, false);
    DicomImageReadParam param = (DicomImageReadParam) reader.getDefaultReadParam();
    BufferedImage img = reader.read(0, param);
    if (!(img.getRaster().getDataBuffer() instanceof DataBufferUShort)) {
        throw new IllegalStateException("input image must be 16-bit per pixel per chennel (or somesuch)...");
    }
    Graphics2D gr = img.createGraphics();
    final int gridConstant = 10;
    final int thickGridConstant = 50;
    gr.setPaint(Color.WHITE);
    Stroke thinStroke = new BasicStroke(1);
    Stroke thickStroke = new BasicStroke(2);
    for (int x = 0; x < img.getWidth(); x += gridConstant) {
        if (x > 0 && 0 == x % thickGridConstant) {
            gr.setStroke(thickStroke);
        } else {
            gr.setStroke(thinStroke);
        }
        gr.drawLine(x, 0, x, img.getHeight() - 1);
    }
    for (int y = 0; y < img.getHeight(); y += gridConstant) {
        if (y > 0 && 0 == y % thickGridConstant) {
            gr.setStroke(thickStroke);
        } else {
            gr.setStroke(thinStroke);
        }
        gr.drawLine(0, y, img.getWidth() - 1, y);
    }

    DataBufferUShort buffer = (DataBufferUShort) img.getRaster().getDataBuffer();
    short[] pixelData = buffer.getData();
    DicomStreamMetaData dsmd = (DicomStreamMetaData) reader.getStreamMetadata();
    DicomObject dicom = dsmd.getDicomObject();
    dicom.putShorts(Tag.PixelData, dicom.vrOf(Tag.PixelData), pixelData);
    File f = new File(fileName + ".with-grid.dcm");
    FileOutputStream fos = new FileOutputStream(f);
    DicomOutputStream dos = new DicomOutputStream(fos);
    dos.writeDicomFile(dicom);
    dos.close();
}
 
Example 9
Project: geopackage-java   File: ElevationTilesPng.java   Source Code and License Vote up 2 votes
/**
 * Get the pixel values of the raster as "unsigned shorts"
 * 
 * @param raster
 *            image raster
 * @return "unsigned short" pixel values
 */
public short[] getPixelValues(WritableRaster raster) {
	DataBufferUShort buffer = (DataBufferUShort) raster.getDataBuffer();
	short[] pixelValues = buffer.getData();
	return pixelValues;
}