intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

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

Chia sẻ: Asg Ahsva | Ngày: | Loại File: PDF | Số trang:11

67
lượt xem
9
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

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à lưu 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...

Chủ đề:
Lưu

Nội dung Text: Mạng thần kinh nhân tạo cho phân lớp màu sắc part 2

  1. 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µ l­u 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µ l­u 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 l­u 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. 266
  2. 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 #include #include #include #include #include #define white (circ
  3. #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(); 268
  4. SetScreen(0); SetInDispMode(); get_video_mode(&mode,&page); set_video_mode(0x12); CIE(); for(i=0;i
  5. 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': 270
  6. 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
  7. 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
  8. 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
  9. { delay(150); if(kount-1) kount--; } } else { gotoxy(11,2); printf("black. "); } } /* Routine to translate mouse movements to PIB screen. */ void move_cursor(x,y) 274
  10. 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 pa ge. */ 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. */ 275
  11. void set_video_mode( int set_mode) { union REGS reg; reg.h.ah=0x00; reg.h.al=set_mode; int86(0x10,&reg,&reg); } /* Routine to draw a straight line of any standard color to join two end 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
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2