MATLAB GUI 開啟/顯示/處理 /儲存/圖象(映像)程式

來源:互聯網
上載者:User

 在百思我發表的文章,現在轉到csdn來

把這幾個檔案放在同一個檔案夾就ok了
%global im111;
h1=figure( ...
    'menu','none',...
   'color',[1,0.8,0.95],...
   'position',[103.8 50.923 880.2 600],...
   'Name',' 廣西工學院資訊與計算科學系', ...
   'NumberTitle','off', 'HandleVisibility', 'on', ...
   'Visible','on', 'Resize', 'off',...
   'BusyAction','Queue','Interruptible','off',...
   'IntegerHandle', 'off', ...
   'Doublebuffer', 'on', ...
   'Colormap', gray(256));
h12 = axes( ...
   'units', 'pixels', ...
   'BusyAction','Queue','Interruptible','off',...
   'ydir', 'reverse', ...
   'XLim', [.5 256.5], ...
   'YLim', [.5 256.5],...
   'CLim', [0 1], ...
   'XTick',[],'YTick',[], ...
   'Position', [300 80 500 500]);
blank1 = repmat(uint8(0),128,128);
h13 = image('Parent', h12,...
   'CData', blank1, ...
   'BusyAction','Queue','Interruptible','off',...
   'CDataMapping', 'scaled', ...
   'Xdata', [1 256],...
   'Ydata', [1 256],...
   'EraseMode', 'none');
p11=uicontrol( ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','pushbutton', ...
   'Units','normalized', ...
   'Position',[0.049 0.870 0.131 0.054], ...
   'String','開啟圖象', ...
   'Enable', 'on',...
   'callback','open_menu_1');
%------------------------------------------------------
p12=uicontrol( ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','pushbutton', ...
   'Units','normalized', ...
   'Position',[0.049 0.670 0.131 0.054], ...
   'String','處理圖象', ...
   'Enable', 'on',...
    'callback','gray_menu_1');
%--------------------------------------------
  
p13=uicontrol( ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','pushbutton', ...
   'Units','normalized', ...
   'Position',[0.049 0.770 0.131 0.054], ...
   'String','儲存圖象', ...
   'Enable', 'on',...
   'callback','save_as_menu_1');
%------------------------------------------------------

%------------------------------------------------------
p14=uicontrol( ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','pushbutton', ...
   'Units','normalized', ...
   'Position',[0.049 0.270 0.131 0.054], ...
   'String','清空', ...
   'Enable', 'on',...
   'callback',[...
   'set(h13,''CData'',blank1);']);
%-----------------------------------------------
Hn1=uicontrol( ...
   'BusyAction','Queue','Interruptible','off',...
   'Style','pushbutton', ...
   'Units','normalized', ...
   'Position',[0.749 0.010 0.131 0.054], ...
   'String','close', ...
   'Enable', 'on',...
   'callback','close');

%請儲存檔案名稱字為:open_menu_1.m
[filename pathname]=uigetfile({'*.bmp','BMP圖象(*.bmp)';...
    '*.jpg','JPG圖象(*.jpg)';'*.gif','GIF圖象(*.gif)';...
    '*.tif','TIF圖象(*.tif)';'*.png','PNG圖象(*.png)';...
    '*.*','ALL FILES(*.*)'},'請選擇一幅映像');

if isequal([filename pathname],[0,0])
    return;
end
str=[pathname filename];
im111=imread(str);
img11= double(im111)/256;
%set(h13,'CData',blank1);
set(h13,'CData',img11);
%hist(img11,[-0.2 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 ]);

=========
%請儲存檔案名稱字為:save_as_menu_1.m
[filename,pathname]=...
    uiputfile({'*.bmp','BMP圖象(*.bmp)';...
    '*.jpg','JPG圖象(*.jpg)';'*.gif','GIF圖象(*.gif)';...
    '*.tif','TIF圖象(*.tif)';'*.png','PNG圖象(*.png)';...
    '*.*','ALL FILES(*.*)'},'圖片另存新檔...');
if isequal([filename pathname],[0,0])
    return;
end
str=[pathname filename];
imwrite(img23,str);

===========
%global imgray;
%請儲存檔案名稱字為:gray_menu_1.m
imgray=rgb2gray(im111);
img23=double(imgray)/256;
set(h13,'CData',img23);
%hist(img23,[-0.2 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 ]);

把上面幾部分代碼,按要求儲存在在同一個檔案夾,應該可以了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.