Showing posts with label Procedural. Show all posts
Showing posts with label Procedural. Show all posts

Thursday, 10 April 2014

Cells and Worms - 2. The Shirt

Last post I talked about how seeing how many worms overlap if you drop them on a patch of ground, how (somehow) this was vaguely related to my scientific research, and that the simulation of this process even generates quite nice pictures. If you thought that was geeky, then this takes geekyness to a whole new level!

Part of my research has been into the shapes of trypanosome parasites. Trypanosomes that cause disease in people are fairly widely known (you might have heard of sleeping sickness, Chagas disease, or leishmaniasis) but trypanosomes don't just infect people. Trypanosome species have also been found infecting animals from sharks to penguins, crocodiles to elephants. There is even one species named after Steve Irwin (the crocodile hunter) that infects koalas!

A scanning electron microscope image of Trypanosoma brucei, the trypanosome which causes sleeping sickness.

In short, I did some research to test whether there were particular characteristic shapes of trypanosomes (length, width, etc.) that look like they might help the parasite survive in the bloodstream of different host animals. I made a big database of properties of trypanosome shape and, using the scripts I made to draw nicely tesselated trypanosome shapes I talked about in the last post, I put together a compelling summary of just how varied trypanosome shapes from different host species are are:


The science behind this picture suggests some interesting adaptation to help the parasites swim within their host bloodstream, but that's enough about the science. To me this pattern was just begging to be on a shirt, an abstract design with a biological twist!

