Sometimes I have to put text on a path

Friday, July 11, 2008

codes matlab 2D 3D image (fr)

xes abscisses d'un graphique ?
Les objets de type Axes ne possèdent pas de propriété permettant d'incliner les labels des repères de l'axe des abscisses d'un graphique.

Il existe néanmoins plusieurs contributions disponibles sur le File EXchange qui répondent à ce besoin :


Comment mettre une étiquette à mes points ?


str=num2str([1:numel(x)].','%1d'); % ATTENTION le premier argument de NUM2STR doit être un vecteur colonne
text(x+0.01,y+0.01,str) % Le décalage de 0.01 est arbitraire ici.
omment tracer une ligne dont la couleur varie ?
x = rand(3,1);
y = rand(3,1);



'facecolor','interp', ...
omment animer le tracé d'une courbe ?
% Génération des données

% Création de l'objet Figure contenant les tracés

% Première objet Axes  est tracée la courbe directe
% Tracé de la courbe
% Ajustement des limites de l'objet Axes
xlim([min(th) max(th)])
ylim([min(y) max(y)])

% Second objet Axes  est tracée la courbe animée

% Modification de la propriété DoubleBuffer de l'objet Figure pour
% éviter le clignotement de la fenêtre

% Tracé du premier point de la courbe
% et récupération de l'identifiant (handle) p de l'objet Line crée.
% Ajustement des limites de l'objet Axes
xlim([min(th) max(th)])
ylim([min(y) max(y)])

% On boucle sur le nombre de points à tracer. 
% On démarre à 2 puisque le premier est déjà tracé
for n=2:numel(th)

% Ajout des points de la courbe au fur et à mesure
% en utilisant la combinaison SET + identifiant (handle)
% Forçage de l'affichage du tracé

Comment récupérer les valeurs de données tracées ?
Dans tous les cas, il faut utiliser la fonction FINDOBJ pour récupérer l'identifiant de l'objet dont on veut
récupérer les données.

Pour les objets de type Line (nuage de points ou lignes), Surface ou Mesh, on récupère les propriétés XDATA, YDATA et ZDATA

Pour les objets de type Image, on récupère la propriété CDATA

Pour les objets de type Patch, on récupère, soit les propriétés XDATA, YDATA et ZDATA, soit les propriétés VERTICES et FACES

[X,Y,Z] = peaks(20)


Comment redimensionner une image ?
La première solution consiste à utiliser la fonction IMRESIZE contenue dans l'Image Processing Toolbox.

La deuxième solution utilise l'indexage des matrices. Puisqu'une
image est une matrice 2D ou 3D (RGB), il est très simple de diminuer la
taille d'une image en jouant sur l'indexage. Par exemple, pour diminuer
par deux la taille d'une image 2D, il suffit de ne conserver qu'un pixel sur deux

img=rand(150,200); % Une image 2D aléatoire

ans =

150   200



ans =

75   100

--------Pour une image 3D (RGB), le code devient :
img=rand(150,200,3); % Une image 3D (RGB) aléatoire

ans =

150   200     3



ans =

75   100     3
On remarque que cette solution utilisant l'indexage se limite à des facteurs de réductions/agrandissement entier.

La troisième solution utilise les fonctions d'interpolation.

Soit INTERP2 pour diminuer par deux la taille d'une image 2D :
img = rand(150,200); % Une image 2D aléatoire

ans =

150   200

[c,r ] = size(img); % Récupération des 2 dimensions de l'image

[ci,ri] = meshgrid(1:2:r,1:2:c); % Génération de la grille d'interpolation

img = interp2(img,ci,ri); % Interpolation des valeurs des pixels


ans =

75   100

Soit INTERP3 pour diminuer par deux la taille d'une image 3D :
img = rand(150,200,3); % Une image 3D (RGB) aléatoire

ans =

150   200     3

[c,r,p] = size(img); % Récupération des 3 dimensions de l'image

[ci,ri,pi] = meshgrid(1:2:r,1:2:c,1:p); % Génération de la grille d'interpolation

img = interp3(img,ci,ri,pi); % Interpolation des valeurs des pixels du plan R


ans =

ans =

75   100     3

VRML of a segmented image

I have an image segmented in matlab (in the form of 3d matrix with
elements 0 and 1) and from that matrix I want to create a vrml model,
do you know the best way to do it (with or without matlab, even if
with matlab I have the virtual reality toolbox installed)!

f,v]=isosurface (3Dmatrix,0);
translated to vrml with a simple script:

