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
documents:120206pyip_cooking:python_imagej_cookbook [2025/10/05 22:36] – [Creating floating point processor image] kotadocuments:120206pyip_cooking:python_imagej_cookbook [2025/10/05 22:53] (current) – [Converting Java array types] kota
Line 821: Line 821:
 ==== Converting Java array types ==== ==== Converting Java array types ====
  
-Sometimes we need to convert the type of Java array e.g. double[] to int[]. For this, there is no magic trick and need to run a loop. Below is a code fragment. +Sometimes we need to convert the type of Java array e.g. double[] to int[]. In Java we can do this by for-loop with casting from float to int, but in Jython we can use the map function 
  
 <code:py>  <code:py> 
 +from ij import IJ
 from ij.process import StackStatistics from ij.process import StackStatistics
 import jarray import jarray
  
 +imp = IJ.getImage() #stack
 stackstats = StackStatistics(imp) stackstats = StackStatistics(imp)
-histD = stackstats.histogram() +histD = stackstats.histogram() #double[] returned, taken as floats in python 
-hist = jarray.zeros(len(histD), 'i'+print(type(histD[0])) 
-for i in range(len(histD)): + 
-    hist[iint(histD[i])+hist = map(int, histD) 
 +histInt = jarray.array(hist, 'i'
 +print(type(histInt[0])) #Java int[]
 </code> </code>
  
documents/120206pyip_cooking/python_imagej_cookbook.txt · Last modified: 2025/10/05 22:53 by kota

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki