




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
第利用Matlab提取圖片曲線%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GUI.fig=figure('units','pixels',...
'position',[350100800500],...
'Numbertitle','off',...
'menubar','none',...
'resize','off',...
'name','getcolor',...
'color',[0.950.950.95]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uh1=uimenu('label','設置');
uimenu(uh1,'label','RGB類型設置','callback',@RGBset)
functionRGBset(~,~)
GUI.rgbfig=figure('units','pixels',...
'position',[360370180200],...
'Numbertitle','off',...
'menubar','none',...
'name','RGBset',...
'resize','off');
GUI.axes=axes('Units','pixels',...
'parent',GUI.rgbfig,...
'PlotBoxAspectRatio',[111],...
'Color',[0.950.950.95],...
'Box','on',...
'XLim',[0500],...
'YLim',[0500],...
'XColor',[0.950.950.95],...
'YColor',[0.950.950.95],...
'YDir','reverse',...
'xtick',[],'ytick',[]);
GUI.checkbox1=uicontrol('parent',GUI.rgbfig,...
'style','checkbox',...
'string','范圍:0-1',...
'position',[4515040030],...
'fontsize',10,...
'value',rgb_type,...
'callback',@ifon1);
GUI.checkbox255=uicontrol('parent',GUI.rgbfig,...
'style','checkbox',...
'string','范圍:0-255',...
'position',[4512040030],...
'fontsize',10,...
'value',~rgb_type,...
'callback',@ifon255);
GUI.makesurebutton=uicontrol('parent',GUI.rgbfig,...
'style','pushbutton',...
'string','確定設置',...
'position',[457010025],...
'fontsize',10,...
'callback',@settype);
functionifon1(~,~)
if(get(GUI.checkbox1,'value')==1)
set(GUI.checkbox1,'value',1);
set(GUI.checkbox255,'value',0);
else
set(GUI.checkbox1,'value',1);
end
functionifon255(~,~)
if(get(GUI.checkbox255,'value')==1)
set(GUI.checkbox255,'value',1);
set(GUI.checkbox1,'value',0);
else
set(GUI.checkbox255,'value',1);
end
functionsettype(~,~)
rgb_type=get(GUI.checkbox1,'value');
if~isempty(color)
set(GUI.text2,'string',['[',num2str((color/255).*rgb_type+color.*(~rgb_type)),']']);
show_color(page);
close(GUI.rgbfig)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uh2=uimenu('label','保存');
uimenu(uh2,'label','儲存為mat','callback',@saveas_mat)
uimenu(uh2,'label','儲存為txt','callback',@saveas_txt)
uimenu(uh2,'label','儲存為excel','callback',@saveas_exl)
uimenupic=uimenu(uh2,'label','儲存為對照圖');
uimenu(uimenupic,'label','儲存全部頁碼','callback',@saveas_pic_all);
uimenu(uimenupic,'label','儲存當前頁碼','callback',@saveas_pic_now);
functionsaveas_mat(~,~)
[filename,pathname]=uiputfile({'*.mat','mat'});
color_list_temp=(color_list/255).*rgb_type+color_list.*(~rgb_type);
save([pathname,filename],'color_list_temp');
catch
end
functionsaveas_txt(~,~)
try
[filename,pathname]=uiputfile({'*.txt','記事本'});
color_list_temp=(color_list/255).*rgb_type+color_list.*(~rgb_type);
[m,n]=size(color_list_temp);
fid=fopen([pathname,filename],'w');
forii=1:m
forjj=1:n
ifjj==n
fprintf(fid,'%d\r\n',color_list_temp(ii,jj));
else
fprintf(fid,'%d\r\t',color_list_temp(ii,jj));
fclose(fid);
catch
functionsaveas_exl(~,~)
[filename,pathname]=uiputfile({'*.xlsx','記事本'});
color_list_temp=(color_list/255).*rgb_type+color_list.*(~rgb_type);
xlswrite([pathname,filename],color_list_temp)
functionsaveas_pic_all(~,~)
page_with_color=total_1;
px=50;
gap_px=10;
pic=ones(9*px,page_with_color*px+(page_with_color-1)*gap_px,3);
forp=1:page_with_color
forii=(p-1)*9+1:p*9
forkk=1:3
ifii=length(color_list)
pic((ii-(p-1)*9-1)*px+1:(ii-(p-1)*9)*px,(p-1)*(px+gap_px)+1:(p-1)*(px+gap_px)+px,kk)=color_list(ii,kk)/255;
[filename,pathname]=uiputfile({'*.jpg;*.png','AllImageFiles';...
'*.jpg','JPG';'*.png','PNG'});
imwrite(pic,[pathname,filename]);
functionsaveas_pic_now(~,~)
[m,~]=size(color_list);
m=m-(1)*9;
m(m9)=9;
px=50;
pic=ones(9*px,1*px,3);
ifm0
forii=(1)*9+1:(1)*9+m
forkk=1:3
pic((ii-1)*px+1:ii*px,1:px,kk)=color_list(ii,kk)/255;
else
[filename,pathname]=uiputfile({'*.jpg;*.png','AllImageFiles';...
'*.jpg','JPG';'*.png','PNG'});
imwrite(pic,[pathname,filename]);
catch
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%uh3=uimenu('label','導入');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GUI.text=uicontrol('parent',GUI.fig,...
'style','text',...
'string','色彩識別',...
'horizontalalign','center',...
'position',[5044040030],...
'backgroundcolor',[0.850.890.85],...
'foregroundcolor','k',...
'fontsize',15);
GUI.text1=uicontrol('parent',GUI.fig,...
'style','text',...
'string','',...
'horizontalalign','center',...
'position',[460330100100],...
'backgroundcolor',[111],...
'foregroundcolor','k',...
'fontsize',10);
GUI.text2=uicontrol('parent',GUI.fig,...
'style','text',...
'string','',...
'horizontalalign','center',...
'position',[35044021030],...
'backgroundcolor',[111],...
'foregroundcolor','k',...
'fontsize',10);
GUI.savecolorbutton=uicontrol('parent',GUI.fig,...
'style','pushbutton',...
'string','儲存顏色',...
'position',[46029010030],...
'backgroundcolor',[0.850.890.85],...
'foregroundcolor','k',...
'fontsize',15,...
'callback',@save_color);
GUI.deletedatabutton=uicontrol('parent',GUI.fig,...
'style','pushbutton',...
'string','清空數(shù)據(jù)',...
'position',[46023010030],...
'backgroundcolor',[0.80.90.9],...
'foregroundcolor','k',...
'fontsize',15,...
'callback',@clear_data);
GUI.deletepicbutton=uicontrol('parent',GUI.fig,...
'style','pushbutton',...
'string','刪除圖片',...
'position',[46018010030],...
'backgroundcolor',[0.80.90.9],...
'foregroundcolor','k',...
'fontsize',15,...
'callback',@delete_pic);
GUI.getcapbutton=uicontrol('parent',GUI.fig,...
'style','pushbutton',...
'string','屏幕截圖',...
'position',[46013010030],...
'backgroundcolor',[0.80.90.9],...
'foregroundcolor','k',...
'fontsize',15,...
'callback',@get_capture);
GUI.getpicbutton=uicontrol('parent',GUI.fig,...
'style','pushbutton',...
'string','讀取圖片',...
'position',[4608010030],...
'backgroundcolor',[0.80.90.9],...
'foregroundcolor','k',...
'fontsize',15,...
'callback',@getImage);
GUI.getcolorbutton=uicontrol('parent',GUI.fig,...
'style','pushbutton',...
'tag','recc',...
'string','獲取顏色',...
'position',[4603010030],...
'backgroundcolor',[0.80.90.9],...
'foregroundcolor','k',...
'fontsize',15,...
'callback',@get_color);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fori=1:9
GUI.text=uicontrol('parent',GUI.fig,...
'tag',num2str(i),...
'style','text',...
'string','',...
'horizontalalign','left',...
'position',[600440-40*(i-1)3030],...
'backgroundcolor',[111],...
'foregroundcolor','k',...
'fontsize',10);
fori=1:9
GUI.text=uicontrol('parent',GUI.fig,...
'tag',[num2str(i),'t'],...
'style','text',...
'string','',...
'horizontalalign','center',...
'position',[640440-40*(i-1)15030],...
'backgroundcolor',[111],...
'foregroundcolor','k',...
'fontsize',8);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GUI.inputbutton=uicontrol('parent',GUI.fig,...
'style','pushbutton',...
'string','清除最后一個顏色',...
'position',[6008019030],...
'backgroundcolor',[0.850.890.85],...
'foregroundcolor','k',...
'fontsize',15,...
'callback',@delete_last);
%GUI.inputbutton=uicontrol('parent',GUI.fig,...
%'style','pushbutton',...
%'string','導出數(shù)據(jù)',...
%'position',[6003019030],...
%'backgroundcolor',[0.850.890.85],...
%'foregroundcolor','k',...
%'fontsize',15,...
%'callback',@output_data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GUI.lpbutton=uicontrol('parent',GUI.fig,...
'style','pushbutton',...
'string','上一頁',...
'position',[600307030],...
'backgroundcolor',[0.850.850.85],...
'foregroundcolor','k',...
'fontsize',12,...
'callback',@lastpage);
GUI.npbutton=uicontrol('parent',GUI.fig,...
'style','pushbutton',...
'string','下一頁',...
'position',[720307030],...
'backgroundcolor',[0.850.850.85],...
'foregroundcolor','k',...
'fontsize',12,...
'callback',@nextpage);
GUI.page=uicontrol('parent',GUI.fig,...
'style','text',...
'string',[num2str(page),'/',num2str(total_page)],...
'horizontalalign','center',...
'position',[670305027],...
'backgroundcolor',[0.950.950.95],...
'foregroundcolor','k',...
'fontsize',12);
functionlastpage(~,~)
page=1;
page(page1)=1;
set(GUI.page,'string',[num2str(page),'/',num2str(total_page)]);
show_color(page);
functionnextpage(~,~)
page=page+1;
page(pagetotal_page)=total_page;
set(GUI.page,'string',[num2str(page),'/',num2str(total_page)]);
show_color(page);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GUI.axes=axes('Units','pixels',...
'PlotBoxAspectRatio',[111],...
'Position',[5030400400],...
'Color',[0.980.980.98],...
'Box','on',...
'XLim',[0500],...
'YLim',[0500],...
'XColor','w','YColor','w',...
'YDir','reverse',...
'Tag','picbagaxes',...
'xtick',[],'ytick',[]);
holdon;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%functionoutput_data(~,~)
%ifcolor_number1
%disp(color_list)
%end
%end
functionshow_color(cur_page)
len_list=size(color_list,1);
forii=(cur_1)*9+1:(cur_1)*9+9
if(ii=len_list)
set(findobj('tag',num2str(ii-(cur_1)*9)),'backgroundcolor',color_list(ii,:)/255)
set(findobj('tag',[num2str(ii-(cur_1)*9),'t']),'string',['[',num2str((color_list(ii,:)/255).*rgb_type+color_list(ii,:).*(~rgb_type)),']'])
else
set(findobj('tag',num2str(ii-(cur_1)*9)),'backgroundcolor',[111])
set(findobj('tag',[num2str(ii-(cur_1)*9),'t']),'string','')
end
functionsave_color(~,~)
if~isempty(get(GUI.text2,'string'))
%set(findobj('tag',num2str(color_number)),'backgroundcolor',color/255)
%set(findobj('tag',[num2str(color_number),'t']),'string',['[',num2str((color/255).*rgb_type+color.*(~rgb_type)),']'])
color_list(color_number,:)=color;%(color/255).*rgb_type+color.*(~rgb_type);
color_number=color_number+1;
ifcolor_number-1(total_1)*9
page=ceil(color_number/9);
total_page=total_page+1;
set(GUI.page,'string',[num2str(page),'/',num2str(total_page)]);
show_color(page)
functiondelete_last(~,~)
ifcolor_number=1
%set(findobj('tag',num2str(color_number-1)),'backgroundcolor',[111])
%set(findobj('tag',[num2str(color_number-1),'t']),'string','')
color_list(end,:)=[];
color_number=color_number-1;
ifcolor_number-2=(total_2)*9
page=ceil((color_number-1)/9);
total_page=total_1;
set(GUI.page,'string',[num2str(page),'/',num2str(total_page)]);
show_color(page)
functiondelete_pic(~,~)
control=0;
set(findobj('Tag','picbagaxes'),...
'XLim',[0500],...
'YLim',[0500],...
'Position',[5030400400],...
'Color',[0.980.980.98]);
delete(a);
functionclear_data(~,~)
control=0;
set(GUI.text1,'backgroundcolor',[111]);
set(GUI.text2,'string','');
set(findobj('Tag','picbagaxes'),...
'XLim',[0500],...
'YLim',[0500],...
'Position',[5030400400],...
'Color',[0.980.980.98]);
set(findobj('tag','recc'),'string','獲取顏色');
delete(a);
functionget_color(~,~)
ifcontrol==0
set(GUI.text1,'backgroundcolor',[111]);
set(GUI.text2,'string','');
control=1;
set(gcf,'WindowButtonMotionFcn',@whilemovefcn)
set(gcf,'WindowButtonDownFcn',@whileclickfcn)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
functionwhilemovefcn(~,~)
xy=get(gca,'CurrentPoint');
x=xy(1,2);y=xy(1,1);
ifx=x_limity=y_limitx=0y=0
x(xx_limit)=x_limit;
y(yy_limit)=y_limit;
x(x1)=1;
y(y1)=1;
x=round(x);
y=round(y);
ifcontrol==1
color=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/255).*rgb_type+color.*(~rgb_type)),']']);
else
ifcontrol==1
set(GUI.text1,'backgroundcolor',[111]);
set(GUI.text2,'string','');
functionwhileclickfcn(~,~)
xy=get(gca,'CurrentPoint');
x=xy(1,2);y=xy(1,1);
ifx=x_limity=y_limitx=0y=0
control=0;
set(GUI.text1,'backgroundcolor',color/255);
set(GUI.text2,'string',['[',num2str((color/255).*rgb_type+color.*(~rgb_type)),']']);
set(findobj('tag','recc'),'string','繼續(xù)取色');
%disp(color/255)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
functionget_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','picbagaxes'),...
'XLim',[0leng],...
'YLim',[0leng]);
ima=cat(3,R,G,B);
delete(a);
a=imshow(ima);
functiongetImage(~,~)
warningoff;
[filename,pathname]=uigetfile({'*.jpg;*.tif;*.png;*.gif','AllImageFiles';...
'*.*','AllFiles'});
ima=imread([pathname,filename]);
[x,y,~]=size(ima);
x_limit=x;y_limit=y;
leng=max([x_limit,y_limit]);
set(findobj('Tag','picbagaxes'),...
'XLim',[0leng],...
'YLim',[0leng]);
delete(a);
a=imshow(ima);
catch
end
顏色轉(zhuǎn)換與色差計算
用RGB比較顏色之間的相似度時,存在很大的問題,不建議直接使用,因為往往一個通道的一點改變,會導致最后融合在一起的顏色發(fā)生巨大變化,而如果三個通道的同時改變,卻只會使最后的明暗發(fā)生變化,色調(diào)并不會產(chǎn)生巨大變化。而這也是H系列色彩空間普遍存在的問題。
所以,經(jīng)過思考,我決定RGB的值轉(zhuǎn)為HSV顏色空間,再進行色差計算。
色差計算,直接利用兩個點的顏色在椎體上的歐式距離,即通過計算如下坐標點的歐式距離。我們通過編寫color_dist函數(shù)計算。
%計算兩個HSV顏色之間的距離
functiond=color_dist(color_std,color)
[x0,y0,z0]=getPos(color_std(1),color_std(2),color_std(3));
[x,y,z]=getPos(color(1),color(2),color(3));
d=sqrt((x-x0).^2+(y-y0).^2+(z-z0)^2);
function[x,y,z]=getPos(H,S,V)
r=1;
h=sqrt(3);
x=r*V*S*cos(H);
y=r*V*S*sin(H);
z=h*(1-V);
%%顏色轉(zhuǎn)為HSV,再進行色差計算
A2=rgb2hsv(A);
color2=rgb2hsv(color);
D=ones(low_num,col_num)*2;
fori=1:low_num
forj=1:col_num
D(i,j)=color_dist(color2,A2(i,j,:));
mesh(D);
分離曲線
通過調(diào)節(jié)閾值參數(shù),可以把我們想要的坐標軸過濾掉。閾值越小,過濾效果越明顯。
%%根據(jù)色彩,把想要的曲線分離出來
threshold=0.5;%可以調(diào)整閾值使分離效果變好
I=(Dthreshold);
fori=1:3
RGB=A(:,:,i);
RGB(~I)=255;
A3(:,:,i)=RGB;
imshow(A3)
二值化,提取數(shù)據(jù)
二值化圖像是以矩陣形式存儲的。我們根據(jù)色素點在矩陣中的位置,利用行列指標和坐標軸的標準化關系,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 行政管理企業(yè)管理自考試題及答案
- 護士對臨床用藥的理解試題及答案
- 2025年經(jīng)濟法概論復習資料及試題答案
- 執(zhí)業(yè)護士備考期間自我激勵方法試題及答案
- 考試心得分享與執(zhí)業(yè)藥師試題及答案
- 2025中招考試英語專項訓練-補全對話含答案
- 行政法學重要人物與貢獻試題及答案
- 聚焦中國文化的試題及答案
- 行政法律法規(guī)的熱點問題及試題及答案
- 2025年執(zhí)業(yè)藥師考試藥品安全性評估試題及答案
- 制造業(yè)產(chǎn)品全生命周期管理流程
- 安全意識教育試題及答案
- SZDBZ 171-2016 物業(yè)服務人員管理規(guī)范
- 《食品營養(yǎng)與健康》課件
- 屋面保溫工程施工方案
- 課題申報書:大學中學融通視域下拔尖創(chuàng)新人才早期培養(yǎng)評價標準體系構建的實證研究
- 復旦大學-自主招生個人陳述自薦信標準范文
- 《東北風情課件》課件
- 土木工程專業(yè)就業(yè)能力展示
- 《初中數(shù)學家長會》課件
- 大學生國家安全教育知到智慧樹章節(jié)測試課后答案2024年秋廣西科技大學
評論
0/150
提交評論