简体   繁体   中英

How do I add the MathWorks logo to an image in MATLAB?

I had asked in a previous question about how to reproduce an image in MATLAB. Now, I want to modify that image by removing the word "Math" and replacing it with the MathWorks logo .

I'm having trouble figuring out how to add the logo to the figure and adjust its position.

Here's the code I have been trying to use to add the logo to the figure:

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

You seem to be having a lot of trouble figuring this out. Here's the image I assume you want to generate:

替代文字

First, I started with the functions heart and I_Heart_Math that I posted in my answer to your other question (which use arrow.m and myaa.m from The MathWorks File Exchange ). I removed all the code in I_Heart_Math that was related to plotting the word "Math" and reduced the size of the figure window.

Next I had to generate and plot the MATLAB L-shaped membrane logo. In MATLAB you can type logo and it will open a new figure with the logo displayed on a black background. You can look at the code that generates the figure by typing type logo in MATLAB, or you can look at this MathWorks demo page .

The logo code required a few modifications. Since I wanted to add the logo to an already existing figure window, I removed the code that created a new figure window. I changed a few properties for the logo axes as well: the 'Parent' property was set to the current figure window ( GCF ), the 'Units' property was set to 'pixels', and the 'Position' property was changed to position the logo axes next to the heart axes within the figure window.

Putting it all together, here's the new I_Heart_MATLAB code to generate the above image:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM