如何在MATLAB中将MathWorks徽标添加到图像中?

时间:2009-10-22 04:01:37

标签: matlab

我曾在previous question中询问过如何在MATLAB中重现an image。现在,我想通过删除单词“Math”并将其替换为MathWorks logo来修改该图像。

我无法弄清楚如何在图中添加徽标并调整其位置。

这是我试图用来在图中添加徽标的代码:

L = 40*membrane(1,25);

logoFig = figure('Color',[1 1 1]);
logoax = axes('CameraPosition', [80.5 50 42.5],...
    'CameraTarget',[26 26 10], ...
    'CameraUpVector',[0 0 1], ...
    'CameraViewAngle',9.5, ...
    'DataAspectRatio', [1 1 .9],...
    'Position',[0 0 1 1], ...
    'Visible','off', ...
    'XLim',[1 51], ...
    'YLim',[1 51], ...
    'ZLim',[-13 40], ...
    'parent',logoFig);
s = surface(L, ...
    'EdgeColor','none', ...
    'FaceColor',[0.9 0.2 0.2], ...
    'FaceLighting','phong', ...
    'AmbientStrength',0.3, ...
    'DiffuseStrength',0.6, ...
    'Clipping','off',...
    'BackFaceLighting','lit', ...
    'SpecularStrength',1.1, ...
    'SpecularColorReflectance',1, ...
    'SpecularExponent',7, ...
    'Tag','TheMathWorksLogo', ...
    'parent',logoax);
l1 = light('Position',[40 100 20], ...
    'Style','local', ...
    'Color',[0 0.8 0.8], ...
    'parent',logoax);
l2 = light('Position',[.5 -1 .4], ...
    'Color',[0.8 0.8 0], ...
    'parent',logoax);

%http://www.mathworks.com/products/matlab/demos.html?file=/products/demos/shipping/matlab/logo.html

1 个答案:

答案 0 :(得分:4)

你似乎在解决这个问题上遇到了很多麻烦。这是我假设您要生成的图像:

alt text

首先,我开始使用my answer to your other question中发布的函数heartI_Heart_Matharrow.m使用myaa.mThe MathWorks File Exchange this MathWorks demo page )。我删除了I_Heart_Math中与绘制单词“Math”相关的所有代码,并缩小了图形窗口的大小。

接下来,我必须生成并绘制MATLAB L形膜标识。在MATLAB中,您可以键入logo,它将打开一个新图形,并在黑色背景上显示徽标。您可以通过在MATLAB中键入type logo来查看生成图形的代码,或者您可以查看'Parent' property

logo代码需要进行一些修改。由于我想将徽标添加到现有的图形窗口,因此我删除了创建新图形窗口的代码。我也更改了徽标轴的一些属性:GCF设置为当前图形窗口('Units' property),'Position' property设置为'像素',{{更改了3}}以将徽标轴定位在图形窗口中的心轴旁边。

总而言之,这是生成上述图片的新I_Heart_MATLAB代码:

function I_Heart_MATLAB

  % Initialize heart plot and adjust figure and axes settings:

  heart;
  set(gcf,'Position',[200 200 640 300],'Name','Original image');
  offset = get(gca,'CameraPosition')-get(gca,'CameraTarget');
  offset = 35.*offset./norm(offset);
  set(gca,'Position',[65 -9 300 300],'CameraViewAngle',6,...
      'XLim',[21+offset(1) 70],'YLim',[16+offset(2) 63],...
      'ZLim',[32 81+offset(3)]);

  % Create the axes and labels, offsetting them in front of the
  % heart to give the appearance they are passing through it:

  arrowStarts = [81 51 51; 51 86 51; 51 51 32]+repmat(offset,3,1);
  arrowEnds = [21 51 51; 51 16 51; 51 51 81]+repmat(offset,3,1);
  arrow(arrowStarts,arrowEnds,5,40,40);
  text('Position',[22 52 48]+offset,'String','x','FontSize',12);
  text('Position',[50 17 49]+offset,'String','y','FontSize',12);
  text('Position',[46.5 51 81.5]+offset,'String','z','FontSize',12);

  % Create the equation text:

  text('Position',[51 47 28],'FontName','Bookman','FontSize',8,...
       'HorizontalAlignment','center',...
       'String',{'(x^2+^9/_4y^2+z^2-1)^3-x^2z^3-^9/_{80}y^2z^3=0'; ...
                 '-3 \leq x,y,z \leq 3'});

  % Create the large-type text:

  hI = text('Position',[4 52 69.5],'String','I',...
            'FontAngle','italic','FontName','Trebuchet MS',...
            'FontSize',116,'FontWeight','bold');

  % Create and plot the L-shaped membrane logo:

  logoData = 40*membrane(1,25);
  logoAxes = axes('Parent',gcf,'Units','pixels',...
                  'Position',[335 21 280 280],...
                  'CameraPosition', [-193.4013 -265.1546  220.4819],...
                  'CameraTarget',[26 26 10],'CameraUpVector',[0 0 1],...
                  'CameraViewAngle',9.5,'DataAspectRatio',[1 1 .9],...
                  'XLim',[1 51],'YLim',[1 51],'ZLim',[-13 40],...
                  'Visible','off');
  surface(logoData,'Parent',logoAxes,'EdgeColor','none',...
          'FaceColor',[0.9 0.2 0.2],'FaceLighting','phong',...
          'AmbientStrength',0.3,'DiffuseStrength',0.6,...
          'Clipping','off','BackFaceLighting','lit',...
          'SpecularStrength',1.1,'SpecularColorReflectance',1,...
          'SpecularExponent',7);
  light('Parent',logoAxes,'Position',[40 100 20],'Color',[0 0.8 0.8],...
        'Style','local');
  light('Parent',logoAxes,'Position',[.5 -1 .4],'Color',[0.8 0.8 0]);

  % Create an anti-aliased version of the figure too (the larger
  % fonts need some adjustment to do this... not sure why):

  set(hI,'FontSize',86);
  myaa;
  set(hI,'FontSize',116);
  set(gcf,'Name','Anti-aliased image');

end