当前位置: 首页 > 知识库问答 >
问题:

在斐济使用Jython运行Java插件:Exception Java.lang.double不能强制转换为[D

范高刚
2023-03-14
#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):

太感谢你们了!

共有1个答案

拓拔浩阔
2023-03-14

这似乎是脚本框架或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
 类似资料: