Text on Sphere-MATLAB CODE
We can see how to wrap a text around a sphere. First obtain the x,y and
z co-ordinates of the sphere.These
co-ordinates can be used as an input for surface object.
Surface object generates sphere using the co-ordinates. Example:[x,y,z]=sphere(25); surface(x,y,z);
Now read a text image and convert it into
binary. Label the components in the
image. You can also check how to label components without BWLABELfunction in MATLAB. Now use the labeled
image as a CDATA value in surface object.
Example: surface(x,y,z, ‘CDATA’,matrix);
MATLAB CODE:
A=~im2bw(A);
B=bwlabel(A,8);
F=double(B);
mytext=flipud(F);
% Create the surface.
[x,y,z] = sphere(100);
figure,surface(x,y,z,'CData',mytext,'FaceColor','texturemap','FaceLighting','phong','EdgeLighting','phong','EdgeColor','none');
%set the colormap. Some
built-in colormaps are pink, copper, jet, hot...
%colormap pink
%Here I created my own colormap, the colors are white[1 1 1], black[0 0 0] and %blue [0 0 1]. Initialize the map with zeros(black) for 256x3 matrix. %Add blue
%color to some components(words). Initialize the first row with [ 1 1 1](white).
%Here I created my own colormap, the colors are white[1 1 1], black[0 0 0] and %blue [0 0 1]. Initialize the map with zeros(black) for 256x3 matrix. %Add blue
%color to some components(words). Initialize the first row with [ 1 1 1](white).
map=zeros([253 3]);
map(1,:)=0;
map(50:80,3)=1;
colormap(map);
%Create light object
light('position',[1 2 0 ],'Style','infinite','color',[0.8 0.7 0.8]);
light('position',[-2 -3 0 ],'color',[0.8 0.7 0.8]);
%Specify the viewpoint
axis square off
view(12,0);
Another Example: To create a GLOBE from a WORLD MAP
To convert a RGB image into SPHERE:
MATLAB CODE:
A=imread('mountain.jpg');
[mytext,map]=rgb2ind(A,256);
mytext=flipud(mytext);
% Create the surface.
[x,y,z] = sphere(100);
figure,surface(x,y,z,'CData',mytext,'FaceColor','texturemap','FaceLighting','phong','EdgeLighting','phong','EdgeColor','none');
%set the colormap.
colormap(map);
%Create light object
light('position',[1 2 0 ],'Style','infinite','color',[0.8 0.7 0.8]);
light('position',[-2 -3 0 ],'color',[0.8 0.7 0.8]);
%Specify the viewpoint
axis square off
%view(12,0);
view(180,0);
Hope you enjoyed this post. Check the link for more images:http://www.facebook.com/media/set/?set=a.352096201499476.75050.241768945865536&type=1
No comments:
Post a Comment