User Tools

Site Tools


documents:110816pyip_cooking

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
documents:110816pyip_cooking [2011/09/22 21:47] kotadocuments:110816pyip_cooking [2016/05/25 07:56] (current) – [plot 3D coordinates using Mayavi] kota
Line 9: Line 9:
 === Tiff file to numpy.ndarray === === Tiff file to numpy.ndarray ===
  
-<sxh python>+<code python>
 >>> import cv >>> import cv
 >>> img = cv.imread('/Users/miura/img/blobs.tif') >>> img = cv.imread('/Users/miura/img/blobs.tif')
 >>> type(img) >>> type(img)
 >>> <type 'numpy.ndarray'> >>> <type 'numpy.ndarray'>
-</sxh>+</code>
  
   * cv.imread reads only the first frame in tiff stack.    * cv.imread reads only the first frame in tiff stack. 
Line 21: Line 21:
 === Tiff file to Iplimage === === Tiff file to Iplimage ===
  
-<sxh python>+<code python>
 In [40]: img = cv.LoadImage('/Users/miura/img/blobs.tif') In [40]: img = cv.LoadImage('/Users/miura/img/blobs.tif')
 In [41]: img In [41]: img
 Out[41]: <iplimage(nChannels=3 width=256 height=254 widthStep=768 )> Out[41]: <iplimage(nChannels=3 width=256 height=254 widthStep=768 )>
-</sxh>+</code>
  
  
Line 35: Line 35:
 === Tiff to numpy.ndarray, Single Image === === Tiff to numpy.ndarray, Single Image ===
  
-<sxh python>+<code python>
 In [44]: import tifffile as tff In [44]: import tifffile as tff
 In [50]: tiffimg = tff.TIFFfile('/Users/miura/img/blobs.tif') In [50]: tiffimg = tff.TIFFfile('/Users/miura/img/blobs.tif')
Line 43: Line 43:
 In [53]: type(img) In [53]: type(img)
 Out[53]: <type 'numpy.ndarray'> Out[53]: <type 'numpy.ndarray'>
-</sxh>+</code>
  
 === Tiff to numpy.ndarray, Stack Image === === Tiff to numpy.ndarray, Stack Image ===
  
-<sxh python>+<code python>
 In [54]: tiffimg = tff.TIFFfile('/Users/miura/img/flybrainG.tif') In [54]: tiffimg = tff.TIFFfile('/Users/miura/img/flybrainG.tif')
 In [55]: img = tiffimg.asarray() In [55]: img = tiffimg.asarray()
Line 57: Line 57:
 In [62]: type(img10) In [62]: type(img10)
 Out[62]: <type 'numpy.ndarray'> Out[62]: <type 'numpy.ndarray'>
-</sxh>+</code>
   * if the image file is a single frame image, not so different from the others   * if the image file is a single frame image, not so different from the others
   * Stack tiff file is loaded peroperly. Single frame is extractable by indexing. In above case, 11th frame is extracted.    * Stack tiff file is loaded peroperly. Single frame is extractable by indexing. In above case, 11th frame is extracted. 
Line 67: Line 67:
   * tested with python2.6, openCV 2.2, numpy 1.6.1, OSX10.6.8   * tested with python2.6, openCV 2.2, numpy 1.6.1, OSX10.6.8
  
-<sxh python>+<code python>
 >>> import cv >>> import cv
 >>> import numpy as np >>> import numpy as np
Line 78: Line 78:
        [ 7.,  7.,  7.,  7.,  7.]], dtype=float32)        [ 7.,  7.,  7.,  7.,  7.]], dtype=float32)
  
-</sxh>+</code>
 <[[http://stackoverflow.com/questions/5762440/how-to-transform-a-opencv-cvmat-back-to-ndarray-in-numpy|link]]> <[[http://stackoverflow.com/questions/5762440/how-to-transform-a-opencv-cvmat-back-to-ndarray-in-numpy|link]]>
  
Line 85: Line 85:
   * tested with python2.6, openCV 2.2, numpy 1.6.1, OSX10.6.8   * tested with python2.6, openCV 2.2, numpy 1.6.1, OSX10.6.8
  
-<sxh python>+<code python>
 >>> im = cv.CreateImage( ( 5 , 5 ) , 8 , 1 ) >>> im = cv.CreateImage( ( 5 , 5 ) , 8 , 1 )
 >>> cv.Set( im , 100 ) >>> cv.Set( im , 100 )
Line 99: Line 99:
        [100, 100, 100, 100, 100]], dtype=uint8)        [100, 100, 100, 100, 100]], dtype=uint8)
  
-</sxh>+</code>
 <[[http://stackoverflow.com/questions/5762440/how-to-transform-a-opencv-cvmat-back-to-ndarray-in-numpy|link]]> <[[http://stackoverflow.com/questions/5762440/how-to-transform-a-opencv-cvmat-back-to-ndarray-in-numpy|link]]>
  
Line 106: Line 106:
 ==== plot 3D coordinates using Mayavi ==== ==== plot 3D coordinates using Mayavi ====
  
-An example script for loading (x, y, y) coordinates data from tab-delimited text file and plot them in 3D using mayavi2. +An example script for loading (x, y, y) coordinates data from tab-delimited text file and plot them in 3D using [[http://github.enthought.com/mayavi/mayavi/|mayavi2]]
  
-<sxh python>+<code python linenums:1>
 from matplotlib import mlab as matp from matplotlib import mlab as matp
 filename = '/Users/miura/data.txt' filename = '/Users/miura/data.txt'
Line 123: Line 123:
     plin1 = plot3d([x1[idx], x2[idx]], [y1[idx], y2[idx]], [z1[idx], z2[idx]], tube_radius=0.1, colormap='Spectral', color=(0, 0, 1))     plin1 = plot3d([x1[idx], x2[idx]], [y1[idx], y2[idx]], [z1[idx], z2[idx]], tube_radius=0.1, colormap='Spectral', color=(0, 0, 1))
 maya.show() maya.show()
-</sxh>+</code>
  
 [{{ :documents:figure20110923:mayaviexample.png?250| plotting data with mayavi}}] [{{ :documents:figure20110923:mayaviexample.png?250| plotting data with mayavi}}]
Line 138: Line 138:
 ipython -wthread ipython -wthread
 </code> </code>
-or incase of newer ipython+or incase of newer ipython (version >= 1.1)
 <code> <code>
 ipython --i ipython --i
Line 160: Line 160:
  
 Note that in this example,  Note that in this example, 
-<sxh python>+<code python>
 from mayavi import mlab as maya from mayavi import mlab as maya
-</sxh>+</code>
  
 since the namespace "mlab" overlaps with matplotlib.mlab.  since the namespace "mlab" overlaps with matplotlib.mlab. 
 +
 +==== plot 3D trajectory using Mayavi ====
 +
 +To evaluate 3D particle tracking results, trajectories could be plotted by color coding the time. 
 +
 +[{{ :documents:figure20111219:snapshot3.png?300| Plotting 3D trajectory. Trajectories are colored so that the beginning of frame is blue and gradually become red towards the end of the sequence}}] 
  
  
  
documents/110816pyip_cooking.1316728037.txt.gz · Last modified: 2016/05/24 12:46 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki