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

相关文章

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk

Spring MVC 图片上传

引入需要的包 <dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.1</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-

Prompt - 将图片的表格转换成Markdown

Prompt - 将图片的表格转换成Markdown 0. 引言1. 提示词2. 原始版本 0. 引言 最近尝试将图片中的表格转换成Markdown格式,需要不断条件和优化提示词。记录一下调整好的提示词,以后在继续优化迭代。 1. 提示词 英文版本: You are an AI assistant tasked with extracting the content of

matlab读取NC文件(含group)

matlab读取NC文件(含group): NC文件数据结构: 代码: % 打开 NetCDF 文件filename = 'your_file.nc'; % 替换为你的文件名% 使用 netcdf.open 函数打开文件ncid = netcdf.open(filename, 'NC_NOWRITE');% 查看文件中的组% 假设我们想读取名为 "group1" 的组groupName

利用matlab bar函数绘制较为复杂的柱状图,并在图中进行适当标注

示例代码和结果如下:小疑问:如何自动选择合适的坐标位置对柱状图的数值大小进行标注?😂 clear; close all;x = 1:3;aa=[28.6321521955954 26.2453660695847 21.69102348512086.93747104431360 6.25442246899816 3.342835958564245.51365061796319 4.87

C# double[] 和Matlab数组MWArray[]转换

C# double[] 转换成MWArray[], 直接赋值就行             MWNumericArray[] ma = new MWNumericArray[4];             double[] dT = new double[] { 0 };             double[] dT1 = new double[] { 0,2 };

研究人员在RSA大会上演示利用恶意JPEG图片入侵企业内网

安全研究人员Marcus Murray在正在旧金山举行的RSA大会上公布了一种利用恶意JPEG图片入侵企业网络内部Windows服务器的新方法。  攻击流程及漏洞分析 最近,安全专家兼渗透测试员Marcus Murray发现了一种利用恶意JPEG图片来攻击Windows服务器的新方法,利用该方法还可以在目标网络中进行特权提升。几天前,在旧金山举行的RSA大会上,该Marcus现场展示了攻击流程,

恶意PNG:隐藏在图片中的“恶魔”

&lt;img src=&quot;https://i-blog.csdnimg.cn/blog_migrate/bffb187dc3546c6c5c6b8aa18b34b962.jpeg&quot; title=&quot;214201hhuuhubsuyuukbfy_meitu_1_meitu_2.jpg&quot;/&gt;&lt;/strong&gt;&lt;/span&gt;&lt;

PHP抓取网站图片脚本

方法一: <?phpheader("Content-type:image/jpeg"); class download_image{function read_url($str) { $file=fopen($str,"r");$result = ''; while(!feof($file)) { $result.=fgets($file,9999); } fclose($file); re