[fid,errmsg] = fopen('mymodel.wrl','w+');


fprintf(fid,' coord Coordinate {\n');
fprintf(fid,' point [\n');

for i=1:size (v,1)
fprintf(fid,'%f ',v(i,1)/500);
fprintf(fid,'%f ',v(i,2)/500);
fprintf(fid,'%f ',v(i,3)/500);

fprintf(fid,' ]#Point\n');
fprintf(fid,' }#Coordinate\n');
fprintf(fid,' index[\n');

for i=1:size (f,1)
fprintf(fid,'%d ',f(i,1)-1);
fprintf(fid,'%d ',f(i,2)-1);
fprintf(fid,'%d ',f(i,3)-1);

fprintf(fid,' ]#index\n');


fclose (fid);

Will you please show some (first ten lines - max .1kB) of the result?

unfortunately 30 megabytes for a 218x218x128 image!

The wrl file is not an image, it is the geometry and lighting.
You are sending the browser (the program that runs the .wrl file

(sets of x,y,z vertex values along with the info to make them
into triangles and lights that become pixels.
that's too much (for both speed and memory), even because i want to
deal with much bigger matrix!

Great, we all want that.


blender file format data

Here are links to file format specs or implementations, with particlar focus on those useful in DCC (Digital Content Creation); CAD (Computer Assisted Design); video/web animation/3d Display formats; game content formats; 2d image formats; and lastly sound formats

The most widely supported CAD formats are DXF, DWG, IGES and STEP

The most widely supported DCC formats are OBJ, LWO, 3DS, Collada

The most widely supported web 3d content formats are Shockwave, VRML, X3D, U3D

The most widely supported image formats are Adobe Photoshop, PNG, JPG, GIF

if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); }

CAD formats

DCC file formats

  • FBX API - there is not a format spec available that I can find only specs for the library/api:

WEB file formats

Motion Capture Formats

Image Formats

Vector Image Formats

Scene Description Languages

Lectures on Scene Description languages

PPM Format Specification

Neutral File Format

Polygon File Format

PLY Tools

Scene Description languages
RenderMan Interface Specification

Radiance Scene Description language

Manchester Scene Description language

POVRAY scene description language

YAFRAY scene description language (is there an official version somewhere??)
Another list of format links (most of the links are broken)

Universal translator tools

  • Polytrans - universal 3d format converter - very useful table of what formats are supported by different CAD programs, also explains the strengths and limitations of different formats

Misc lists of formats and universal importers/exporters

  • An extremely large list of formats and specs some with sample code

(note that for some of the formats he links there are much more complete specs availabled - ie lightwave lwo)

  • Material Exchange Format (a subset of the Advanced Authoring Format):

Useful overview of MEF

HOOPS Streaming File Format spec -

Imagine IOB - code to parse it

Misc stuff

Poser related format data



Interactive 3D-Visualization of various microscopic image stacks.

First version was implemented in pure MS-Visual-c++ and OpenGl. The new version uses the MedWorld3D-VRML/X3D-Core. It supports all the (interactive) features of MedWorld3D and some new components especially for microscopic visualization.

Image import features (additionally to DICOM, ACR-NEMA): JPG, BMP, RAW, TIFF, PNG, JPEG2000, Biorad, Metamorph, Zeiss, Lucia, Nikon, Leica, Autooquant, Imagepro

Preparation features (additionally to MedWorld3D-features): innovative script mechanism for different filters and filter combinations for multiple ROIs.

Postprocessing features (additionally to MedWorld3D-features): 3D-Color-Manipulation, interactive chromatek 3D, object code combination

Interactive anatomical 3d-visualisation powered by X3D/VRML

Interactive 3D Visualization technique represents an important diagnosis and therapy planning tool. It cannot be compensated with simple 2D Pictures or static 3D Views.

Multimedia teaching tools which contain textual information, non-interactive videos and restricted pseudo three-dimensional scenarios can considerably contribute to the understanding of medical facts by the completion of interactive 3D Components. Multiuser environments are also an important aspect to recognize coherence of single events in patients physical health and to support medical teachings.

