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

相关文章

Java实现将HTML文件与字符串转换为图片

《Java实现将HTML文件与字符串转换为图片》在Java开发中,我们经常会遇到将HTML内容转换为图片的需求,本文小编就来和大家详细讲讲如何使用FreeSpire.DocforJava库来实现这一功... 目录前言核心实现:html 转图片完整代码场景 1:转换本地 HTML 文件为图片场景 2:转换 H

Java实现在Word文档中添加文本水印和图片水印的操作指南

《Java实现在Word文档中添加文本水印和图片水印的操作指南》在当今数字时代,文档的自动化处理与安全防护变得尤为重要,无论是为了保护版权、推广品牌,还是为了在文档中加入特定的标识,为Word文档添加... 目录引言Spire.Doc for Java:高效Word文档处理的利器代码实战:使用Java为Wo

基于C#实现PDF转图片的详细教程

《基于C#实现PDF转图片的详细教程》在数字化办公场景中,PDF文件的可视化处理需求日益增长,本文将围绕Spire.PDFfor.NET这一工具,详解如何通过C#将PDF转换为JPG、PNG等主流图片... 目录引言一、组件部署二、快速入门:PDF 转图片的核心 C# 代码三、分辨率设置 - 清晰度的决定因

Python从Word文档中提取图片并生成PPT的操作代码

《Python从Word文档中提取图片并生成PPT的操作代码》在日常办公场景中,我们经常需要从Word文档中提取图片,并将这些图片整理到PowerPoint幻灯片中,手动完成这一任务既耗时又容易出错,... 目录引言背景与需求解决方案概述代码解析代码核心逻辑说明总结引言在日常办公场景中,我们经常需要从 W

Java+AI驱动实现PDF文件数据提取与解析

《Java+AI驱动实现PDF文件数据提取与解析》本文将和大家分享一套基于AI的体检报告智能评估方案,详细介绍从PDF上传、内容提取到AI分析、数据存储的全流程自动化实现方法,感兴趣的可以了解下... 目录一、核心流程:从上传到评估的完整链路二、第一步:解析 PDF,提取体检报告内容1. 引入依赖2. 封装

Java使用正则提取字符串中的内容的详细步骤

《Java使用正则提取字符串中的内容的详细步骤》:本文主要介绍Java中使用正则表达式提取字符串内容的方法,通过Pattern和Matcher类实现,涵盖编译正则、查找匹配、分组捕获、数字与邮箱提... 目录1. 基础流程2. 关键方法说明3. 常见场景示例场景1:提取所有数字场景2:提取邮箱地址4. 高级

使用Python实现无损放大图片功能

《使用Python实现无损放大图片功能》本文介绍了如何使用Python的Pillow库进行无损图片放大,区分了JPEG和PNG格式在放大过程中的特点,并给出了示例代码,JPEG格式可能受压缩影响,需先... 目录一、什么是无损放大?二、实现方法步骤1:读取图片步骤2:无损放大图片步骤3:保存图片三、示php

Python 字符串裁切与提取全面且实用的解决方案

《Python字符串裁切与提取全面且实用的解决方案》本文梳理了Python字符串处理方法,涵盖基础切片、split/partition分割、正则匹配及结构化数据解析(如BeautifulSoup、j... 目录python 字符串裁切与提取的完整指南 基础切片方法1. 使用切片操作符[start:end]2

使用Python提取PDF大纲(书签)的完整指南

《使用Python提取PDF大纲(书签)的完整指南》PDF大纲(Outline)​​是PDF文档中的导航结构,通常显示在阅读器的侧边栏中,方便用户快速跳转到文档的不同部分,大纲通常以层级结构组织,包含... 目录一、PDF大纲简介二、准备工作所需工具常见安装问题三、代码实现完整代码核心功能解析四、使用效果控

Linux从文件中提取特定内容的实用技巧分享

《Linux从文件中提取特定内容的实用技巧分享》在日常数据处理和配置文件管理中,我们经常需要从大型文件中提取特定内容,本文介绍的提取特定行技术正是这些高级操作的基础,以提取含有1的简单需求为例,我们可... 目录引言1、方法一:使用 grep 命令1.1 grep 命令基础1.2 命令详解1.3 高级用法2