Mạng thần kinh nhân tạo cho phân lớp màu sắc part 2 pps

11 200 0
Mạng thần kinh nhân tạo cho phân lớp màu sắc part 2 pps

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

266 Lấy rất nhiều các giá trị từ một loạt các điểm trên miền đã lựa chọn sắc màu bằng cách nhắp đơn nút trái chuột. Chú ý là màn hình VGA sẽ hiện lên biểu đồ màu và cờng độ màu tại nơi mà bạn trỏ tới. Nơi mà bạn kích vào sẽ đánh dấu bằng một dấu thập màu đỏ trên biểu đồ màu vẽ trên màn hình VGA (xem hình 12.6) và lu nó vào một mảng. Nếu bạn muốn dời dấu thập đi chỗ khác trong trờng hợp các điểm nhập vào lớn hơn một, thì nhắp nút trái chuột nhiều lần. Hành động này sẽ làm dời đi rất nhiều điểm tuỳ theo bạn chọn (bắt đầu từ điểm cuối cùng) từ biểu đồ màu và lu trong mảng. Khi bạn ấn ESC, con trỏ sẽ xuất hiện trên màn hình VGA. Đa con trỏ vào sơ đồ màu vẽ trên màn hình VGA, bằng cách kích lại nút trái chuột ta sẽ thu đợc dữ liệu cho một lớp màu khác. Nhắp nút trái chuột, nh trớc đây, sẽ làm dịch chuyển đến đầu vào cuối cùng. Chú ý rằng một dấu thập màu xanh sẽ xuất hiện bất cứ khi nào bạn nhắp trái chuột, và sẽ bị dời đi khi bạn nhắp phải chuột. Nhấn ESC để thoát. Bạn sẽ đợc hỏi tên file cho chứa dữ liệu. Dữ liệu đợc lu trữ bao gồm 3 số: số đầu tiên biểu diễn cho x, số thứ hai biểu diễn cho y, và số cuối cùng xác định lớp. Giá trị lớp này đợc gán bằng 1 trong trờng hợp lựa chọn sắc màu và 0 trong các trờng hợp còn lại. Dữ liệu đợc cho dới dạng "%f%f%d". Kết quả ta thu đợc là một cung màu trên biểu đồ màu đợc tách ra từ phần còn lại của phổ màu. Hình 12.6 Thu thập dữ liệu cho phân lớp màu sắc. 267 Ch¬ng tr×nh 12.2 COLORRDM.C. Ch¬ng tr×nh thu thËp d÷ liÖu; §îc dïng víi PIB. /************************************ * Developed by M.A.Sid_Ahmed. * * ver. 1.0, 1992. * * @ 1994 *************************************/ /* Program to read color from PIB screen. It also classifies color according to colors in Chromaticity diagram. Use mouse left button to enter x.y coordinates and right button to erase as many previous entries as you wish. The cursor will initially point to the PIB screen, use the mouse to enter the tone you wish to classify as one color set. Press ESC to exit from PIB screen. The cursor mouse will appear on VGA screen. Use mouse to point at points in the Chromaticity diagram that do not belong to the set of colors you wish to classify. Use left button to enter a point, right button to erase previous entry or entries. Press ESC again to exit and store data. */ #include <stdio.h> #include <conio.h> #include <dos.h> #include <math.h> #include <io.h> #include <custom.h> #define white (circ<0) 268 #define green (l[0]&&l[6]) #define yellow ((!l[0])&&l[1]) #define skin_tone ((!l[1])&&l[2]) #define red ((!l[2])&&l[3]) #define magenta ((!l[3])&&l[4]) #define blue ((!l[4]&&(!l[53)) #define cyan (l[5]&&(!l[6])) #define ESC 0x1B #define LBUTTON 0x01 #define RBUTTON 0x02 void make_cursor(int,int); void find_color(int,int); void move_cursor(int,int); void get_video_mode(int *,int *); void set_video_mode(int); void mouse_cursor_on(void); void mouse_cursor_off(void); void read_mouse(int *, int *, int *); void draw_line(int,int,int,int,int); void draw_circle(int,int,int,int); void set_pixel(int,int,int); void mouse_vrange(int,int); void mouse_hrange(int,int); void set_mouse(int,int); void CIE(void); void draw_cross(float,float,int); int kount=-1; float xold[200],yold[200]; int set[200]; void main() { int mode,page,row,col,button,ind,i; float x,y; char ch,file_name[14]; FILE *fptr; clrscr(); InitPIB(); 269 SetScreen(0); SetInDispMode(); get_video_mode(&mode,&page); set_video_mode(0x12); CIE(); for(i=0;i<100;i++) read_mouse(&row,&col,&button); row=100; col=200; set_mouse(row,col); read_mouse(&row, &col, &button); gotoxy(1,18); make_cursor(col, row); find_color(col, row); move_cursor (col, row); mouse_vrange(5,480); mouse_hrange( 5,640); mouse_cursor_on(); ind=1; while(ind) { for(i=0;i<100;i++) read_mouse(&row,&col,&button); gotoxy(1,19); printf("row_%d, col_%d",row,col); if(button==LBUTTON) { delay(150); x=((float)col-200.0)/400.0; y=(400.0-(float)row)/250.0; gotoxy(1,15); printf("x=%f y=%f ",x,y); draw_cross(x,y,GREEN); if(kount<200) kount++; else { gotoxy(1,4); printf("Max. total number data points should not exceed 200.\n"); } 270 xold[kount]=x; yold[kount]=y; set[kount]=0; gotoxy(1,3); printf("x=%f y=%f set=%2d total number of points=%4d", xold[kount],yold[kount],set[kount],kount); } else if(button==RBUTTON) { delay(150); draw_cross(xold[kount],yold[kount],BLACK); if(kount>-1) kount ; gotoxy(1,3); printf("x=%f y=%f set=%2d total number of points=%4d", xold[kount],yold[kount],set[kount],kount); } if(kbhit()!=0) { if(getch()==ESC) ind=0; } } gotoxy(1,5); printf("Do you wish to save data? (y or n) >"); while(((ch=getch())!='y')&&(ch!='n')); switch(ch) { case 'y': printf("\n Enter file name >"); scanf("%s",file_name); ind=access(file_name,0); while(!ind) { printf("File exists. Wish to overwrite? (y or n) >"); while(((ch=getch())!='y')&&(ch!='n')); switch(ch) { case 'y': 271 ind=1; break; case 'n': gotoxy(1,6); printf("\n Enter file name > "); scanf("%s",file_name); ind=access(file_name,0); } } fptr=fopen(file_name,"w"); for(i=0;i<kount;i++) fprintf(fptr,"%f %f %d ", xold[i],yold[i],set[i]); break; case 'n': break; } fclose(fptr); set_video_mode(mode); } /* Routine to draw cursor on PIB screen. */ void make_cursor(x,y) int x,y; { int i,j; unsigned value=0xffff; for(i=x-5;i<x+6;i++) PutPixel(&value,i,y,1); for(j=y-5;j<y+6;j++) PutPixel(&value,x,j,1); } #define sqr(x) ((x)*(x)) /* Routine to read and classify colors from PIB screen. */ 272 void find_color(x1,y1) { unsigned int color,R,G,B; float X,Y,Z,D,x,y; int row,col,button; float m[]={3.3600, 1.260274, 0.663317, - 1.029762, -61.75, 0.384, -0.875}; float c[]={-0.785880, -0.086671, 0.112116, 0.675911, 20.89575, 0.205128, 0.624375}; float r=0.01; float lt,circ; int l[7], i; GetPixel(&color,x1,y1); B=(0x001F & color); G=(0x03E0 & color)>>5; R=(0x7C00 & color)>>10; gotoxy(1,1); printf(" blue= %5u, oreen=%5u, red=%5u ",B,G,R); if(R+G+B) { X=2.769*R+1.7518*G+1.1300*B; Y=R+4.5907*G+0.0601*B; Z=0.0565*G+5.5943*B; D=X+Y+Z ; x=X/D; y=Y/D; circ=sqr(x-0.333)+sqr(y-0.333)-sqr(r); for(i=0;i<7;i++) { lt=m[i]*x+c[i]-y; if(lt<0.0) l[i]=1; else l[i]=0; } gotoxy(1,2); printf("Color is:"); if(white) { gotoxy(11,2); 273 printf("white. "); } else if(green) { gotoxy(11,2); printf("green. "); } else if(yellow) { gotoxy(11,2); printf("yellow. "); } else if(skin_tone) { gotoxy(11,2); printf("Skin tone."); } else if(red) { gotoxy(11,2); printf("red. "); } else if(magenta) { gotoxy(11,2); printf("magenta. "); } else if(blue) { gotoxy(11,2); printf("blue. "); } else if(cyan) { gotoxy(11,2); printf("cyan. "); } for(i=0;i<100;i++) read_mouse(&row,&col,&button); if(button==LBUTTON) 274 { delay(150); if(kount<200) kount++; else { gotoxy(1,4); printf("Max. total number data points should not exceed 200.\n"); } draw_cross(x,y,RED); xold[kount]=x; yold[kount]=y; set[kount]=(char)1; gotoxy(1,3); printf("x=%f y=%f set=%2d total number of points=%4d", xold[kount],yold[kount],set[kount],kount); } else if(button==RBUTTON) { delay(150); gotoxy(1,3); printf("x=%f y=%f set=%2d total number of points=%4d", xold[kount],yold[kount],set[kount],kount); draw_cross(xold[kount],yold[kount],BLACK); if(kount>-1) kount ; } } else { gotoxy(11,2); printf("black. "); } } /* Routine to translate mouse movements to PIB screen. */ void move_cursor(x,y) 275 int x,y; { int ind,row,col,button; char ch; mouse_vrange(5,250); mouse_hrange(5,500); ind=1; while (ind) { make_cursor(x,y); read_mouse(&row,&col,&button); x=col; y=row; make_cursor(x,y); find_color(x,y); if(kbhit()!=0) { ch=getch(); if(ch==ESC) { make_cursor(x,y); ind=0; } } } } /* Routine to obtain video mode and active page. */ void get_video_mode(int *display_mode,int *active_page) { union REGS reg; reg.h.ah=0x0F; int86(0x10,&reg,&reg); *display_mode=reg.h.al; *active_page=reg.h.bh; } /* Routine to change to one of the VGA/EGA modes. */ [...]... points (xl,yl) and (x2,y2) using Bresenham's algorithm */ void draw_line(x1,y1,x2,y2,color) { int dx,dy,x,y,x_end,y_end,p,const1,const2,ind; /* Bresenham's line algorithm */ dx=abs(x1-x2); dy=abs(y1-y2); if((dx==0)&&(dy==0)) { set_pixel(x1,y1,color); return; } else if(dy==0) { if(x1>x2) { x_end=x1; x=x2 ; } else { x_end=x2; x=x1; } while(x . biểu đồ màu đợc tách ra từ phần còn lại của phổ màu. Hình 12. 6 Thu thập dữ liệu cho phân lớp màu sắc. 26 7 Ch¬ng tr×nh 12. 2 COLORRDM.C. Ch¬ng tr×nh thu thËp d÷ liÖu; §îc dïng víi. lựa chọn sắc màu và 0 trong các trờng hợp còn lại. Dữ liệu đợc cho dới dạng "%f%f%d". Kết quả ta thu đợc là một cung màu trên biểu đồ màu đợc tách ra từ phần còn lại của phổ màu. . PIB screen. */ 27 2 void find_color(x1,y1) { unsigned int color,R,G,B; float X,Y,Z,D,x,y; int row,col,button; float m[]={3.3600, 1 .26 027 4, 0.663317, - 1. 029 7 62, -61.75, 0.384,

Ngày đăng: 29/07/2014, 04:20

Tài liệu cùng người dùng

Tài liệu liên quan