?? color.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 + -