当前位置: 首页>>代码示例>>Java>>正文


Java DicomObject.putShorts方法代码示例

本文整理汇总了Java中org.dcm4che2.data.DicomObject.putShorts方法的典型用法代码示例。如果您正苦于以下问题:Java DicomObject.putShorts方法的具体用法?Java DicomObject.putShorts怎么用?Java DicomObject.putShorts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.dcm4che2.data.DicomObject的用法示例。


在下文中一共展示了DicomObject.putShorts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.dcm4che2.data.DicomObject; //导入方法依赖的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();
}
 
开发者ID:Sofd,项目名称:viskit,代码行数:51,代码来源:AddGridToDcmImageApp.java

示例2: paintGrayscaleInto

import org.dcm4che2.data.DicomObject; //导入方法依赖的package包/类
public void paintGrayscaleInto(DicomObject image, int scaleHeight) {
    int bitsAllocated = image.getInt(Tag.BitsAllocated);
    if (bitsAllocated <= 0) {
        throw new IllegalStateException("unsupported image");
    }
    int bitsStored = image.getInt(Tag.BitsStored);
    if (bitsStored <= 0) {
        throw new IllegalStateException("unsupported image");
    }
    boolean isSigned = (1 == image.getInt(Tag.PixelRepresentation));
    if (isSigned) {
        throw new IllegalStateException("unsupported image");
    }
    // TODO: return null if compressed
    // TODO: support for RGB (at least don't misinterpret it as luminance)
    // TODO: account for endianness (Tag.HighBit)
    // TODO: maybe use static multidimensional tables instead of nested switch statements
    switch (bitsAllocated) {
        case 8:
            throw new IllegalStateException("unsupported image");
        case 16:
            switch (bitsStored) {
                case 12:
                    //=> 12-bit unsigned
                    break;
                case 16:
                    throw new IllegalStateException("unsupported image");
                    //pixelType = (isSigned ? RawImage.PIXEL_TYPE_SIGNED_16BIT : RawImage.PIXEL_TYPE_UNSIGNED_16BIT);
                    //break;
                default:
                    throw new IllegalStateException("unsupported image");
            }
            break;
        default:
            throw new IllegalStateException("unsupported image");
    }
    int width = image.getInt(Tag.Columns);
    int height = image.getInt(Tag.Rows);

    short[] pixels = image.getShorts(Tag.PixelData);
    for (short gray=0; gray<4096; gray++) {
        int x = gray % width;
        int row = gray / width;
        int ystart = row * 3 * scaleHeight;
        short gray8 = (short)(gray / 16 * 16);
        for (int dy=0; dy<scaleHeight; dy++) {
            int grayy = ystart + dy;
            int gray8y = ystart + scaleHeight + dy;
            pixels[grayy*width + x] = gray;
            pixels[gray8y*width + x] = gray8;
        }
    }
    image.putShorts(Tag.PixelData, image.vrOf(Tag.PixelData), pixels);
}
 
开发者ID:Sofd,项目名称:viskit,代码行数:55,代码来源:PaintGrayscaleIntoDcmImageApp.java

示例3: paintGraysInto

import org.dcm4che2.data.DicomObject; //导入方法依赖的package包/类
public void paintGraysInto(DicomObject image, int grayNW, int grayNE, int graySE, int graySW) {
    int bitsAllocated = image.getInt(Tag.BitsAllocated);
    if (bitsAllocated <= 0) {
        throw new IllegalStateException("unsupported image");
    }
    int bitsStored = image.getInt(Tag.BitsStored);
    if (bitsStored <= 0) {
        throw new IllegalStateException("unsupported image");
    }
    boolean isSigned = (1 == image.getInt(Tag.PixelRepresentation));
    if (isSigned) {
        throw new IllegalStateException("unsupported image");
    }
    // TODO: return null if compressed
    // TODO: support for RGB (at least don't misinterpret it as luminance)
    // TODO: account for endianness (Tag.HighBit)
    // TODO: maybe use static multidimensional tables instead of nested switch statements
    switch (bitsAllocated) {
        case 8:
            throw new IllegalStateException("unsupported image");
        case 16:
            switch (bitsStored) {
                case 12:
                    //=> 12-bit unsigned
                    break;
                case 16:
                    throw new IllegalStateException("unsupported image");
                    //pixelType = (isSigned ? RawImage.PIXEL_TYPE_SIGNED_16BIT : RawImage.PIXEL_TYPE_UNSIGNED_16BIT);
                    //break;
                default:
                    throw new IllegalStateException("unsupported image");
            }
            break;
        default:
            throw new IllegalStateException("unsupported image");
    }
    int width = image.getInt(Tag.Columns);
    int height = image.getInt(Tag.Rows);

    short[] pixels = image.getShorts(Tag.PixelData);
    for (int y=0; y<height; y++) {
        for (int x=0; x<width; x++) {
            float grayTop = (float) grayNW * (1.0f - (float) x/width) + (float) grayNE * x/width;
            float grayBottom = (float) graySW * (1.0f - (float) x/width) + (float) graySE * x/width;
            float gray = (float) grayTop * (1.0f - (float) y/height) + (float) grayBottom * y/height;
            pixels[y*width + x] = (short)gray;
        }
    }
    image.putShorts(Tag.PixelData, image.vrOf(Tag.PixelData), pixels);
}
 
开发者ID:Sofd,项目名称:viskit,代码行数:51,代码来源:PaintGrayDcmImageApp.java


注:本文中的org.dcm4che2.data.DicomObject.putShorts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。