documents:110816pyip_cooking
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| documents:110816pyip_cooking [2011/08/16 23:39] – created kota | documents: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> |
| >>> | >>> | ||
| >>> | >>> | ||
| >>> | >>> | ||
| >>> | >>> | ||
| - | </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('/ | In [40]: img = cv.LoadImage('/ | ||
| In [41]: img | In [41]: img | ||
| Out[41]: < | Out[41]: < | ||
| - | </sxh> | + | </code> |
| Line 35: | Line 35: | ||
| === Tiff to numpy.ndarray, | === Tiff to numpy.ndarray, | ||
| - | <sxh python> | + | <code python> |
| In [44]: import tifffile as tff | In [44]: import tifffile as tff | ||
| In [50]: tiffimg = tff.TIFFfile('/ | In [50]: tiffimg = tff.TIFFfile('/ | ||
| Line 43: | Line 43: | ||
| In [53]: type(img) | In [53]: type(img) | ||
| Out[53]: <type ' | Out[53]: <type ' | ||
| - | </sxh> | + | </code> |
| === Tiff to numpy.ndarray, | === Tiff to numpy.ndarray, | ||
| - | <sxh python> | + | <code python> |
| In [54]: tiffimg = tff.TIFFfile('/ | In [54]: tiffimg = tff.TIFFfile('/ | ||
| 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 ' | Out[62]: <type ' | ||
| - | </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> |
| >>> | >>> | ||
| >>> | >>> | ||
| Line 78: | Line 78: | ||
| [ 7., 7., 7., 7., 7.]], dtype=float32) | [ 7., 7., 7., 7., 7.]], dtype=float32) | ||
| - | </sxh> | + | </code> |
| < | < | ||
| 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> |
| >>> | >>> | ||
| >>> | >>> | ||
| Line 99: | Line 99: | ||
| [100, 100, 100, 100, 100]], dtype=uint8) | [100, 100, 100, 100, 100]], dtype=uint8) | ||
| - | </sxh> | + | </code> |
| < | < | ||
| + | |||
| + | ===== Data Visualization ===== | ||
| + | |||
| + | ==== 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 [[http:// | ||
| + | |||
| + | <code python linenums: | ||
| + | from matplotlib import mlab as matp | ||
| + | filename = '/ | ||
| + | x1, y1, z1, x2, y2, z2 = matp.load(filename, | ||
| + | |||
| + | from mayavi.mlab import points3d | ||
| + | from mayavi.mlab import plot3d | ||
| + | from mayavi import mlab as maya | ||
| + | |||
| + | p1s = points3d(x1, | ||
| + | p2s = points3d(x2, | ||
| + | |||
| + | for idx, xval in enumerate(x1): | ||
| + | plin1 = plot3d([x1[idx], | ||
| + | maya.show() | ||
| + | </ | ||
| + | |||
| + | [{{ : | ||
| + | |||
| + | In this example, we assume the follwoing data structure in the file: a pair of coordinates per line, so 6 numbers are in one line separated by tab. It should look like | ||
| + | |||
| + | < | ||
| + | 1.0 3.6 4.8 5.1 6.12 7.14 | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | To run this script, the best is to run it from ipython with thread so first you start ipython by | ||
| + | < | ||
| + | ipython -wthread | ||
| + | </ | ||
| + | or incase of newer ipython (version >= 1.1) | ||
| + | < | ||
| + | ipython --i | ||
| + | </ | ||
| + | then in the ipython interface, | ||
| + | < | ||
| + | run exampleMayavi.py | ||
| + | </ | ||
| + | A new window pops up, and after drawing of the scene is finished, you could control the scene by such as | ||
| + | < | ||
| + | maya.view(100, | ||
| + | </ | ||
| + | or to animate the scene | ||
| + | < | ||
| + | for i in range (1, 360, 3): maya.view(i, | ||
| + | </ | ||
| + | to close the scene, | ||
| + | < | ||
| + | maya.close() | ||
| + | </ | ||
| + | |||
| + | Note that in this example, | ||
| + | <code python> | ||
| + | from mayavi import mlab as maya | ||
| + | </ | ||
| + | |||
| + | since the namespace " | ||
| + | |||
| + | ==== plot 3D trajectory using Mayavi ==== | ||
| + | |||
| + | To evaluate 3D particle tracking results, trajectories could be plotted by color coding the time. | ||
| + | |||
| + | [{{ : | ||
| + | |||
| + | |||
documents/110816pyip_cooking.1313537967.txt.gz · Last modified: 2016/05/24 12:46 (external edit)
