本文整理汇总了Java中java.awt.image.DataBufferUShort.getData方法的典型用法代码示例。如果您正苦于以下问题:Java DataBufferUShort.getData方法的具体用法?Java DataBufferUShort.getData怎么用?Java DataBufferUShort.getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.DataBufferUShort
的用法示例。
在下文中一共展示了DataBufferUShort.getData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readTileXY
import java.awt.image.DataBufferUShort; //导入方法依赖的package包/类
/**
*
* @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;
}
示例2: read
import java.awt.image.DataBufferUShort; //导入方法依赖的package包/类
/**
*
* @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;
}
示例3: read
import java.awt.image.DataBufferUShort; //导入方法依赖的package包/类
/**
*
* @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;
}
示例4: read
import java.awt.image.DataBufferUShort; //导入方法依赖的package包/类
/**
*
* @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;
}
示例5: decode
import java.awt.image.DataBufferUShort; //导入方法依赖的package包/类
@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");
}
}
示例6: WritePNGfile
import java.awt.image.DataBufferUShort; //导入方法依赖的package包/类
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();
}
}
示例7: extractImageData
import java.awt.image.DataBufferUShort; //导入方法依赖的package包/类
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;
}
示例8: main
import java.awt.image.DataBufferUShort; //导入方法依赖的package包/类
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();
}
示例9: getPixelValues
import java.awt.image.DataBufferUShort; //导入方法依赖的package包/类
/**
* 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;
}