⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 color.m

📁 color recognition for matlab
💻 M
字号:
clear all;
count=0;fcount=0;
sall=0;sx=0;sy=0;
disp ('The file "color.txt" contains these images for testing:');


fid=fopen('color.txt');
while ~feof(fid) 
       fcount=fcount+1;
       tline = fgetl(fid);
   if isempty(tline), break, end
   disp(tline);
Testname {fcount}=sprintf(tline);
end
fclose(fid);

fid=fopen('color_results.txt','w');


for nn=1:fcount
% ********************************this is the main loop ***********************

x=Testname(nn)


Raw=imread(char(x));
R=Raw(:,:,1);
G=Raw(:,:,2);
B=Raw(:,:,3);


[f,h]=imhist(R);
[mass, red]= max(f);
[f1,h1]=imhist(G);
[mass1, green]= max(f1);
[f2,h2]=imhist(B);
[mass2, blue]= max(f2);

disp('the car color is:');
disp(red);
disp(green);
disp(blue);

Color_Names= {'White'; 'Black'; 'Silver'; 'Carbon';'Dark Blue';'Light Blue';'Red';'Pink';'Brown';'Yellow';'Orange';'Blue Green';'Green'};
CM=[255 255 255; 0 0 0; 238 224 229; 150 150 150;00 00 128;100 149 237;255 0 0;255 105 180;139 71 38;255 255 0;255 165 0;127 255 212;84 139 84];
for cc=1:13
xcolor(cc)=(CM(cc,1)-red)*(CM(cc,1)-red)+(CM(cc,2)-green)*(CM(cc,2)-green)+(CM(cc,3)-blue)*(CM(cc,3)-blue); 
end
[num,color_code] =min(xcolor);
disp('color found is:');disp( Color_Names(color_code));

end
% ********************************end of main loop ******************
fclose(fid);
figure;
imhist(R)
figure;
imhist(G)
figure;
imhist(B)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -