I had some problems recently when I wanted to create an animated GIF mixing true color images and an overlaying graph.
I found a solution and thought I should share it!
The main problem is having a consistent colormap throughout the GIF. The rgb2ind function needed totransform the true color image to an indexed one provides a different color map for each frame. This will give weird colors in the GIF  because the indexing of the colors is right, but the associated colours change with each frame.
My solution is to make one large mosaic by repeating the background image and placing the overlays on top. Only then, then the rgb2ind function is called, so that it builds a colormap for all the colors of all the frames. Then you just need to cut it out and build the frames.
Here we go!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
% Gif file name here
gifName = 'd:\gif with different colormaps.gif';
 
% Prepare a figure and make it nice
hFig = figure;
hAxis = gca;
set(hFig,'color','w');
set(hAxis , 'Position' , [0 0 1 1]);
box(hAxis , 'off');
 
% Load a background image
I = imread('peppers.png');
 
 
% Prepare a few random overlays, one each frame of the GIF
n_frames = 5;
overlays = cell(n_frames);
for k = 1 : n_frames
    overlays{k} = rand(5);
end
 
 
% Coordinates where the overlay is plotted
s = size(I);
overlayCoord = [1+s(2)/5/2  ,  s(2)-s(2)/5/2  ,  1+s(1)/5/2   ,  s(1)-s(1)/5/2];
 
for k = 1 : n_frames
 
    % Cyclically select all overlays and paint
    hold off;
    imagesc(I , 'Parent' , hAxis);
    hold on;  axis equal;
 
 
    % Plot overlay over the image and make it transparent
    hOverlay = imagesc([overlayCoord(1) , overlayCoord(2)] , ...
                       [overlayCoord(3) , overlayCoord(4)] , overlays{k});
    alpha(hOverlay , 0.5)
 
 
    % Recover the figure contents and add it to the mosaic
    f = getframe(hFig);
    s = size(f.cdata);
    mosaic(: , (k-1) * s(2) + 1 : k * s(2), :) = f.cdata;
 
end
 
% Transform the whole RGB mosaic in an indexed image
[mosaic , map] = rgb2ind(mosaic,256); 
 
% Build frames for the GIF
frames = uint8(zeros(s(1) , s(2) , 1 , n_frames));
for k = 1 : n_frames
    frames(:,:,1,k) = mosaic(: , (k-1) * s(2) + 1 : k * s(2), :);
end
 
 
% And finally, save animated GIF
imwrite(frames , map , gifName , 'DelayTime' , 0.5 , 'LoopCount',inf);

And here is the result in all its random splendor:
gif with adapted colormaps

Category: Matlab | Leave a Comment

A couple of months ago I moved in Exeter, UK! I am working at the University of Exeter, with the Biophysics group. It is quite a change to go from having 99% of engineers and clinicians as colleagues, to having physicists and biologists. An interesting change! I look forward to do some science here!

I will still be working on intervertebral disc, but now at a much smaller scale: I will investigate the effects of needle puncture on the disc structure at the micro-scale. Very exciting, and very now, at least for me. I will be working with the great non linear laser microscopy setups at the UoE. Find out more University of Exeter – Claudio Vergari! I will try to prepare some pages on my new research as soon as possible…

Category: Research news | Leave a Comment

A nice video was published by the “Innovation & Handicap” group of Société Générale about their financing the BiomecAM chair program on subject-specific musculoskeletal modelling. Check it out!

 

Category: Research news | Leave a Comment

COngrès SB 2014

Prix SB small

 

A couple of days ago I was at the congress of the international francophone Société de Biomécanique: I won the Young Investigator Award for my work on intervertebral disc elastography!
I am so happy! It is very encouraging for a young researcher, and most of all it comes from a society that I really like. The SB congresses are always interesting since the topics range from cellular mechanics to bio-fluidodynamics, from tissue engineering to prosthesis characterization and, of course, numerical modeling. However, the best part is that it is a friendly community where everyone is accessible and ready to discuss. And IT IS an international community, with people coming from France, Belgium, Switzerland, Canada, but also Austria, Czech Republic, Denmark…

Category: Congress, Research news, Uncategorized | Leave a Comment

ESB2013 in Patras

I will be in Patras for the 19th Congress of the European Society of Biomechanics. I will present an “in vitro evaluation of intervertebral disc elastic modulus by elastography” on Tuesday, august 27th between 17:15 and 18:30. See you there!

Category: Congress | Leave a Comment