xp1632 / VPE_IP

0 stars 0 forks source link

Possible 【Auto Op generation enhancement】 #75

Open xp1632 opened 6 months ago

xp1632 commented 6 months ago

default (6)




-result_image= ij.op().run(Op_name, ij.py.jargs(result_image, process_image, HyperSphereShape(range),None))

mask = ij.op().run("threshold.otsu", smoothed)


xp1632 commented 6 months ago

VP node for Auto Op Generation Node should look like :

image

  1. We create a large string area for displaying the user code snippet as in the picture left, and add an output handle to it

  2. Or, we make the path string input area in the picture right really large

xp1632 commented 6 months ago

3. Auto workflow conversion


import ast

code = """
HyperSphereShape = sj.jimport("net.imglib2.algorithm.neighborhood.HyperSphereShape")
smoothed = ij.op().run("create.img", jslice)
smoothed = ij.op().run("filter.median", ij.py.jargs(smoothed, cells_slice, HyperSphereShape(5)))
mask = ij.op().run("threshold.otsu", smoothed)
mask = ij.op().run("morphology.dilate", mask, HyperSphereShape(1))
mask = ij.op().run("morphology.fillHoles", mask)
ij.py.show(mask)
"""

tree = ast.parse(code)

# List to store the operations and their output variables
ops = []

for node in ast.walk(tree):
    if isinstance(node, ast.Assign):
        # If the node is an assignment, get the variable name and the operation that produces it
        var_name = node.targets[0].id
        if isinstance(node.value, ast.Call):
            func = node.value.func
            if isinstance(func, ast.Attribute) and func.attr == 'run':
                op_name = node.value.args[0].s
                ops.append((op_name, var_name))  # Add the operation and its output variable to the list
                print(f"Variable '{var_name}' is produced by operation '{op_name}'")

    elif isinstance(node, ast.Call):
        func = node.func
        if isinstance(func, ast.Attribute) and func.attr == 'run':
            # If the node is a function call, check if any of the arguments are variables produced by previous operations
            for arg in node.args[1:]:
                if isinstance(arg, ast.Name):
                    for i in reversed(range(len(ops))):
                        if ops[i][1] == arg.id:
                            print(f"Variable '{arg.id}' produced by operation '{ops[i][0]}' is used as an argument in operation '{node.args[0].s}'")
                            break

image


xp1632 commented 5 months ago

Answer to Fei's HypersphereShape(5) handle type passing value question



And the two node handles can only be connected if both datatype and java_type match

xp1632 commented 5 months ago

Next step for auto generation pipeline


xp1632 commented 5 months ago

Where to iterate all ImageJ2 Ops?

In OpService image