我正在编写一个jython脚本来操纵斐济的图像。具体来说,我试图通过实现JFilament插件(TwoDContourDeformation和IntensityEnergy)中的一部分类来跟踪单元格轮廓。请参阅https://github.com/odinsbane/jfilament/tree/master/src/main/java/snakeprogram)。
我能够成功构建一个TwoDContourDeformation对象,但是当我尝试在我的对象上调用addSnakePoints方法时,我始终收到以下异常: java.lang.ClassCastException:java.lang.ClassCastException:java.lang.Double无法强制转换为[D
我理解这个异常通常是指尝试将Double对象加载到未构造为接受这些类型的数组或类中。但是,在DoubleDContourDeformation类的addSnakePoints方法中,不清楚Double对象在哪里/什么或它在哪里遇到错误。这是我的代码:
#IMPORTS
import java.util
from ij import IJ
from snakeprogram import IntensityEnergy
from snakeprogram import TwoDContourDeformation
#CONSTANTS
initial_parameters = java.util.Arrays.asList()
initial_parameters.add(1.0)
initial_parameters.add(2000.0)
initial_parameters.add(40.0)
initial_parameters.add(1.0)
initial_parameters.add(10.0)
initial_parameters.add(1000.0)
initial_parameters.add(1.0)
tracking_parameters = java.util.ArrayList()
tracking_parameters.add(1.0)
tracking_parameters.add(2000.0)
tracking_parameters.add(40.0)
tracking_parameters.add(1.0)
tracking_parameters.add(10.0)
tracking_parameters.add(5.0)
tracking_parameters.add(3.0)
def set_parameters(deform, initial_parameters):
deform.setAlpha(initial_parameters[0])
deform.setBeta(initial_parameters[1])
deform.setGamma(initial_parameters[2])
deform.setWeight(initial_parameters[3])
deform.setStretch(initial_parameters[4])
return None
def set_parameters_deform(edges, outline, num_slice, initial_parameters, tracking_parameters):
'''
Sets parameters for JFilament and deforms snake around cell edges
Inputs:
edges: ImagePlus, binary image stack
outline: java.util.ArrayList, x coordinates for the initial snake
num_slice: int, initial frame of the image stack
initial_parameters: java.util.ArrayList, list of starting parameters
tracking_parameters: java.util.ArrayList, list of parameters for tracking through all frames of the image stack
Returns:
outline: java.util.ArrayList, list of java.util.ArrayList. Length is equal to number of frames
'''
deform = TwoDContourDeformation(outline, IntensityEnergy(edges.getProcessor(), 1.0))
if num_slice == 1:
set_parameters(deform, initial_parameters)
for i in xrange(initial_parameters[5]):
try:
deform.addSnakePoints(initial_parameters[6])
#the above line is where the Exception is thrown
deform.deformSnake()
except ValueError:
IJ.log('snake failure')
set_parameters(deform, tracking_parameters)
for i in xrange(initial_parameters[5]):
try:
deform.addSnakePoints(tracking_parameters[6])
deform.deformSnake()
except ValueError:
IJ.log('snake failure')
return outline
edges = IJ.getImage()
x_coords = [49.71320343559643, 49.702736000251505, 49.67134402431167, 49.619058487867186, 49.54593099043001, 49.45203370001131, 49.33745928190039]
#length of x_coords list shortened for brevity
jx = java.util.ArrayList()
for x in x_coords:
jx.add(float(x))
set_parameters_deform(edges, jx, 1, initial_parameters, tracking_parameters):
非常感谢你!
答案 0 :(得分:0)
这似乎是脚本框架或JFilament插件的问题。
以下Python最小示例重现了该问题:
# @ImagePlus edges
from java.util import ArrayList
from snakeprogram.energies import IntensityEnergy
from snakeprogram import TwoDContourDeformation
outline = ArrayList()
outline.add(1.0)
outline.add(2.0)
outline.add(3.0)
deform = TwoDContourDeformation(outline, IntensityEnergy(edges.getProcessor(), 1.0))
deform.addSnakePoints(1000.0)
print deform
以及这个Groovy示例:
// @ImagePlus edges
import snakeprogram.energies.IntensityEnergy
import snakeprogram.TwoDContourDeformation
outline = [1.0, 2.0, 3.0]
deform = new TwoDContourDeformation(outline, new IntensityEnergy(edges.getProcessor(), 1.0))
deform.addSnakePoints((double)1000.0)
print deform
两者都指向此行作为错误来源:
at snakeprogram.TwoDContourDeformation.addSnakePoints(TwoDContourDeformation.java:101)
使用特定于脚本的转换例外:
java.lang.ClassCastException: java.lang.Double cannot be cast to [D
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to [D
在这两种情况下,都需要一个double([D
)数组,但只提供一个数字实例。您可以尝试在ImageJ forum上与@odinsbane联系。