Until now, these techniques are not applicable every time and everywhere. Insufficient software functionality and quality, competitive and proprietary software and hardware as well as different system requirements for visualization aggravated the distribution of interactive 3D Systems.

So far, there is no common standard for 3D Geometry in medicine, like the Dicom files. These files include medical 2D Images, patient information and acquisition details in a special syntax.

Besides many simple 3D File formats, there are also considerably "more intelligent" specifications, like the XML compliant X3D specification. The new system reduces or eliminates all disadvantages of the regular systems and opens new Potentials.


Features (public Version 1.0.0)
  • 3D-Generator reads and creates 3d data from DICOM, JPG, BMP, RAW
  • VRML97/X3D compliant, tested with viper (vrml) and most known plugins on different OSs (vrml,x3d)
  • Platform-independent, uses a standard Browser Plugin (Best viewed with Cortona,BS-Contact,Freewrl or GLView, because of missing/bad/buggy script-implementation in octagonfree,flux,openvrml,venues,horizon,casa,vrweb - on those browsers only limited features)
  • Works with PocketCortona on Pdas
  • Ergonomic x3d/vrml interface, also for full windowxp-tabletpc use
  • 3D-manipulation functions like 3d-volume/area measuring and 3d-annotations in X3D/VRML. Transformation of 2D markers into 3d space and back. Export to ISO-SVG-Code.
  • Access to the real world via java-servlets
  • Multiprocessing, multimonitor and multiuser realtime experience trough EAI and SAI, limited only by the java-socket-interface and EAI availability (IE)
  • Multiuser database control for the 3d-manipulation system via java-servlets
  • Dicom-source-browsing via java-servlets (on next version also texture mapping)
  • Easy StepIn3D-system for vrml/x3d-beginners (plugin installation, tips, os-control)
  • Anatomical X3D/VRML-data-generation for all greyscale-datasets like CT,MR in dicoms/jpg/bmp-files (volume surface rendering with marching cube), interactive rendering control and annotation support with virtual sound and text enhancement -modular design, pluggable features via the 3d-generator-authoring-tool
  • Export of dicom-tags (patient,physician, institute...) to XML files for integration in X3D-scenes
  • Supports also special devices: X3D/VRML-viewer-software like 4d-vision stereo display software, phantom force-feedback-system, actual-systems holo-viewer (reduced vrml subset)
  • Special stereoscopic support and interface-design on all stereo-enabled devices (nvidia...) with e.g. cortona or glview
  • Hardware support for spaceball and spacemouse over special emulator software for all vrml/x3d viewers (windows only)
  • DirectX-device-support via bs-contact joystick interface and cortona keyboard-interface via plugin-independent joystick-emulator(partially third party, thanks to
  • Programmable POS-Keyboard support for cortona keyboard-nodes -plugin independent realtime image manipulation in the 2d-gui and 3d-gui(windows only, but next version comes also for linux and mac) -

3D Object Converter The program supports 524 file formats.

3D Object Converter, a powerful 3d model translation and interactive viewing shareware tool that allows arbitrary 3d model data to be imported from external sources, exported to various industry standard 3d file formats with great accuracy and quality. The program supports 524 file formats. It is available for Windows95/98/Me/NT/2K/2003/XP 32/XP 64/Vista 32/Vista 64.

STL bin asci        In/Out



PRO/Engineer render

Qhull Mathematica

QuickDraw 3D Binary Mesh








IGES                       /only Out

X3D VRML freeware file translator input import export

X3D is a royalty-free open standards file format and run-time architecture to represent and communicate 3D scenes and objects using XML. It is an ISO ratified standard that provides a system for the storage, retrieval and playback of real time graphics content embedded in applications, all within an open architecture to support a wide array of domains and user scenarios.

X3D has a rich set of componentized features that can tailored for use in engineering and scientific visualization, CAD and architecture, medical visualization, training and simulation, multimedia, entertainment, education, and more.

The development of real-time communication of 3D data across all applications and network applications has evolved from its beginnings as the Virtual Reality Modeling Language (VRML) to the considerably more mature and refined X3D standard.

X3D Features at a Glance

  • XML Integrated: the key to integration with:
    • Web Services
    • Distributed Networks
    • Cross-platform, inter-application file and data transfer

  • Componentized: allows lightweight core 3D runtime delivery engine
  • Extensible: allows components to be added to extend functionality for vertical market applications and services
  • Profiled: standardized sets of extensions to meet specific application needs
  • Evolutionary: easy to update and preserve VRML97 content as X3D
  • Broadcast/Embedded Application Ready: from mobile phones to supercomputers
  • Real-Time: graphics are high quality, real-time, interactive, and include audio and video as well as 3D data.
  • Well-Specified: makes it easier to build conformant, consistent and bug-free implementations

X3D Supports

  • 3D graphics and programmable shaders - Polygonal geometry, parametric geometry, hierarchical transformations, lighting, materials, multi-pass/multi-stage texture mapping, pixel and vertex shaders, hardware acceleration
  • 2D graphics - Spatialized text; 2D vector graphics; 2D/3D compositing
  • CAD data - Translation of CAD data to an open format for publishing and interactive media
  • Animation - Timers and interpolators to drive continous animations; humanoid animation and morphing
  • Spatialized audio and video - Audio-visual sources mapped onto geometry in the scene
  • User interaction - Mouse-based picking and dragging; keyboard input
  • Navigation - Cameras; user movement within the 3D scene; collision, proximity and visibility detection
  • User-defined objects - Ability to extend built-in browser functionality by creating user-defined data types
  • Scripting - Ability to dynamically change the scene via programming and scripting languages
  • Networking - Ability to compose a single X3D scene out of assets located on a network; hyperlinking of objects to other scenes or assets located on the World Wide Web
  • Physical simulation and real-time communication - Humanoid animation; geospatial datasets; integration with Distributed Interactive Simulation (DIS) protocols

Overview of X3D Profiles and Conformance

The modular architecture of X3D allows for layered "profiles" that can provide 1) increased functionality for immersive environments and enhanced interactivity or 2) focused data interchange formats for vertical market applications within a small downloadable footprint composed of modular blocks of functionality ("Components"), that can be easily understood and implemented by application and content developers.

