如何将标记点的.csv文件导入斐济并将其放置在正确的切片上

时间:2018-10-04 16:55:01

标签: python tiff imagej roi fiji

已解决的问题:如何有效地利用人类在tiff图像堆栈上标记一堆点?

  1. 将tiff堆栈导入斐济
  2. 选择多点工具
  3. 在每个切片上标记一些点(切片是图像堆栈中的图像)
  4. 分析->测量
  5. 文件->另存为...-> marking.csv

生成的markings.csv文件的前几行如下所示。有趣的是每个点的X和Y坐标,它们的顺序以及每个点位于的Slice上。

 ,Area,Mean,X,Y,Slice,Counter,Count
1,0,34,240.0,31.0,1,0,200
2,0,133,313.2,120.8,1,0,200
3,0,77,290.2,234.5,1,0,200
4,0,74,314.5,217.2,1,0,200
5,0,120,343.2,230.8,1,0,200
6,0,52,249.2,39.2,2,0,200
7,0,140,309.0,104.8,2,0,200
8,0,88,287.2,232.8,2,0,200
9,0,89,307.0,228.2,2,0,200
10,0,145,332.8,231.2,2,0,200
11,0,190,274.0,62.8,3,0,200
12,0,130,246.5,128.0,3,0,200
13,0,61,186.8,251.5,3,0,200
14,0,33,195.2,239.0,3,0,200
15,0,117,210.0,257.2,3,0,200
16,0,111,245.5,47.2,4,0,200

未解决的问题:如何有效地利用人工调整现有CSV文件中的标记?

我尝试将斐济创建的现有.csv文件重新导入斐济,以便将正确的点放置在堆栈中的正确切片上。用户的目标是快速浏览这些点,如有必要,将其中一些移动一点,然后保存回.csv文件。如果有比斐济更好的工具,请告诉我。

在网上找到一个example之后,我尝试实现一个Python代码,该代码将读取CSV文件,读取当前切片的所有点,将它们放置在切片上,然后移至下一个切片,依此类推,直到文件结束。我得到了错误

NameError: name 'makeSelection' is not defined

经过几个小时的搜索,翻遍了official documentationapi之后,我完全不知道人们可以为斐济写宏的所有奇特语言的语法是什么。编写的示例,以及最重要的是如何找到给定function所属的类,以便可以将其导入python脚本中

请在下面查看我的代码尝试。如果您注释掉包括makeSelection和setSlice在内的2行,即使没有加载的切片,它也可以运行。请帮助

import os
from ij.io import OpenDialog
from ij import IJ

########################
# Open file dialog
########################
od = OpenDialog("Select the file to import")
srcDir = od.getDirectory()
if srcDir is None:
    print("Cancelled by user")
else:
    filePathName = os.path.join(srcDir, od.getFileName())

    print("importing from file", filePathName)

    ########################
    # Get data
    ########################
    #text = File.openAsString(fileName).split("\n")
    f = open(filePathName, "r")
    text = f.readlines()

    #these are the column indexes
    header = text[0].rstrip().split(",")
    headerDict = dict([(header[i], i) for i in range(len(header))])
    iX = headerDict["X"]
    iY = headerDict["Y"]
    iSlice = headerDict["Slice"]
    oldSlice = 1

    xLst = []
    yLst = []

    # Loop over all lines
    IJ.getImage().setSlice(1)
    for i in range(1, len(text)):
        lineSplit = text[i].rstrip().split(",");
        x = float(lineSplit[iX])
        y = float(lineSplit[iY])
        sl = int(lineSplit[iSlice])

        # Separate input into slices
        if sl == oldSlice:  
            xLst += [x]
            yLst += [y]
        else:
            print "Reading slice",oldSlice, ":::", xLst, yLst

            # Place selection points on the frame
            makeSelection("point", xLst, yLst);

            # Move to the next frame
            IJ.getImage().setSlice(sl+1)

            # Update point storage
            oldSlice = sl
            xLst = [x]
            yLst = [y]

    # Finish off the last trailing slice
    print "Reading slice",oldSlice, ":::", xLst, yLst

编辑:我写了另一个解决方案,现在使用.ijm格式。以这种格式,显然不必导入任何内容。使标记有效,但所有切片的标记均相同,但并非每个切片都唯一。我不知道如何解决这个问题。

// ask for a file to be imported
fileName = File.openDialog("Select the file to import");
allText = File.openAsString(fileName);
tmp = split(fileName,".");
// get file format {txt, csv}
posix = tmp[lengthOf(tmp)-1];
// parse text by lines
text = split(allText, "\n");

// define array for points
var xpoints = newArray;
var ypoints = newArray; 

// in case input is in CSV format

print("importing CSV point set...");
//these are the column indexes
hdr = split(text[0]);
iLabel = 0; iX = 3; iY = 4;
// loading and parsing each line
for (i = 1; i < (text.length); i++){
   line = split(text[i],",");
   setOption("ExpandableArrays", true);   
   xpoints[(i-1)%5] = parseInt(line[iX]);
   ypoints[(i-1)%5] = parseInt(line[iY]);
   print("p("+i+") ["+xpoints[(i-1)%5]+"; "+ypoints[(i-1)%5]+"]");
   if (i % 5 == 0) {
      setSlice(i / 5);
      makeSelection("point", xpoints, ypoints);
      xpoints = newArray;
      ypoints = newArray; 
   }

0 个答案:

没有答案