How to generate surface mesh from DICOM files and/or nifti file in Python? - mesh

I need to generate surface generation from a segmented NIFTI file. I can do that easily in 3D slicer but I want to do that in Python. Is it possible to do that in Python?
I tried using VTK model but it is not showing the Surface rendered output.

check out simpleITK. It has tools that can read in series with full 3d awareness, and also generate various surfaces for you.
It isn't an app that will display things for you however, but there are various examples you can find for how to take the output of simpleITK and use with various visualisation options.

You can do that easily by scripting in 3D Slicer. You don't need to use the graphical user interface, just launch a Python script from the command-line. You can put together the script you need from examples in the script repository (for example https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Export_model_nodes_from_segmentation_node).

Related

Picker Tool for 4D data (2D x 2D)

Does there exist a (free) solution for extracting 2D slices from a 4D dataset? I'm thinking of something like the EELS SI Picker tool, or the DM-script one in Dave Mitchell's SITools package. I can currently change the slice being viewed on my 4D data in GMS 3 using the Gatan-provided SI Viewer, but I'm unable to manipulate it in a meaningful way.
To answer the scripting question:
It could be done by scripting and listener scripts, yes.
But there is no need to..
The 4D picker tool in GMS 3 is already free, but you need to use the appropriate free license.
When you go to Gatan's webpage for the free offline GMS you get various choices.
You need the STEMx lincense for the 4D picker tool. See below.
Note that you can use multiple licenses side-by-side, so I would recommend to get the last two or three.

Using Pyradiomics to calculate shape features on meshes instead of matrices?

I am trying to compute some mesh features for 3D models that I created using numpy-stl. I would like to compute all of the features given within pyradiomics, but I am not sure how to use them on just the meshes without them having all of the extra binary image, and matrix information? Unless there is a better program t use for shape feature extraction? Also, in the documentation, it says that there are some features you need to enable C extensions for. How can you do that in your python script?
C extensions are enabled by default. As of PyRadiomics 2.0, the python equivalents for those functions have been remove (horrible performance).
As to your meshes. PyRadiomics is build to extract features from images and binary labelmaps. To use meshes you would have to first convert them.
What features do you want to extract? PyRadiomics does use a sort of on-the-fly built mesh to calculate surface area and volume, which are also used in the calculation of several other shape features.
If you want to take a look at how volume and SA are calculated, the source code for that is in C (radiomics/src/cshape.c). The calculation of the derived features (e.g. sphericity) is in shape.py

What tools are commonly used to visualize meteorological and climatological data?

I am interested in visualizing meteorological and climatological data.
Here we are talking about 2D/3D visualization for weather and climate elements:
Temperature
Pressure
Wind
Example
We have used some tools previously, such as:
GrADS
Surfer (commercial software)
GIS Meteo (commercial software)
What another tools (preferably open source) would you suggest for that purpose nowadays?
I know you mentioned GrADS, but it was the tool I used mostly for development of weather products, a little more intuitive and resource friendly than IDV when I coded, and generally pretty good rate of development. You mentioned Open Source... did you know there is an OpenGrADS (http://opengrads.org/)? Most friends involved in weather product development use a combination of GrADS\OpenGrADS for much of their work. But I agree it doesn't produce knock-your-socks-off graphics.
Another commonly used free program is Gempak, another Unidata product, which really seems to be becoming outdated in my personal opinion).
And then you can talk high end graphics, you're going to pay more. http://moe.met.fsu.edu/~hrw22/movies/WIND_Katrina_2005-08-28_00Z.gif is a great video of Katrina that was produced by someone I knew using Amira. According to Wikipedia, you're looking at
"Cost: $4,000 USD + $800/year support (2009)... although now has much more ugly/complex pricing structure where each feature is priced separately (eg: Amira Mesh Option $360). I believe at NCMIR we pay ~$9000/year for five user-license." Ouch!
I don't have an open source tool, but if you can get access to a Level-II data feed (Level-II is minimally post processed radar data), I and a meteorologist friend use GR2Analyst. I would assume you know enough about weather sources to be able to figure out how to set this up.
If you're looking for an open source (and free) tool that can do 2D and 3D, which also includes access to a wide variety of datasets (obs, model output, remote sensing - radar level 2 and 3, satellite, and more!), then you might want to check out the Unidata Integrated Data Viewer (IDV):
http://www.unidata.ucar.edu/software/idv/
Source code available here:
https://github.com/Unidata/IDV
The interface is a bit complex, but we have some youtube screencasts to help people get up and going:
http://www.youtube.com/user/unidatanews/videos
If you'd like to see a video for a specific thing, we are taking requests :-) (email support-idv#unidata.ucar.edu). We do yearly training workshops as well, and those materials are available online here:
http://www.unidata.ucar.edu/software/idv/docs/workshop/
Cheers!
Sean
Panoply is a multiplataform desktop option if data is available in formats such NetCDF, HDF or GRIB.
I extracted the following text from his site that describes some of the characteristics:
Slice and plot geo-gridded latitude-longitude, latitude-vertical, longitude-vertical, or time-latitude arrays from larger multidimensional variables.
Slice and plot "generic" 2D arrays from larger multidimensional variables.
Slice 1D arrays from larger multidimensional variables and create line plots.
Combine two geo-gridded arrays in one plot by differencing, summing or averaging.
Plot lon-lat data on a global or regional map using any of over 100 map projections or make a zonal average line plot.
Overlay continent outlines or masks on lon-lat map plots.
Use any of numerous color tables for the scale colorbar, or apply your own custom ACT, CPT, or RGB color table.
Save plots to disk GIF, JPEG, PNG or TIFF bitmap images or as PDF or PostScript graphics files.
Export lon-lat map plots in KMZ format.
Export animations as AVI or MOV video or as a collection of invididual frame images.
Explore remote THREDDS and OpenDAP catalogs and open datasets served from them.
If you are interested in interactive visualization over web, there are some options such as:
ncWMS: an webmapping server that reads NetCDF data and publish it using Web Mapping Service standard.
GeoServer: another webmapping server that has plugin to read NetCDF data.
Vtk (visualization Toolkit) is a C++ open source 2D and 3D visualization library that I use to visualize radar data in 3D.

