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

2024-01-08 13:58
文章标签 matlab 提取 图片 颜色 rgb 255

本文主要是介绍matlab 图片RGB颜色提取0-255版,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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:9GUI.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);    
endfor i=1:9GUI.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>1disp(color_list)endendfunction save_color(~,~)if (~isempty(get(GUI.text2,'string')))&&color_number<10set(findobj('tag',num2str(color_number)),'backgroundcolor',color/255)set(findobj('tag',[num2str(color_number),'t']),'string',['[',num2str(color),']'])color_list(color_number,:)=color;color_number=color_number+1;endendfunction delete_last(~,~)if color_number>1set(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;endendfunction 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);endfunction 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);endfunction get_color(~,~)if control==0set(GUI.text1,'backgroundcolor',[1 1 1]);set(GUI.text2,'string','');       endcontrol=1;set(gcf,'WindowButtonMotionFcn',@whilemovefcn)  set(gcf,'WindowButtonDownFcn',@whileclickfcn)endfunction whilemovefcn(~,~)xy=get(gca,'CurrentPoint');x=xy(1,2);y=xy(1,1);if x<=x_limit&&y<=y_limit&&x>=0&&y>=0x(x>x_limit)=x_limit;y(y>y_limit)=y_limit;x(x<1)=1;y(y<1)=1;x=round(x);y=round(y);if control==1color=double([ima(x,y,1),ima(x,y,2),ima(x,y,3)]);set(GUI.text1,'backgroundcolor',color/255);set(GUI.text2,'string',['[',num2str(color),']']);endelseif control==1set(GUI.text1,'backgroundcolor',[1 1 1]);set(GUI.text2,'string','');    endendendfunction whileclickfcn(~,~)          xy=get(gca,'CurrentPoint');x=xy(1,2);y=xy(1,1);if x<=x_limit&&y<=y_limit&&x>=0&&y>=0control=0;set(GUI.text1,'backgroundcolor',color/255);set(GUI.text2,'string',['[',num2str(color),']']);set(findobj('tag','recc'),'string','继续取色');%disp(color/255)endendfunction get_capture(~,~)screensize=get(0,'screensize');screensize=1.5*screensize;robot=java.awt.Robot();rectangle=java.awt.Rectangle();rectangle.x=0;rectangle.y=0;rectangle.width=screensize(3);rectangle.height=screensize(4);image=robot.createScreenCapture(rectangle);data=image.getData(); temp=zeros(screensize(3)*screensize(4)*3,1);temp=data.getPixels(0,0,screensize(3),screensize(4),temp);  temp=uint8(temp);R=temp(1:3:end); G=temp(2:3:end); B=temp(3:3:end);R=reshape(R,[screensize(3),screensize(4)]); G=reshape(G,[screensize(3),screensize(4)]); B=reshape(B,[screensize(3),screensize(4)]);R=R';G=G';B=B';x_limit=screensize(4); y_limit=screensize(3);leng=max([x_limit,y_limit]);set(findobj('Tag','sokoduaxes'),...'XLim',[0 leng],...'YLim',[0 leng]);ima=cat(3,R,G,B);delete(a);a=imshow(ima);endfunction getImage(~,~)warning off;[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...'*.*','All Files' });ima = imread([ pathname,filename]);[x,y,~]=size(ima);x_limit=x;y_limit=y;leng=max([x_limit,y_limit]);set(findobj('Tag','sokoduaxes'),...'XLim',[0 leng],...'YLim',[0 leng]);delete(a);a=imshow(ima);endend

这篇关于matlab 图片RGB颜色提取0-255版的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/583683

相关文章

Python利用PIL进行图片压缩

《Python利用PIL进行图片压缩》有时在发送一些文件如PPT、Word时,由于文件中的图片太大,导致文件也太大,无法发送,所以本文为大家介绍了Python中图片压缩的方法,需要的可以参考下... 有时在发送一些文件如PPT、Word时,由于文件中的图片太大,导致文件也太大,无法发送,所有可以对文件中的图

java获取图片的大小、宽度、高度方式

《java获取图片的大小、宽度、高度方式》文章介绍了如何将File对象转换为MultipartFile对象的过程,并分享了个人经验,希望能为读者提供参考... 目China编程录Java获取图片的大小、宽度、高度File对象(该对象里面是图片)MultipartFile对象(该对象里面是图片)总结java获取图片

Java实战之自助进行多张图片合成拼接

《Java实战之自助进行多张图片合成拼接》在当今数字化时代,图像处理技术在各个领域都发挥着至关重要的作用,本文为大家详细介绍了如何使用Java实现多张图片合成拼接,需要的可以了解下... 目录前言一、图片合成需求描述二、图片合成设计与实现1、编程语言2、基础数据准备3、图片合成流程4、图片合成实现三、总结前

使用Python在Excel中插入、修改、提取和删除超链接

《使用Python在Excel中插入、修改、提取和删除超链接》超链接是Excel中的常用功能,通过点击超链接可以快速跳转到外部网站、本地文件或工作表中的特定单元格,有效提升数据访问的效率和用户体验,这... 目录引言使用工具python在Excel中插入超链接Python修改Excel中的超链接Python

使用Python实现图片和base64转换工具

《使用Python实现图片和base64转换工具》这篇文章主要为大家详细介绍了如何使用Python中的base64模块编写一个工具,可以实现图片和Base64编码之间的转换,感兴趣的小伙伴可以了解下... 简介使用python的base64模块来实现图片和Base64编码之间的转换。可以将图片转换为Bas

css实现图片旋转功能

《css实现图片旋转功能》:本文主要介绍了四种CSS变换效果:图片旋转90度、水平翻转、垂直翻转,并附带了相应的代码示例,详细内容请阅读本文,希望能对你有所帮助... 一 css实现图片旋转90度.icon{ -moz-transform:rotate(-90deg); -webkit-transfo

C#从XmlDocument提取完整字符串的方法

《C#从XmlDocument提取完整字符串的方法》文章介绍了两种生成格式化XML字符串的方法,方法一使用`XmlDocument`的`OuterXml`属性,但输出的XML字符串不带格式,可读性差,... 方法1:通过XMLDocument的OuterXml属性,见XmlDocument类该方法获得的xm

C#提取PDF表单数据的实现流程

《C#提取PDF表单数据的实现流程》PDF表单是一种常见的数据收集工具,广泛应用于调查问卷、业务合同等场景,凭借出色的跨平台兼容性和标准化特点,PDF表单在各行各业中得到了广泛应用,本文将探讨如何使用... 目录引言使用工具C# 提取多个PDF表单域的数据C# 提取特定PDF表单域的数据引言PDF表单是一

C#实现添加/替换/提取或删除Excel中的图片

《C#实现添加/替换/提取或删除Excel中的图片》在Excel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更加美观,下面我们来看看如何在C#中实现添加/替换/提取或删除E... 在Excandroidel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更

C#中图片如何自适应pictureBox大小

《C#中图片如何自适应pictureBox大小》文章描述了如何在C#中实现图片自适应pictureBox大小,并展示修改前后的效果,修改步骤包括两步,作者分享了个人经验,希望对大家有所帮助... 目录C#图片自适应pictureBox大小编程修改步骤总结C#图片自适应pictureBox大小上图中“z轴