首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复TypeError:'intancemethod‘对象在Python/斐济中是无法编写脚本的错误

如何修复TypeError:'intancemethod‘对象在Python/斐济中是无法编写脚本的错误
EN

Stack Overflow用户
提问于 2019-08-20 08:20:11
回答 1查看 94关注 0票数 0

我正在尝试让斐济在一组图像上运行对比函数进行分析。但是,每当我尝试运行该文件时,当我试图索引直方图对象时,我都会得到一个错误。对比代码被认为是模仿可通过斐济使用的自动阈值函数。我已经尝试过使用IJ.run(imp,“增强对比度”,“saturated=0.02”),但它没有自动阈值效果好。

代码语言:javascript
复制
dc = DirectoryChooser("Choose a folder")
folder = dc.getDirectory()

for filename in os.listdir(folder):  
  if filename.endswith(".tif"):  
    print "Processing", filename  
    imp = IJ.openImage(os.path.join(folder, filename))  
    if imp is None:  
      print "Could not open image from file:", filename  
      continue  

    IJ.run(imp,"8-bit","")


    at = 0
    AT = 5000
    cal = imp.getCalibration()
    imp.setCalibration(None)
    stats = imp.getStatistics()
    imp.setCalibration(cal)
    limit = int(stats.pixelCount/10)
    histogram = stats.histogram
    if at < 10:
      at = AT
    else:
      at /= 2
    threshold = int(stats.pixelCount/at)
    i = -1
    found = False
    count = 0
    while True:
      i += 1
      count = histogram[i]
      if count > limit:
        count = 0
      found = count > threshold
      if found or i >= 255:
        break
    hmin = i
    i = 256
    while True:
      i -= 1
      count = histogram[i]
      if count > limit:
        count = 0
      found = count > threshold
      if found or i < 1:
        break
    hmax = i

  else:  
    print "Ignoring", filename  
代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Users\jacob\Documents\School\PytonTest.py", line 41, in <module>
    count = histogram[i]
TypeError: 'instancemethod' object is unsubscriptable

    at org.python.core.Py.TypeError(Py.java:265)
    at org.python.core.PyObject.__finditem__(PyObject.java:687)
    at org.python.core.PyObject.__getitem__(PyObject.java:755)
    at org.python.pycode._pyx0.f$0(C:/Users/jacob/Documents/School/PytonTest.py:11)
    at org.python.pycode._pyx0.call_function(C:/Users/jacob/Documents/School/PytonTest.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:171)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1614)
    at org.python.core.__builtin__.eval(__builtin__.java:497)
    at org.python.core.__builtin__.eval(__builtin__.java:501)
    at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
    at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
    at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
    at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
EN

回答 1

Stack Overflow用户

发布于 2019-08-21 04:57:33

将获取直方图的方式更改为以下内容-这应该可以解决您的问题:

代码语言:javascript
复制
test = imp.getProcessor()
histogram = test.getHistogram()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57565295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档