我使用NetBeans平台在Java中制作DesktopApp。在我的应用程序中,我使用了16位,tiff,灰度图像和对该图像的处理。现在,我想使用16位,tiff,灰度图像(或16位图像的数据)制作32位,tiff,灰度图像。那么我怎样才能将16位图像转换为java中的32位图像?如何将16位,TIFF,灰度图像转换为32位,TIFF,在Java中的灰度图像?
1
A
回答
0
你需要做的是通过一个图像处理器对象,然后校准它。也许有些事情是这样的:
import java.awt.*;
import java.awt.image.*;
import ij.*;
import ij.gui.*;
import ij.measure.*;
/** converting an ImagePlus object to a different type. */
public class ImageConverter {
private ImagePlus imp;
private int type;
private static boolean doScaling = true;
/** Construct an ImageConverter based on an ImagePlus object. */
public ImageConverter(ImagePlus imp) {
this.imp = imp;
type = imp.getType();
}
/** Convert your ImagePlus to 32-bit grayscale. */
public void convertToGray32() {
if (type==ImagePlus.GRAY32)
return;
if (!(type==ImagePlus.GRAY8||type==ImagePlus.GRAY16||type==ImagePlus.COLOR_RGB))
throw new IllegalArgumentException("Unsupported conversion");
ImageProcessor ip = imp.getProcessor();
imp.trimProcessor();
Calibration cal = imp.getCalibration();
imp.setProcessor(null, ip.convertToFloat());
imp.setCalibration(cal); //update calibration
}
/** Set true to scale to 0-255 when converting short to byte or float
to byte and to 0-65535 when converting float to short. */
public static void setDoScaling(boolean scaleConversions) {
doScaling = scaleConversions;
IJ.register(ImageConverter.class);
}
/** Returns true if scaling is enabled. */
public static boolean getDoScaling() {
return doScaling;
}
}
这样你的校正图像被设置为32位,有史以来输入可能是什么。记得要输入正确的罐子。
+0
感谢回复me.But我不想使用ImageJ API。我想使用Java的API而不是第三方API。 – Jay
+0
好吧,如果您正在寻找内置的API,那么请查找BufferedImage类。它所做的是,它将从一个图像获取RGB值并将值存储在另一个图像中。 BufferedImage类然后为你做转换。 –
0
如果您的TIFF加载为一个BufferedImage,可以减少这样说:
BufferedImage convert(BufferedImage image) {
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorModel colorModel = new ComponentColorModel(
colorSpace, false, false, Transparency.OPAQUE,
DataBuffer.TYPE_USHORT);
BufferedImageOp converter = new ColorConvertOp(colorSpace, null);
BufferedImage newImage =
converter.createCompatibleDestImage(image, colorModel);
converter.filter(image, newImage);
return newImage;
}
相关问题
- 1. 在.Net 2.0中将8位灰度tiff图像转换为8位灰度jpg
- 2. 如何在Java中将16位.tiff图像转换为8位.tiff图像?
- 3. 阅读16位灰度TIFF
- 4. 如何将16位灰度图像转换为java中的RGB图像?
- 5. Python将32位转换为16位tiff
- 6. iOS - 如何将png图像转换为4位位图灰度?
- 7. 在java中转换8位灰度RAW图像中的图像
- 8. 将图像转换为灰度图像
- 9. 转换8位灰度级图像以7位灰度级图像
- 10. 着色灰度16位图像
- 11. cvSobel与16位灰度图像
- 12. OpenCV - 读取16位灰度图像
- 13. Emgu Cv和16位灰度图像
- 14. 如何将32位RGBA图像转换为保存灰度图的alpha
- 15. 图像处理 - 在Matlab TIFF图像在灰度
- 16. 将RGB图像转换为灰度和灰度转换为RGB图像?
- 17. 如何将16位灰度图像写入为jpeg?
- 18. 读取16位灰度TIFF文件的像素值(但只有前12位)
- 19. 位图8位灰度图像在C
- 20. MATLAB/Opencv:将24位RGB图像转换为16位灰色
- 21. 如何在C#中将32bpp图像转换为16 bpp图像? (灰度)
- 22. 如何将捕获的位图转换为8位图像作为灰度?
- 23. 16位灰度
- 24. 我如何创建一个16位的灰度图像与java
- 25. 将32bpp位图转换为16bpp(灰度)
- 26. SciPy的:转换RGB TIFF为灰度TIFF和输出它Matplotlib
- 27. 16位图像转换为32位
- 28. 16位灰度png图像的Python图像处理
- 29. 将简单图像转换为灰度
- 30. 将图像转换为灰度
你知道,如果你这样做,你不会得到任何新的数据? –
http://stackoverflow.com/questions/1177059/converting-a-32bpp-image-to-a-16bpp-image-in-java这是储备转换 –
@NikolayKuznetsov感谢您的回复early.Linked给你是为ARGB图像,但是im图像是灰度图像而不是ARGB或RGB。那么我怎么做转换? – Jay