Spoonflower is a fantastic online service where you can order customised fabric, wallpaper and other prints. So that is exactly what I did, and after some sewing (that I didn't do myself) I am now the proud owner of the world's only 100% scientifically accurate trypanosome shirt, featuring 27 different trypanosome species.


Scientists always say that research can take you down unexpected paths. This path from wriggly worms, through an image generating script, through research into trypanosome shape, to the world's only trypanosome shirt was quite an unexpected one!

Software used:
ImageJ: Automated trypanosome drawing.
Inkscape: Conversion to vector graphics for printing.

Wednesday, 9 April 2014

Cells and Worms - 1. The Theory

If you scatter 100 worms on a patch of soil 1 meter by 1 meter how many worms will fall on top of another worm? This might seem like a really pointless question, but it is surprisingly relevant to biological research using microscopes. It's also a surprisingly hard question to answer because worms are very wriggly! However, even this dry, theoretical, research problem provides the tools for making fun illustrations...


My work involves a lot of automated image analysis; taking a picture from a microscope and automatically analysing it to extract scientific data. To make sure an automated analysis is reliable you have to think about all the likely problems that might turn up, and with cells and microscopes a common problem is when two cells are lying on top of each other. The problems this causes are easy to imagine; if there are two cells with one nucleus lying on top of each other then it might look like one cell with two nuclei.

For some types of cells it is quite easy to work out how likely two are to touch or lie partly on top of each other when they are scattered randomly over a microscope slide. An example of an easy case is where all cells are circular and the same size; the approximate calculation is quite simple. Unfortunately the cells I work on are more worm-like in shape, about 17 microns long and 2 wide... if you scatter these cells over a slide how many will end up touching?

To work out the answer simulation is vital; the maths is just too complicated to do it analytically. A simulation of worm-like shapes proved to be quite simple:
  1. Pick a random starting point, direction and curvature.
  2. Start drawing a curved line from that point.
  3. Occasionally re-randomise the curvature.
  4. Stop once you have reached the length of the cell.
  5. Draw the profile of the cell shape along that curve.
Following these simple rules and tweaking the parameters (e.g. the minimum and maximum curvature, frequency of randomising curvature, etc.) gives a simple algorithm for drawing a worm-like shape. With a bit of tweaking it could draw cells that look like trypanosomes. Using this drawing tool it was possible to measure the chance of a cell touching or lying on top of another cell already on the microscope slide. Just repeat the drawing process thousands of times and detect whether the newly drawn cell intersects with any previously drawn ones. Problem solved.

This process gave me the answer I needed, but it also provided a tool for drawing trypanosome-like shapes. Better than that, it was easy to adapt it to make sure no two cells overlapped and they fitted neatly together over the image... And just like that a dry, theoretical, research problem turned into a beautiful image:


This was also easy to adapt to other worm-like shapes, like earthworms:


Software used:

Wednesday, 8 September 2010

Procedural Planets

This is the same procedural trick all over again... A planet is an enormously complex thing; it is basically impossible to model one by hand so procedural generation is key to making a believable looking planet. This planet is generated using the built in procedural textures of Blender - mostly perlin noise which defines the height of the land, texture of the water and location of the clouds.

You can watch a video of this planet in action on Youtube.

Software used:
Blender: Modeling, texturing and rendering.
ffmpeg: Video transcoding.

Wednesday, 11 August 2010

Procedural Trees

Organic objects, particularly plants and trees, are every 3D artist's nightmare. They are very familiar objects with a huge amount of detail which is really hard to capture within the memory constraints of pre-rendered graphics and polygon constraints of real time graphics.

The best approach is not to try and model or paint the detail yourself but design a program which can "grow" the graphics for you... The images of branches below are generated by a custom script in ImageJ, this is an example of procedural generation, which can generate huge detail very quickly. The graphics are made up of three parts; the alpha map (black shows that area should be transparent, white indicates opaque), the bump map (which adds depth and shape to the shading of the texture) and the diffuse texture (which provides the colour).

The alpha map (black is transparent).
The bump map (white is higher).
The diffuse texture (the colours to use)

Putting 6 of these computer generated textures together a pretty detailed tree can be made with just a few polygons. These trees render quickly and could be used in a computer game.Software used:
ImageJ - Procedural generation of textures.
Blender - Creation and rendering of 3D models.

Thursday, 20 August 2009

3D Texturing

Texturing in 3D is a pesky thing, images are 2D and 3D meshes are obviously 3D! Furthermore 2D images are always rectangular. There are two main ways of texturing a 3D object, neither of them great when you just want a quick seamless texturing job...

1. Simple mapping
For example cube mapping. For these the texture is projected onto the mesh according to very simple rules, for cube mapping this is simply if a face is pointing in the direction of one side of a cube then it gets its texture from that cube face. Mapping in this way has problems of distortion, for example if you try and use cube mapping on a sphere then you get problems of distortion near the cube corners. The texture also has to tile at each edge (ie. top to bottom, top to top, top to side, side to side, etc.) to prevent seams. Other mapping methods which avoid seams (eg. sphere or cylinder) tend to cause more distortion. This mapping is, however, dead easy to do and good procedural texures can reduce tiling problems.

Sphere mapping:

Cube mapping:

2. UV mapping
Here the 3D object is unwrapped to a 2D shape, think about flattening a cardboard box to its net. This can eliminate distortion (just make sure the unwrapping is good and doesn't change the shape of any faces). The big problem is tiling; a face on the 2D image may be isolated from its neighbours in 3D, it is hard to make a texture which links these edges with no errors... Making a logical UV unwrap for a texture artist to work with is very time consuming.

This is where I stepped in! I have been working on a way to let you do 3D texturing on any UV unwrapped model.

3D Texturing
All real life objects are "3D textured", ie. the texture could be calculated for any point in 3D space. Imagine cutting a plank of wood in half to reveal a new face; you reveal a new part of the 3D texture, some new grain, which (obviously) perfectly tiles with the sides around it. It is simple to use procedural textures to make a full 3D texture on a computer, you just need a way to transfer the correct information to the correct object faces of a 3D model.

The Method:
In blender:
1. Take the object you want to texture
2. UV unwrap it (while this method takes care of all distortion it is still best to make sure there are no really tiny faces)
3. Give the object the 3Dtexturingtool texture (this encodes the x,y,z location of every point on every face to a specific RGB colour)
4. Bake the object texture to the UV unwrapped image
OR
3/4. Bake the displacement data

In ImageJ
5. Open the image encoding the x,y,z locations
6. Run a macro which calculates the value of a 3D texture at each x,y,z location and writes that to the imageIn blender
7. Assign the new texture image to the object

This allows 100% tiling 100% distortion free texturing of an object, so far I have only written an ImageJ macro for assigning 3D perlin noise, but it works beautifully!The Limitations
This is limited to a 256x256x256 voxel texture (each r, g and b, so x, y and z, can only take a value of 0-255), so large images or detailed textures will become voxelated. There are ways around this (eg. encoding the x, y and z directions separately using all r,g,b colours for each direction in more detail), but these are significantly more hassle because you would have to bake the texture 3 times per object. I might do this if I ever need more detail!
It is also (currently) cringingly slow... This is because I don't know how to program efficiently and because it uses a macro, not even a proper script. It would probably be over 1000 times faster if you actually programmed it properly!
It is also (currently) useless because you can do this all with blender anyway, however it gives easy access to the tools needed to generate more interesting procedural textures outside of blender; I have planets and asteroids in mind!

Software Used:

ImageJ - Image generation

Blender - 3D modelling, texturing and rendering