您当前的位置: 首页 >  matlab

slandarer

暂无认证

  • 4浏览

    0关注

    248博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

matlab 图片RGB颜色提取0-255版

slandarer 发布时间:2019-11-27 21:17:38 ,浏览量:4

APP designer版本链接:MATLAB App Designer 特别篇:RGB颜色提取器 新版本链接:matlab图片RGB颜色提取第二版

function getcolor255
global control;
global ima;
global GUI;
global x_limit;
global y_limit;
global color;
global a;
global color_number;
global color_list;
color_number=1;

GUI.fig=figure('units','pixels',...
    'position',[350 100 800 500],...
    'Numbertitle','off',...
    'menubar','none',...
    'resize','off',...
    'name','getcolor',...
    'color',[0.95 0.95 0.95]);
GUI.text=uicontrol('parent',GUI.fig,...
    'style','text',...
    'string','色彩识别',...
    'horizontalalign','center',...
    'position',[50 440 400 30],...
    'backgroundcolor',[0.85 0.89 0.85],...
    'foregroundcolor','k',...
    'fontsize',15);
GUI.text1=uicontrol('parent',GUI.fig,...
    'style','text',...
    'string','',...
    'horizontalalign','left',...
    'position',[460 330 100 100],...
    'backgroundcolor',[1 1 1],...
    'foregroundcolor','k',...
    'fontsize',10);
GUI.text2=uicontrol('parent',GUI.fig,...
    'style','text',...
    'string','',...
    'horizontalalign','left',...
    'position',[350 440 210 30],...
    'backgroundcolor',[1 1 1],...
    'foregroundcolor','k',...
    'fontsize',10);
GUI.savecolorbutton=uicontrol('parent',GUI.fig,...
    'style','pushbutton',...
    'string','储存颜色',...
    'position',[460 290 100 30],...
    'backgroundcolor',[0.85 0.89 0.85],...
    'foregroundcolor','k',...
    'fontsize',15,...
    'callback',@save_color);

GUI.deletedatabutton=uicontrol('parent',GUI.fig,...
    'style','pushbutton',...
    'string','清空数据',...
    'position',[460 230 100 30],...
    'backgroundcolor',[0.8 0.9 0.9],...
    'foregroundcolor','k',...
    'fontsize',15,...
    'callback',@clear_data);
GUI.deletepicbutton=uicontrol('parent',GUI.fig,...
    'style','pushbutton',...
    'string','删除图片',...
    'position',[460 180 100 30],...
    'backgroundcolor',[0.8 0.9 0.9],...
    'foregroundcolor','k',...
    'fontsize',15,...
    'callback',@delete_pic);
GUI.getcapbutton=uicontrol('parent',GUI.fig,...
    'style','pushbutton',...
    'string','屏幕截图',...
    'position',[460 130 100 30],...
    'backgroundcolor',[0.8 0.9 0.9],...
    'foregroundcolor','k',...
    'fontsize',15,...
    'callback',@get_capture);
GUI.getpicbutton=uicontrol('parent',GUI.fig,...
    'style','pushbutton',...
    'string','读取图片',...
    'position',[460 80 100 30],...
    'backgroundcolor',[0.8 0.9 0.9],...
    'foregroundcolor','k',...
    'fontsize',15,...
    'callback',@getImage);
GUI.getcolorbutton=uicontrol('parent',GUI.fig,...
    'style','pushbutton',...
    'tag','recc',...
    'string','获取颜色',...
    'position',[460 30 100 30],...
    'backgroundcolor',[0.8 0.9 0.9],...
    'foregroundcolor','k',...
    'fontsize',15,...
    'callback',@get_color);

for i=1:9
    GUI.text=uicontrol('parent',GUI.fig,...
    'tag',num2str(i),...
    'style','text',...
    'string','',...
    'horizontalalign','left',...
    'position',[600 440-40*(i-1) 30 30],...
    'backgroundcolor',[1 1 1],...
    'foregroundcolor','k',...
    'fontsize',10);    
end

for i=1:9
    GUI.text=uicontrol('parent',GUI.fig,...
    'tag',[num2str(i),'t'],...
    'style','text',...
    'string','',...
    'horizontalalign','center',...
    'position',[640 440-40*(i-1) 150 30],...
    'backgroundcolor',[1 1 1],...
    'foregroundcolor','k',...
    'fontsize',8);    
end
GUI.inputbutton=uicontrol('parent',GUI.fig,...
    'style','pushbutton',...
    'string','清除最后一个颜色',...
    'position',[600 80 190 30],...
    'backgroundcolor',[0.85 0.89 0.85],...
    'foregroundcolor','k',...
    'fontsize',15,...
    'callback',@delete_last);
GUI.inputbutton=uicontrol('parent',GUI.fig,...
    'style','pushbutton',...
    'string','导出数据',...
    'position',[600 30 190 30],...
    'backgroundcolor',[0.85 0.89 0.85],...
    'foregroundcolor','k',...
    'fontsize',15,...
    'callback',@output_data);




GUI.axes=axes('Units','pixels',...
      'PlotBoxAspectRatio',[1 1 1],...
      'Position',[50 30 400 400],...
      'Color',[0.98 0.98 0.98],...
      'Box','on', ...
      'XLim',[0 500],...
      'YLim',[0 500], ...
      'XColor','w','YColor','w',...
      'YDir','reverse', ...
      'Tag','sokoduaxes',...
      'xtick',[],'ytick',[]);
hold on;
    function output_data(~,~)
        if color_number>1
            disp(color_list)
        end
    end
    function save_color(~,~)
        if (~isempty(get(GUI.text2,'string')))&&color_number1
            set(findobj('tag',num2str(color_number-1)),'backgroundcolor',[1 1 1])
            set(findobj('tag',[num2str(color_number-1),'t']),'string','')
            color_list(end,:)=[];
            color_number=color_number-1;
        end
    end

    function delete_pic(~,~)
        control=0;
        set(findobj('Tag','sokoduaxes'),...
        'XLim',[0 500],...
        'YLim',[0 500],...
        'Position',[50 30 400 400],...
        'Color',[0.98 0.98 0.98]);
        delete(a);
    end
    function clear_data(~,~)
        control=0;
        set(GUI.text1,'backgroundcolor',[1 1 1]);
        set(GUI.text2,'string','');
        set(findobj('Tag','sokoduaxes'),...
        'XLim',[0 500],...
        'YLim',[0 500],...
        'Position',[50 30 400 400],...
        'Color',[0.98 0.98 0.98]);
        set(findobj('tag','recc'),'string','获取颜色');
        delete(a);
    end

    function get_color(~,~)
        if control==0
            set(GUI.text1,'backgroundcolor',[1 1 1]);
            set(GUI.text2,'string','');       
        end
        control=1;
        set(gcf,'WindowButtonMotionFcn',@whilemovefcn)  
        set(gcf,'WindowButtonDownFcn',@whileclickfcn)
    end

    function whilemovefcn(~,~)
        xy=get(gca,'CurrentPoint');
        x=xy(1,2);y=xy(1,1);
        if x=0
            x(x>x_limit)=x_limit;
            y(y>y_limit)=y_limit;
            x(x            
关注
打赏
1664692598
查看更多评论
0.0383s