gpt4 book ai didi

java - 如何在java中将16位、tiff、灰度图像转换为32位、tiff、灰度图像?

转载 作者:行者123 更新时间:2023-12-01 04:57:10 27 4
gpt4 key购买 nike

我正在使用 netbeans 平台用 java 制作 DesktopApp。在我的应用程序中,我使用 16 位、tiff、灰度图像并对该图像进行处理。现在,我想使用 16 位、tiff、灰度图像(或 16 位图像的数据)制作 32 位、tiff、灰度图像。那么如何在 java 中将 16 位图像转换为 32 位图像?

最佳答案

您需要做的是将其传递给图像处理器对象,然后对其进行校准。可能是这样的:

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 位。不过请记住导入正确的 jar 。

关于java - 如何在java中将16位、tiff、灰度图像转换为32位、tiff、灰度图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13910645/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com