home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 3.ddi / DEMOS.DI$ / IMAGEEXT.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  5.4 KB  |  164 lines

  1. function imageext()
  2. %IMAGEEXT    Demonstrate MATLAB V4's image capability.
  3.  
  4. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  5.  
  6. if ~(exist('gatlin.mat')==2)
  7.    return
  8. end
  9. global IM_FIG;
  10. if ~isempty(IM_FIG)
  11.     set(0,'CurrentFigure',IM_FIG);
  12.     return
  13. end
  14. global IM_NAMES
  15. IM_NAMES = ['flujet  '
  16.          'spine   '
  17.          'gatlin  '
  18.          'durer   '
  19.          'detail  '
  20.          'cape    '
  21.          'clown   '
  22.          'earth   '
  23.          'mandrill'
  24.          'spiral  '];
  25. nimages = size(IM_NAMES,1);
  26. image_button_labels = str2mat('NCSA Fluid Jet', ...
  27.          'Human Spine', ...
  28.          'Gatlinburg, 1964', ...
  29.          'Durer Etching', ...
  30.          'Durer Detail', ...
  31.          'Cape Cod');
  32. image_button_labels = str2mat(image_button_labels, ...
  33.          'Clown', ...
  34.          'Earth', ...
  35.          'Mandrill', ...
  36.          'Color Spiral');
  37.  
  38. color_button_labels = [ ...
  39.          'hsv     ',
  40.          'hot     ',
  41.          'pink    ',
  42.          'cool    ',
  43.          'bone    ',
  44.          'prism   ',
  45.          'flag    ',
  46.          'gray    ',
  47.          'rand    ',
  48.          'spin    ',
  49.          'revert  '];
  50. nil = size(image_button_labels,1);
  51. nic = size(color_button_labels,1);
  52. if nil > nic
  53.     color_button_labels = str2mat(color_button_labels,'Close');
  54.     nic = nic + 1;
  55.     where_close = 'color';
  56. else
  57.     image_button_labels = str2mat(image_button_labels,'Close');
  58.     nil = nil + 1;
  59.     where_close = 'image';
  60. end
  61. maxbut = max(nil,nic);
  62. IM_FIG = figure('units','normal','position',[.13 .33 .65 .6]);
  63. revert = get(IM_FIG,'colormap');
  64.  
  65. % place image menu buttons on left side
  66. toti = 1.5*nil+.5;
  67. but_h = .8/nil;
  68. widi = 0.2;
  69. hi = [];
  70. for k = 1:nil
  71.    pos = [0.01 (1.5*(k-1)+.25)/toti widi but_h];
  72.    hi = [uicontrol(IM_FIG,'units','normal','pos',pos) ; hi];
  73. end
  74.  
  75. % place color menu buttons on right side
  76. totc = 1.5*nic+.5;
  77. widc = 0.08;
  78. hc = [];
  79. for k = 1:nic
  80.    pos = [0.99-widc (1.5*(k-1)+.25)/totc widc but_h];
  81.    hc = [uicontrol(IM_FIG,'units','normal','pos',pos) ; hc];
  82. end
  83.  
  84. if strcmp(where_close,'image')
  85.    hcl = hi(length(hi));
  86.    hi = hi(1:length(hi)-1);
  87.    image_button_labels(nil,:) = [];
  88.    nil = nil-1;
  89. else
  90.    hcl = hc(length(hc));
  91.    hc = hc(1:length(hc)-1);
  92.    color_button_labels(nic,:) = [];
  93.    nic = nic-1;
  94. end
  95.  
  96. % set close callback
  97. s = ['global IM_FIG;close(IM_FIG),clear global IM_FIG IM_NAMES IM_AXIS;'];
  98. s = [s 'clear IM_AXIS IM_FIG IM_NAMES;'];
  99. if strcmp(where_close,'image')
  100.    set(hcl,'string',' Close','horiz','left','callback',s);
  101. else
  102.    set(hcl,'string',' close','horiz','center','callback',s);
  103. end
  104. for k=1:nic
  105.     col = color_button_labels(k,:);
  106.     col(col==' ') = [];
  107.     coll = col;
  108.     if strcmp(col,'rand'),col='rand(size(get(gcf,''''colormap''''),1),3)'; end
  109.     if strcmp(col,'spin')
  110.         s = ['global IM_FIG,cf=gcf;set(0,''CurrentFigure'',IM_FIG),',...
  111.             'point = get(IM_FIG,''pointer'');',...
  112.             'set(IM_FIG,''pointer'',''watch'');drawnow;',...
  113.             'spinmap;set(IM_FIG,''pointer'',point);'];
  114.     else
  115.        s = ['global IM_FIG, cmap = ''',col,''';',...
  116.             'cf=gcf;set(0,''CurrentFigure'',IM_FIG);',...
  117.             'point = get(IM_FIG,''pointer'');',...
  118.             'set(IM_FIG,''pointer'',''watch'');drawnow;',...
  119.             'cmap(cmap=='' '')=[];eval([''cm='' cmap '';'']);',...
  120.             'set(IM_FIG, ''mincolormap'',size(cm,1),''colormap'',cm);',...
  121.             'set(IM_FIG,''pointer'',point);',...
  122.             'if cf~=IM_FIG,set(0,''CurrentFigure'',cf),end;'];
  123.     end
  124.     set(hc(k),'string',coll,'horiz','center','callback',s);
  125. end
  126. for k = 1:nil-1
  127.     s = ['global IM_AXIS IM_FIG IM_NAMES IM_CAPT;cf=gcf;',...
  128.         'set(0,''currentfigure'',IM_FIG);',...
  129.         'set(IM_FIG,''CurrentAxes'',IM_AXIS);',...
  130.         'cla; drawnow;',...
  131.         'point = get(IM_FIG,''pointer'');',...
  132.         'set(IM_FIG,''pointer'',''watch'');drawnow;',...
  133.         'file = ''',IM_NAMES(k,:),''';file(file == '' '') = [];',...
  134.         'load(file);',...
  135.         '[m,n] = size(X); image(X);axis off;A = [n/m 1];',...
  136.         'set(IM_AXIS,''aspect'',eval(''A''));',...
  137.         'set(IM_FIG,''mincolormap'',size(map,1),''colormap'',map);',...
  138.         'IM_CAPT = imtext(.5,1.035,caption);',...
  139.         'revert = map;' ...
  140.         'set(IM_FIG,''pointer'',point);',...
  141.         'drawnow,if cf~=IM_FIG,set(0,''CurrentFigure'',cf),end,'];
  142.     set(hi(k),'string',[' ',deblank(image_button_labels(k,:))],'horiz','left','callback',s);
  143. end
  144.  
  145. % now do color spiral
  146. s = ['global IM_AXIS IM_FIG IM_NAMES;cf=gcf;set(0,''currentfigure'',IM_FIG);',...
  147.     'point = get(IM_FIG,''pointer'');set(IM_FIG,''pointer'',''watch'');',...
  148.     'drawnow,set(IM_FIG,''CurrentAxes'',IM_AXIS);',...
  149.     'm = 16; X = [spiral(m)-1 zeros(m,1); zeros(1,m+1)]; pcolor(X);',...
  150.     'map = hsv; set(IM_FIG,''mincolormap'',size(map,1),''colormap'',map);',...
  151.     'revert = map; drawnow,set(IM_FIG,''pointer'',point);',...
  152.     'if cf~=IM_FIG,set(0,''CurrentFigure'',cf),end,'];
  153. set(hi(nil),'string',[' ',deblank(image_button_labels(nil,:))],'horiz','left','callback',s);
  154.  
  155. % set default axes location
  156. IM_AXIS = axes('pos',[1.2*(0.01+widi) .11 .9*(.98-widi-widc) .81]);
  157. global IM_AXIS;
  158. axis off
  159. rect = [.25 .95 .5 .04];
  160. uicontrol(IM_FIG,'style','text','units','normal','position',rect,'string',...
  161.          'Images and Color Maps','backgroundcolor',get(gcf,'color'), ...
  162.          'clipping','off', 'foregroundcolor', get(IM_AXIS,'xcolor'));
  163.  
  164.