User Tools

Site Tools


documents:120206pyip_cooking:python_imagej_cookbook

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
documents:120206pyip_cooking:python_imagej_cookbook [2021/10/19 17:55] – added scijava scripting in a script kotadocuments:120206pyip_cooking:python_imagej_cookbook [2021/11/24 09:05] – [Python + ImageJ, Fiji Cookbook] kota
Line 3: Line 3:
 This page was last edited at: ~~LASTMOD~~ This page was last edited at: ~~LASTMOD~~
  
-For learning image processing using Fiji and Jython scripting, go to excellent tutorials written by Albert Cardona, such as [[https://www.ini.uzh.ch/~acardona/fiji-tutorial/ | here in his website]] or [[https://imagej.net/Jython_Scripting | here in ImageJ.net]]. The former is in a tutorial style so if you want to learn how to do scripting using Jython, that's the place where you go. +For learning image processing using Fiji and Jython scripting, go to excellent tutorials written by Albert Cardona, such as [[https://www.ini.uzh.ch/~acardona/fiji-tutorial/ | here in his website]] or [[https://imagej.net/Jython_Scripting | here in ImageJ.net]]. The former is in a tutorial style so if you want to learn how to do scripting using Jython, that's the place where you go. Recently, there is a very good tutorial page for real beginners: [[https://learning.rc.virginia.edu/notes/fiji-scripting/|here.]]  
  
 This page is like a cookbook: there are no details about how to do programming, but more centered on how to use Classes built in ImageJ and its plugins. This is because the style how each algorithm is implemented is not consistent (they are written by 1000 different people!) so it takes a while to figure out how to use them when we are writing a bioimage analysis workflow. Examples below show how they are actually used in Jython scripts, to save our time for reading the source code of each.  This page is like a cookbook: there are no details about how to do programming, but more centered on how to use Classes built in ImageJ and its plugins. This is because the style how each algorithm is implemented is not consistent (they are written by 1000 different people!) so it takes a while to figure out how to use them when we are writing a bioimage analysis workflow. Examples below show how they are actually used in Jython scripts, to save our time for reading the source code of each. 
Line 1364: Line 1364:
  
 For more explanation about this processing, see [[http://rsbweb.nih.gov/ij/developer/api/ij/plugin/filter/GaussianBlur.html|the explanation in javadoc]]. For more explanation about this processing, see [[http://rsbweb.nih.gov/ij/developer/api/ij/plugin/filter/GaussianBlur.html|the explanation in javadoc]].
 +
 +==== Background Subtraction (Rolling Ball) ====
 +
 +Menu item [Process > Subtract Background]
 +
 +<code python>
 +from ij import IJ
 +from ij.plugin.filter import BackgroundSubtracter
 +
 +imp = IJ.getImage()
 +
 +ip = imp.getProcessor()
 +radius = 50.0
 +createBackground = False
 +lightBackground = False
 +useParaboloid = False
 +doPresmooth = False
 +correctCorners = False
 +
 +bs = BackgroundSubtracter()
 +bs.rollingBallBackground(ip, radius, createBackground, lightBackground, useParaboloid, doPresmooth, correctCorners)
 +imp.updateAndDraw()
 +</code>
 +
 +If the image is in RGB, then use a different method (rollingBallBrightnessBackground​).
 +
 +For more explanation about this processing, see [[https://imagej.nih.gov/ij/developer/api/ij/ij/plugin/filter/BackgroundSubtracter.html|the explanation in javadoc]].
 ==== ImageCalculator ==== ==== ImageCalculator ====
  
Line 2330: Line 2357:
  
 See explanation in [[http://www.prasannatech.net/2008/09/implementing-java-interfaces-in-jython.html|here]].  See explanation in [[http://www.prasannatech.net/2008/09/implementing-java-interfaces-in-jython.html|here]]. 
 +
 +==== Shell Command ====
 +
 +To run Shell command in OSX, here is an example. 
 +
 +<code python>
 +from java.lang import Runtime
 +from java.util import Scanner
 +
 +def runShellCommand( cmd ):
 + proc = Runtime.getRuntime().exec(cmd)
 + istream = proc.getInputStream()
 + scan = Scanner(istream).useDelimiter("\\n")
 + for ss in scan:
 + print ss
 +
 +
 +runShellCommand( "pwd" )
 +runShellCommand( "ls -la" )
 +</code>
 +
 +
 +==== Is dockr daemon running? ====
 +
 +Check if the docker daemon is running ():
 +
 +<code python>
 +from java.lang import Runtime
 +from java.util import Scanner
 +
 +
 +def checkDockerRunning( cmd ):
 + proc = Runtime.getRuntime().exec(cmd)
 + inputst = proc.getInputStream()
 + s = Scanner(inputst).useDelimiter("\\n")
 + if not s.hasNext():
 + print "Please start docker desktop!"
 + return False
 + for ss in s:
 + print ss
 + if ss.startswith("CONTAINER ID"):
 + return True
 + else:
 + print "Please start docker desktop!"
 + return False
 +
 +# below is for OSX. WIth win, just "docker ps"
 +cmd = "/usr/local/bin/docker ps" 
 +if checkDockerRunning( cmd ):
 + print "Docker running"
 +else:
 + print "Docker not running"
 +</code>
  
 ===== JAVADOCS ===== ===== JAVADOCS =====
documents/120206pyip_cooking/python_imagej_cookbook.txt · Last modified: 2022/10/16 07:12 by kota

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki