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实现高效PPT转图片工具

《基于Python实现高效PPT转图片工具》在日常工作中,PPT是我们常用的演示工具,但有时候我们需要将PPT的内容提取为图片格式以便于展示或保存,所以本文将用Python实现PPT转PNG工具,希望... 目录1. 概述2. 功能使用2.1 安装依赖2.2 使用步骤2.3 代码实现2.4 GUI界面3.效

Python实现AVIF图片与其他图片格式间的批量转换

《Python实现AVIF图片与其他图片格式间的批量转换》这篇文章主要为大家详细介绍了如何使用Pillow库实现AVIF与其他格式的相互转换,即将AVIF转换为常见的格式,比如JPG或PNG,需要的小... 目录环境配置1.将单个 AVIF 图片转换为 JPG 和 PNG2.批量转换目录下所有 AVIF 图

详解如何通过Python批量转换图片为PDF

《详解如何通过Python批量转换图片为PDF》:本文主要介绍如何基于Python+Tkinter开发的图片批量转PDF工具,可以支持批量添加图片,拖拽等操作,感兴趣的小伙伴可以参考一下... 目录1. 概述2. 功能亮点2.1 主要功能2.2 界面设计3. 使用指南3.1 运行环境3.2 使用步骤4. 核

Java图片压缩三种高效压缩方案详细解析

《Java图片压缩三种高效压缩方案详细解析》图片压缩通常涉及减少图片的尺寸缩放、调整图片的质量(针对JPEG、PNG等)、使用特定的算法来减少图片的数据量等,:本文主要介绍Java图片压缩三种高效... 目录一、基于OpenCV的智能尺寸压缩技术亮点:适用场景:二、JPEG质量参数压缩关键技术:压缩效果对比

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整

使用C#代码在PDF文档中添加、删除和替换图片

《使用C#代码在PDF文档中添加、删除和替换图片》在当今数字化文档处理场景中,动态操作PDF文档中的图像已成为企业级应用开发的核心需求之一,本文将介绍如何在.NET平台使用C#代码在PDF文档中添加、... 目录引言用C#添加图片到PDF文档用C#删除PDF文档中的图片用C#替换PDF文档中的图片引言在当

详解C#如何提取PDF文档中的图片

《详解C#如何提取PDF文档中的图片》提取图片可以将这些图像资源进行单独保存,方便后续在不同的项目中使用,下面我们就来看看如何使用C#通过代码从PDF文档中提取图片吧... 当 PDF 文件中包含有价值的图片,如艺术画作、设计素材、报告图表等,提取图片可以将这些图像资源进行单独保存,方便后续在不同的项目中使

Java实现文件图片的预览和下载功能

《Java实现文件图片的预览和下载功能》这篇文章主要为大家详细介绍了如何使用Java实现文件图片的预览和下载功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... Java实现文件(图片)的预览和下载 @ApiOperation("访问文件") @GetMapping("

python+opencv处理颜色之将目标颜色转换实例代码

《python+opencv处理颜色之将目标颜色转换实例代码》OpenCV是一个的跨平台计算机视觉库,可以运行在Linux、Windows和MacOS操作系统上,:本文主要介绍python+ope... 目录下面是代码+ 效果 + 解释转HSV: 关于颜色总是要转HSV的掩膜再标注总结 目标:将红色的部分滤