Automate AutoCAD 3D model generation

I want to use AutoCAD to generate a 3D model which is composed of many basic 3D geometries such as sphere, cube, etc.
I have the dimensions and the origin and orientation of the local coordinate system of the basic geometries. The data are stored in an Excel file. Each row of the excel data corresponds to one geometry and the columns are for dimensions, origin coordinates, and orientations. The data format is defined for each type of geometry.
I wanted to use AutoLisp or VBA or some other macro tool for AutoCAD to automate this process so that when the data is changed, I just need to run the macro to read the data and regenerate the AutoCAD 3D model.
What is the best solution?
There is no "best" solution for the general case. If you have experience with AutoLISP, use AutoLISP. If you have and use Visual Studio, use the ObjectARX .NET API. You could also write an Excel macro that generates a simple script file, use VBA inside AutoCAD, or drive AutoCAD from within Excel. The "best" way in your case is whichever way you feel most comfortable with.

Given a pair of images, how to automatically create an animation sequence morphing one image into the other?

Is there a programmatic way to convert two images into an animation sequence (e.g., an animated GIF) like the following example?
This image sequence, taken from a http://memrise.com course, doesn't seem to have manually-edited frames, but seems automatically transformed using some kind shape morphing algorithm. Is there a common term used to describe such an animation or algorithm? Is there a feature in ImageMagick or Photoshop/Gimp that generates such animations, given a pair of images?
Ideally the technique could be scriptable so I could create animations for several pairs of start-end images.
Edit: I have just been told about Gimp's tool under Filters->Animation->Blend, which appears to do the same thing as jQuery morph: each frame i is start + (finish - start)/N*i. In other words, you're transitioning each pixel independently from the start value to the finish value, without any shape morphing. The example gives is more complicated, as it modifies the contours of both images to achieve its compelling effect.
Other examples:
http://static.memrise.com/uploads/mems/32000121024054535.gif
http://static.memrise.com/uploads/mems/225428000121109232837.gif
I have written a tool that doesn't require setting manual keypoints and is not restricted to a domain (like faces). Anyway, the images have to be similar (e.g. two faces or two cars from the same perspective).
https://github.com/kallaballa/Poppy
There is also a web-version created with emscripten.
I generated the above animation using following command line:
poppy flame.png glyph.png flame.png
Although this is an old question, since ImageMagick is mentioned, for anyone who comes here from google it may be worth looking at this imagemagick plugin called shapemorph.
GIMP can't do that directly, but over the years a series of (now poorly maintaind) plug-ins to do that where released by third parties. The keyword for searching for this is "morph" - you should find a bunch of stand alone programs to do that as well, from "gratis" to full fledged Free Software, such as xmorph
Given pairs of vector files (.wmf extension) it is possible to use linear interpolation of shapenodes in Visual Basic for Applications to create frames for GIF animations , though this would take along time to explain. For some examples see
http://www.giless.co.uk/animatorMorphGIFs.htm (it is like a slideshow)
I have made some improvements since then, as well!