A component-based architecture supports creation of different "profiles" which can be individually supported. Components can be individually extended or modified through adding new "levels", or new components can be added to introduce new features, such as streaming. Through this mechanism, advancements of the specification can move quickly because development in one area doesn't slow the specification as a whole. Importantly, the conformance requirements for a particular piece of content are unambiguosly defined by indicating the profiles, components and levels required by that content.

X3D Baseline Profiles

  • Interchange is the basic profile for communicating between applications. It support geometry, texturing, basic lighting, and animation. There is no run time model for rendering, making it very easy to use and integrate into any application.
  • Interactive enables basic interaction with a 3D environment by adding various sensor nodes for user navigation and interaction (e.g., PlanseSensor, TouchSensor, etc.), enhanced timing, and additional lighting (Spotlight, PointLight).
  • Immersive enables full 3D graphics and interaction, including audio support, collision, fog, and scripting.
  • Full includes all defined nodes including NURBS, H-Anim and GeoSpatial components.profiles

Additional X3D Profiles

  • MPEG-4 Interactive is a small footprint version of the Interactive profile designed for broadcast, handheld devices and mobile phones
  • CDF (CAD Distillation Format) is in development to enable translation of CAD data to an open format for publishing and interactive media.

X3D Content Authoring & Editing Tools
Tools for authoring X3D objects, scenes, behaviors, and character animation

X3D Viewers, Browsers & Plug-ins
X3D file and scene viewers, web browsers & viewer plug-ins

Developer Toolkits and Libraries
Tools to help developers create X3D applications and integrate X3D-support into existing applications

File Translators & Utilities
Utilities for optimizing and translating 3D data for import and/or use in X3D applications

et-Specific Applications
X3D applications that are targeted for use in specific vertical markets such as simulation, CAD, geographic mapping, medical and prototyping

X3D Collaboration Applications
X3D applications for online collaboration and communication in virtual environments.

Games, Entertainment, and Education
Games, entertainment applications, and media-rich educational applications


File Translators & Utilities

3d model translation and interactive viewing shareware tool that imports X3D geometry and exports to other formats

X3D Exporter for 3D Studio Max versions 5, 6, and 7

