gpt4 book ai didi

java - 使用 Jython 在斐济运行 Java 插件 : Exception java. lang.Double 无法转换为 [D

转载 作者:太空宇宙 更新时间:2023-11-04 12:20:36 25 4
gpt4 key购买 nike

我正在编写一个 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 对象加载到未构造为接受这些类型的数组或类中。但是,尚不清楚 Double 对象在哪里/是什么,或者在 TwoDContourDeformation 类中的 addSnakePoints 方法中哪里遇到错误。这是我的代码:

#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):

非常感谢!

最佳答案

这似乎是脚本框架或 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)

https://github.com/odinsbane/jfilament/blob/master/src/main/java/snakeprogram/TwoDContourDeformation.java#L101

具有特定于脚本的转换异常(exception):

java.lang.ClassCastException: java.lang.Double cannot be cast to [D

java.lang.ClassCastException: java.math.BigDecimal cannot be cast to [D

在这两种情况下,都需要一个 double 组 ([D),但只提供了一个数字实例。您可以尝试联系@odinsbane ImageJ forum .

关于java - 使用 Jython 在斐济运行 Java 插件 : Exception java. lang.Double 无法转换为 [D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38883729/

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