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 [2017/12/03 13:03] – [Automatic Brightness/Contrast Button] updated github repo link kotadocuments:120206pyip_cooking:python_imagej_cookbook [2018/07/19 14:43] – [Plugin: LOCI BioFormats, Replacing OME-TIFF XML] kota
Line 972: Line 972:
       - if the count exceeds "limit", then count becomes 0       - if the count exceeds "limit", then count becomes 0
       - if the count is larger than "threshold", then that value is the maximum.        - if the count is larger than "threshold", then that value is the maximum. 
 +
 +Explanation in human language: this algorithm first determines two values "limit" and "Threshold"
 +
 +"Threshold" is the parameter that actually sets the min and the max of the contrast curve for the automatic enhancement. Starting from the lowest pixel value (0) or the highest value (255), the algorithm determines the number of pixels with that pixel value. If the number exceeds 0.02% of total pixel number, then that pixel value becomes wither the min or the max for enhancing the contrast. For this decision to ignore background pixels, the algorithm also needs to have another decision determining the background pixel value. 
 +
 +"limit" actually is a fixed number for each image to decide which of black (0) or white (255) is the background. If the number of pixels with current pixel value is more than 10% of total pixel number, then that value is considered to be the background of the image. For example, when the number of pixels with the value of 0 is 15%, then pixels with 0 values are background. In the next step, if pixels with the value of 1 are still over 10% like 11%, then pixels with values <= 1 are background. When the background is white, then similar decision takes place in the second loop. 
  
 The Jython script shown below is the re-written version based on original Java code. You could see the Java code of method "autoadjust"  [[https://github.com/imagej/imagej1/blob/master/ij/plugin/frame/ContrastAdjuster.java#L780-L829|in the git repo]], line 780-829.  The Jython script shown below is the re-written version based on original Java code. You could see the Java code of method "autoadjust"  [[https://github.com/imagej/imagej1/blob/master/ij/plugin/frame/ContrastAdjuster.java#L780-L829|in the git repo]], line 780-829. 
Line 1303: Line 1309:
  
 <code python linenums:1> <code python linenums:1>
 +from ij import IJ, ImagePlus
 from ij.plugin.filter import ParticleAnalyzer as PA from ij.plugin.filter import ParticleAnalyzer as PA
 +from ij.measure import ResultsTable
 +
 imp = IJ.getImage() imp = IJ.getImage()
  
Line 1513: Line 1522:
 cm.setPointSize(3) cm.setPointSize(3)
 </code> </code>
-===== Plugin: LOCI BioFormats, Replacing OME-TIFF XML =====+===== Plugin: LOCI BioFormats ===== 
 + 
 +==== Importing CZI file ==== 
 + 
 +<code python linenums:1> 
 +from loci.plugins import BF 
 +from loci.plugins.in import ImporterOptions 
 + 
 +filepath = "/path/to/image/my.czi" 
 + 
 +# Options for Bioformats pluginincludeing the image path 
 +options = ImporterOptions() 
 +options.setOpenAllSeries(True) 
 +options.setShowOMEXML(False) 
 +options.setStitchTiles(False) 
 +options.setId(filepath) 
 +     
 +fullimps = BF.openImagePlus(options) 
 + 
 +#fullimps now holds multiple images contained within the czi file.  
 +# open the first one.  
 +fullimps[0].show() 
 +</code> 
 + 
 +See here for more on metadata parsing and so on: [[https://gist.github.com/ctrueden/6282856|bio-formats.py]] 
 + 
 +==== Replacing OME-TIFF XML ====
  
 <code python linenums:1> <code python linenums:1>
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