10/12/2010

Who bothers with ellipses?

In the previous post, we know how to draw an 2-D ellipse with its center, its major and minor axis, and its orientation. The process can be easily extent to draw N-D multi-dimensional ellipsoid with its center and covariance matrix (of course we can't visualize on N>3).
Now the question is why we need it? Well, mostly for visualization purpose. Check out some following examples.
1. Want to count how many small objects in a given image, such as embryos, and what is their average size?
Given image with small embryos (and a dime for real area reference)

Ask my 3-yrs-old daughter to do it - she can count up to 10 :). Or write a simple image processing program, and here I show the result:
Detect each embryo, fitting by an ellipse, compute its area

2. Other use might be the case that you want to show clusters clearly, like this:
Elliptic-Shape Clusters in 2-D
Or in 3-D, it might be more impressive:
Ellipsoid-Shape Clusters in 3-D

One who interested in the image processing or clustering techniques used in these examples can give me a note.
Any other thoughts? Comments are always welcome.

10/10/2010

Simple code to draw a 2-D ellipse

Sometime you want to add ellipses to your figures or images in Matlab? Rather than update to Matlab 2010 or buy PDE toolbox, you could google around and hopefully you find here: A simple code illustrates how you can do it.

Content

Input parameters of 2-D ellipse

clc, clear, close all 
x0 = 3; y0 = 3; % Center of ellip 
a = 2; b = 1;   % Major and minor radius 
phi = 30;       % Orientation (degree) 
num = 100;      % #points -> smoothness 

draw 'ellip = scaled circle' at origin

theta = linspace(0,2*pi,num);
p(1,:) = a*cos(theta);
p(2,:) = b*sin(theta);
figure(1), hold on 
plot(p(1,:),p(2,:),'k--','LineWidth',2)
axis equal
Rotate to derised angle

phi = phi*pi/180; % deg->rad 
% Rotation matrix: 
Q = [cos(phi) -sin(phi)
    sin(phi)  cos(phi)];
p = Q*p;
plot(p(1,:),p(2,:),'g--','LineWidth',2)
plot(0,0,'r+')
Move to derised location

p(1,:) = p(1,:) + x0;
p(2,:) = p(2,:) + x0;
plot(p(1,:),p(2,:),'LineWidth',2)
plot(x0,y0,'r+')