我对java和imageJ很陌生。我已经加载了一个映像并获得了一个ImageProcessor,我称之为imgproc。我在环绕这些特征的图像中找到了边界/框。外面只是背景。我还找到了这个区域的像素矩阵。现在我只想在图像中处理这个区域。要用以前的现有代码(方法)来实现这一点,我的输入参数应该是ImageProcessor。因此,我最初的想法是使用复制()方法创建imgproc的副本。并使用调整大小的方法将其缩小到我之前发现的框的大小。但这是行不通的,因为我用一种显示图像的方法进行了测试,我必须显示它。我得到的只是一张缩小的黑色照片。这个最初的想法被编码在这里:
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类的新对象。
谢谢
发布于 2013-07-31 09:06:28
我不确定,但第一种方法可能行不通,因为ImageProcessor的类型与第二种方法的类型不同。尝试使用ImageProcessors检查BWhiteimproc.getClass().getName()的运行时类型。
ImageProcessor#setIntArray(int[][])为不同类型的图像做了不同的事情。对于32位图像,它调用Float.intBitsToFloat(int),因此如果int值为100,则保存的浮点数为+0e100 (浮点数的最后8位为指数),为零。对于8位和16位图像,它将int转换为不太精确的类型(字节和简短)。
我知道为什么不能使用ImageProcessor来定义ImageProcessor类的新对象。
ImageProcessor是一个抽象类。不能创建抽象类的实例。代之以使用其中一个子类:
https://stackoverflow.com/questions/17956054
复制相似问题