Python + imageJ 解决方案,采坑记录

Python + imageJ 解决方案,采坑记录

方案一:ImageJ的Python脚本编程

ImageJ的Python脚本编程 | 数字旗手

方案二:jython

建议放弃,因为jython很多包都pip install 不了

方案三:pyimagej(注意不是imagepy,imagepy的作者是闫大),

pyimagej · PyPI

方案四:Python程序,cmd调用imageJ,解析imageJ的宏脚本,是可以做到的

---

code如下

def WriteImageJMacroFile(fileRootPath, fileName, ROI):
    fileRootPath = fileRootPath.replace('\\', '/')

    ijmPath = fileRootPath + "/" + fileName[0:-4] + '.ijm'

    p1 = "fileRootPath=\"" + fileRootPath + "\";\n"
    p2 = "fileName=\"" + fileName + "\";\n"
    p3 = "ROI=newArray(" + str(ROI.iloc[0, 0]) + "," + str(ROI.iloc[1, 0]) + "," + str(ROI.iloc[2, 0]) + "," + str(
        ROI.iloc[3, 0]) + ");\n"

    body = """function processFile(fileRootPath, fileName) {
    setBatchMode(true); 
    open(fileRootPath + "/" + fileName);
    id = getImageID();
    selectImage(id);
    makeRectangle(ROI[0], ROI[1], ROI[2], ROI[3]);
    run("Crop");
    run("8-bit");  
    run("Size...", "width=100 height=80 average interpolation=Bilinear");
   outputFileName2 = "Pupil_Crop_"+fileName.substring(0,lengthOf(fileName)-4)+".avi";
   saveAs("avi", fileRootPath+"/"+outputFileName2);   

    run("Close");
}
processFile(fileRootPath,fileName);"""
    macro2 = p1 + p2 + p3 + body
    with open(ijmPath, "w") as f:
        f.write(macro2)
    return ijmPath
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值