AccuTrans 3D provides accurate translation of 3D geometry between the file formats used by many popular modeling programs. Positional and rotational information for the 3D meshes is maintained. Also many material attributes, such as color, index of refraction, reflection, specularity and Phong shading, are transferred between the files. Textures and UV coordinates are supported. The program has been enhanced with additional features to make it more than just a 3D file conversion program. It supports VRML and writing of X3D-files.

Polyhedron modelling in OFF format with conversion from OFF to VRML97 with the off2vrml program. [please include in the VRML section]

Exporter (Python-Script) which will generate an X3D-Files from Blender.

Import X3D models into the popular Blender modeling and animation package

BS Encrypt encrypts 3D models for use in commercial business applications with focus on Internet use.

BS Encrypt encrypts 3D models as content protection for use in applications with focus on Internet use or content dissemination via CD/DVD.

BS Exporter for 3ds max converts data from 3ds max and supported Extensions for BS Contact VRML/X3D for state of the art realtime and Internet ready applications.

This feature-rich exporter includes support for real-timeshadows, static radiosity lighting, dynamic particle effects, multi-texturing, normal and environment maps, movie textures, animation and custom interaction scripting from within Blender itself.

BS Reducer decreases the number of polygons in high detailed 3D models without changing the appearance.

BS Reducer decreases the number of polygons in high detailed models without changing the appearance.

A series of scripts to take BVH (Biovision) motion capture files and apply them to CAESAR human body scan files. The body parts plus the animation are combined into a complete VRML file following the H-ANIM spec plus the animation resulting in a complete H-ANIM figure animated by the BVH file.

CIS/2 are the CIMsteel Integration Standards, a common method to represent steel structures. The translator converts a CIS/2 file into a VRML or X3D file.

Translator utility to convert files in the Keyhole Markup Language (KML), the modeling format for Google Earth, into X3D

Export X3D including H-Anim from the MilkShape 3D polygon modeler

The Octaga Exporter is a very useful tool if you are a user of 3D studio max. It helps you to ease the process from design to real-time 3D presentation. It saves you a lot of time and hazel by directly exporting visual effects made in 3D studio max. The Octaga Exporter makes the work process complete from 3D studio max, to Octaga Professional, Octaga Producer to Octaga Server. Octaga Exporter is available for both 3ds Max v.5 and v.6

Okino's PolyTrans & NuGraf provide the defacto implementations of X3D, Classic-VRML, VRML2 and VRML1 for the 3D industry. Provides bi-directional conversion between all major 3D file formats, animation systems (3ds Max, Maya, XSI, Lightwave, C4D and more), CAD file formats and VisSim systems. Robustly and accurately cross-converts meshes, trimmed NURBS, curves, 3D points, line sets, materials, textures, bitmaps, animation, and everything expected of a professional conversion system. See online help for full details. Used by 10's of thousands of 3D professionals and Fortune 1000 companies.

Enables 3DS MAX to use SFImage data in WRL/X3D/X3DV file, include input PixelTexture to a bitmap, and output a bitmap to WRL/X3D/X3DV file.

RawKee is an open source plugin for Maya Complete and Maya Unlimited that not only allows users to export the X3D file format, but also allows them to setup X3D scripting and routing from with Maya through the RawKee X3D interaction editor.

A stand-alone application to convert the scene files exported from UnrealEd (free Unreal game editor) into X3D, including geometry, animation, sound and interactivity.

This is a standalone Java-based software package for translating VRML97 files into X3d file using "x3d-3.0.dtd".

VrmlMerge converts VRML'97 files to X3D files (XML encoding), merges multiple .wrl files producing one big file, and replaces image textures with pixel textures.

The X3D and VRML Plugin Detector determines which, if any, X3D and VRML plugins are installed in your web browser.

Export X3D data files form the popular AC3D modeler

Xj3D includes a command-line X3D translator between XML encoding (.x3d), Classic VRML encoding (.x3dv) and VRML97 encoding (.wrl).

VRML File Format

VRML File Format

You need not have any substantial knowledge of the VRML format to use the VRML authoring tools to create virtual worlds. However, it is useful to have a basic knowledge of VRML scene description. This helps you to create virtual worlds more effectively, and gives you a good understanding of how the virtual world elements can be controlled using the Virtual Reality Toolbox.

