Map An Image on A Surface

I’ve been always wondering how to create some interesting profile photos, so as to show off  to the guys on facebook or twitter. Of course the photo should be different with others, which should not be simply photoshoped. Here comes a simple idea: why not spread a photo on a surface?

With matlab, it’s definitely not hard to make one.  I referred to the matlab document , at Coloring mesh and Surface Plots.  The “surf” function is a classic tool to plot surface. Inputting a meshgrid matrix with certain spatial shape, it will plot the surface out. Then we can play with the color property of the surface, so that the color accord with the our photo property.

The procedure goes like this:

  1. Import a graph to matlab, transform the RGB image to an index image. 
  2. Create a surface you want, like sphere, cylinder, you name one.
  3. Use “surf” function to plot the surface.
  4. Change the”Texture mapping” properties of the surface, with the image. 
Here are the codes:
G= imread(‘filepath & file name’); % load an image
[X,map] = rgb2ind(G,256); % Convert RGB image to indexed image
% Create a surface
[theta,~]=meshgrid([-pi:0.1:pi,pi],[-pi:0.1:pi,pi]);
%[x,y]=meshgrid(10*cos(theta),10*sin(theta));
x=10*cos(theta);
y=10*sin(theta);
[~,z]=meshgrid(1:length(x));
surf(x,y,z) %plot the surface
h = findobj(‘Type’,'surface’); % get the object of the surface 
set(h,’CData’,flipud(X),’FaceColor’,'texturemap’,'EdgeColor’,'none’) % Change the surface property
colormap(map) % change colormap 
rotate3d on



Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.