本文整理汇总了Java中ij.process.ShortProcessor.setPixels方法的典型用法代码示例。如果您正苦于以下问题:Java ShortProcessor.setPixels方法的具体用法?Java ShortProcessor.setPixels怎么用?Java ShortProcessor.setPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.process.ShortProcessor
的用法示例。
在下文中一共展示了ShortProcessor.setPixels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertArgbLabelTo16BitGray
import ij.process.ShortProcessor; //导入方法依赖的package包/类
/**
* Converts the specified ARGB label image to a 16-bit gray image.
* Only uses the two lowest order RGB bytes for each pixel (the green and blue values)
* to calculate the pixel's corresponding 16-bit gray value.
*
* @param image ARGB image to convert.
*
* @return a 16-bit gray image.
*/
public static BufferedImage convertArgbLabelTo16BitGray(final BufferedImage image) {
final long startTime = System.currentTimeMillis();
final int width = image.getWidth();
final int height = image.getHeight();
int p = 0;
final short[] convertedPixels = new short[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
convertedPixels[p] = (short) image.getRGB(x, y);
p++;
}
}
final ShortProcessor sp = new ShortProcessor(width, height);
sp.setPixels(convertedPixels);
final long elapsedTime = System.currentTimeMillis() - startTime;
LOG.debug("convertArgbLabelTo16BitGray: converted {} pixels in {} milliseconds", convertedPixels.length, elapsedTime);
return sp.get16BitBufferedImage();
}
示例2: readImagePlusRegion
import ij.process.ShortProcessor; //导入方法依赖的package包/类
@Override
public PathImage<ImagePlus> readImagePlusRegion(RegionRequest request) {
// Create an ImagePlus from a BufferedImage
BufferedImage img = readBufferedImage(request);
ImagePlus imp = null;
SampleModel sampleModel = img.getSampleModel();
int dataType = sampleModel.getDataType();
int w = img.getWidth();
int h = img.getHeight();
if ((dataType == DataBuffer.TYPE_BYTE && sampleModel.getNumBands() != 1) ||
dataType == DataBuffer.TYPE_USHORT || dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_FLOAT || dataType == DataBuffer.TYPE_DOUBLE) {
// Handle non-8-bit images
ImageStack stack = new ImageStack(w, h);
for (int b = 0; b < sampleModel.getNumBands(); b++) {
// Read data as float (no matter what it is)
FloatProcessor fp = new FloatProcessor(w, h);
float[] pixels = (float[])fp.getPixels();
sampleModel.getSamples(0, 0, w, h, b, pixels, img.getRaster().getDataBuffer());
// Convert to 8 or 16-bit, if appropriate
if (dataType == DataBuffer.TYPE_BYTE) {
ByteProcessor bp = new ByteProcessor(w, h);
bp.setPixels(0, fp);
stack.addSlice(bp);
} else if (dataType == DataBuffer.TYPE_USHORT) {
ShortProcessor sp = new ShortProcessor(w, h);
sp.setPixels(0, fp);
stack.addSlice(sp);
} else
stack.addSlice(fp);
}
imp = new ImagePlus(getShortServerName(), stack);
} else
// Create whatever image ImageJ will give us
imp = new ImagePlus(getShortServerName(), img);
imp.setDimensions(imp.getNSlices(), 1, 1);
IJTools.calibrateImagePlus(imp, request, this);
return PathImagePlus.createPathImage(this, request, imp);
}