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实现一个图片拆分工具

《基于Python实现一个图片拆分工具》这篇文章主要为大家详细介绍了如何基于Python实现一个图片拆分工具,可以根据需要的行数和列数进行拆分,感兴趣的小伙伴可以跟随小编一起学习一下... 简单介绍先自己选择输入的图片,默认是输出到项目文件夹中,可以自己选择其他的文件夹,选择需要拆分的行数和列数,可以通过

在Linux中改变echo输出颜色的实现方法

《在Linux中改变echo输出颜色的实现方法》在Linux系统的命令行环境下,为了使输出信息更加清晰、突出,便于用户快速识别和区分不同类型的信息,常常需要改变echo命令的输出颜色,所以本文给大家介... 目python录在linux中改变echo输出颜色的方法技术背景实现步骤使用ANSI转义码使用tpu

利用Python脚本实现批量将图片转换为WebP格式

《利用Python脚本实现批量将图片转换为WebP格式》Python语言的简洁语法和库支持使其成为图像处理的理想选择,本文将介绍如何利用Python实现批量将图片转换为WebP格式的脚本,WebP作为... 目录简介1. python在图像处理中的应用2. WebP格式的原理和优势2.1 WebP格式与传统

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

Python如何去除图片干扰代码示例

《Python如何去除图片干扰代码示例》图片降噪是一个广泛应用于图像处理的技术,可以提高图像质量和相关应用的效果,:本文主要介绍Python如何去除图片干扰的相关资料,文中通过代码介绍的非常详细,... 目录一、噪声去除1. 高斯噪声(像素值正态分布扰动)2. 椒盐噪声(随机黑白像素点)3. 复杂噪声(如伪

Python中图片与PDF识别文本(OCR)的全面指南

《Python中图片与PDF识别文本(OCR)的全面指南》在数据爆炸时代,80%的企业数据以非结构化形式存在,其中PDF和图像是最主要的载体,本文将深入探索Python中OCR技术如何将这些数字纸张转... 目录一、OCR技术核心原理二、python图像识别四大工具库1. Pytesseract - 经典O

Python中提取文件名扩展名的多种方法实现

《Python中提取文件名扩展名的多种方法实现》在Python编程中,经常会遇到需要从文件名中提取扩展名的场景,Python提供了多种方法来实现这一功能,不同方法适用于不同的场景和需求,包括os.pa... 目录技术背景实现步骤方法一:使用os.path.splitext方法二:使用pathlib模块方法三

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

OpenCV实现实时颜色检测的示例

《OpenCV实现实时颜色检测的示例》本文主要介绍了OpenCV实现实时颜色检测的示例,通过HSV色彩空间转换和色调范围判断实现红黄绿蓝颜色检测,包含视频捕捉、区域标记、颜色分析等功能,具有一定的参考... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间

苹果macOS 26 Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色

《苹果macOS26Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色》在整体系统设计方面,macOS26采用了全新的玻璃质感视觉风格,应用于Dock栏、应用图标以及桌面小部件等多个界面... 科技媒体 MACRumors 昨日(6 月 13 日)发布博文,报道称在 macOS 26 Tahoe 中