Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在ImageJ中使用ImageProcessor_Java_Image_Imagej - Fatal编程技术网

Java 在ImageJ中使用ImageProcessor

Java 在ImageJ中使用ImageProcessor,java,image,imagej,Java,Image,Imagej,我不熟悉java和imageJ。我已经加载了一个图像并获得了一个名为imgproc的图像处理器。我在图像中找到了包围特征的边界/框。外面只是背景。我还找到了这个区域的像素矩阵。现在我尝试只处理图像中的这个区域。要使用以前的现有代码(方法)实现这一点,我的输入参数应该是ImageProcessor。因此,我最初的想法是使用duplicate()方法复制imgproc。然后使用resize方法将其缩小到我以前找到的框的大小。但这不起作用,因为我用show-image方法进行了测试,我必须显示它。我得

我不熟悉java和imageJ。我已经加载了一个图像并获得了一个名为imgproc的图像处理器。我在图像中找到了包围特征的边界/框。外面只是背景。我还找到了这个区域的像素矩阵。现在我尝试只处理图像中的这个区域。要使用以前的现有代码(方法)实现这一点,我的输入参数应该是ImageProcessor。因此,我最初的想法是使用duplicate()方法复制imgproc。然后使用resize方法将其缩小到我以前找到的框的大小。但这不起作用,因为我用show-image方法进行了测试,我必须显示它。我得到的只是一张缩小的黑色照片。这个最初的想法被编码在这里:

ImageProcessor Whiteimproc=imgproc.duplicate();
ImageProcessor BWhiteimproc=Whiteimproc.resize(BWhiteMatrix.length,BWhiteMatrix[0].length);
BWhiteimproc.setIntArray(BWhiteMatrix);
//the next three lines are going to show the image
Image ImagetoShow=BWhiteimproc.createImage();
Img ShowImg= new Img();
ShowImg.imgFrame(ImagetoShow,"BWhite");`
然后我尝试使用ImagePlus并创建一个新的ImageProcessor。它成功了。如下图所示:

ImagePlus imgWhite=IJ.createImage("white","jpg",BWhiteMatrix.length,BWhiteMatrix[0].length,1);
ImageProcessor BWhiteimproc=imgWhite.getProcessor();
BWhiteimproc.setIntArray(BWhiteMatrix);
//the next three lines are going to show the image
Image ImagetoShow=BWhiteimproc.createImage();
Img ShowImg= new Img();
ShowImg.imgFrame(ImagetoShow,"BWhite");
有人能帮我吗?为什么?我知道为什么我不能使用ImageProcessor来定义ImageProcessor类的新对象


谢谢

我不确定,但第一种方法可能不起作用,因为图像处理器的类型与第二种方法不同。尝试使用
BWhiteimproc.getClass().getName()
检查ImageProcessors的运行时类型

ImageProcessor#setIntArray(int[])
对不同类型的图像执行不同的操作。对于32位图像,它调用
Float.intBitsToFloat(int)
,因此如果int值为100,则保存的浮点值将为+0e100(浮点的最后8位为指数),即零。对于8位和16位图像,它将int转换为精度较低的类型(byte和short)

我知道为什么我不能用ImageProcessor来定义一个新的 ImageProcessor类的对象

ImageProcessor是一个抽象类。不能创建抽象类的实例。请使用以下子类之一:

  • 用于8位灰度图像的ByteProcessor
  • 用于16位灰度图像的短处理器
  • 用于32位浮点灰度图像的浮点处理器
  • RGB图像的彩色处理器

您在这里混合了各种类别:
ImagePlus
ImageProcessor
属于核心ImageJ,但是您从哪里导入
Image
Img
?我建议大家学习一些入门教程。约瑟夫,谢谢。我将尝试你的建议,可能需要阅读更多关于这方面的内容。