This section is an introduction to VRML. For more information, refer to the VRML97 Reference. This reference is available online at

In VRML, a 3-D scene is described by a hierarchical tree structure of objects (nodes). Every node in the tree represents some functionality of the scene. There are 54 different types of nodes. Some of them are shape nodes (representing real 3-D objects), and some of them are grouping nodes used for holding child nodes. Here are some examples:
  • Box node -- Represents a box in a scene.
  • Transform node -- Defines position, scale, scale orientation, rotation, translation, and children of its subtree (grouping node).
  • Material node -- Corresponds to material in a scene.
  • DirectionalLight node -- Represents lighting in a scene.
  • Fog node -- Allows you to modify the environment optical properties.
  • ProximitySensor node -- Brings interactivity to VRML97. This node generates events when the user enters, exits, and moves within the defined region in space.

Each node contains a list of fields that hold values defining parameters for its function.

Nodes can be placed in the top level of a tree or as children of other nodes in the tree hierarchy. When you change a value in the field of a certain node, all nodes in its subtree are affected. This feature allows you to define relative positions inside complicated compound objects.

You can mark every node with a specific name by using the keyword DEF in the VRML scene syntax. For example, the statement DEF MyNodeName Box sets the name for this box node to MyNodeName. You can only access the fields of those nodes that you name in a virtual world.

In the following example of a simple VRML file, two graphical objects are modeled in a 3-D scene: A floor is represented by a flat box with a red ball above it. Note that VRML file is a readable text file that you can write in any text editor.

  • #VRML V2.0 utf8
    # This is a comment line
    WorldInfo {
      title "Bouncing Ball" 
    Viewpoint {
      position 0 5 30
      description"Side View"
    DEF Floor Box {
      size 6 0.2 6
    DEF Ball Transform {
      translation 0 10 0
      children Shape {
        appearance Appearance {
          material Material {
            diffuseColor 1 0 0
        geometry Sphere {

The first line is the VRML header line. Every VRML file must start with this header line. It indicates that this is a VRML 2 file and that the text objects in the file are encoded according to the UTF8 standard. You use the number sign (#) to comment VRML worlds. Everything on a line after the # sign is ignored by a VRML viewer, with the exception of the first header line.

Most of the box properties are left at their default values -- distance from the center of coordinate system, material, color, and so on. Only the name Floor and the dimensions are assigned to the box. To be able to control the position and other properties of the ball, it is defined as a child node of a Transform type node. Here, the default unit sphere is assigned a red color and a position 10 m above the floor. In addition, the virtual world title is used by VRML viewers to distinguish between virtual worlds. A suitable initial viewpoint is defined in the virtual world VRML file.

When displayed in V-Realm builder, the floor and red ball look like

Features of the Virtual Reality Toolbox Matlab VRML wrl

Features of the Virtual Reality Toolbox

The Virtual Reality Toolbox includes many features for you to create and visualize dynamic systems. It also provides real-time virtual interaction with dynamic models.

This section includes the following topics that describe these features:

V-Realm Builder supports all 54 VRML97 types AND matlab

V-Realm Builder 2.0  buid28 is inside the VR toolbox but you must  install with the matlab editor (command).

V-Realm Builder 2 is a flexible, graphically oriented tool for 3-D editing and is available for Windows operating systems only. It is a native VRML authoring tool that provides a convenient interface to the VRML syntax. Its primary file format is VRML. Its graphical interface (GUI) offers not only the graphical representation of a 3-D scene and tools for interactive creation of graphical elements, but also a hierarchical tree-style view (tree viewer) of all the elements present in the virtual world.

These structure elements are called nodes. V-Realm Builder lists the nodes and their properties according to their respective VRML node types, and it supports all 54 VRML97 types. For each type of node there is a specific tool for convenient modification of the node parameters. You can access node properties in two ways:
  • Using dialog boxes accessible from the tree viewer
  • Directly, using a pointing device

In many cases, it is easier to use the tree viewer to access nodes because it can be difficult to select a specific object in a 3-D scene. The tree view also lets you easily change the nesting levels of certain nodes to modify the virtual world according to your ideas. In the tree viewer, you can give the nodes unique names -- a feature necessary for working with Virtual Reality Toolbox.