Giáo trình xử lý ảnh y tế Tập 3 P2 pot

9 322 0
Giáo trình xử lý ảnh y tế Tập 3 P2 pot

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

Thông tin tài liệu

264 printf("\n w[0]=%f W[1]=%f",w[0], w[1]); exit(1); } if(kbhit()!=0) { gotoxy(1,7); if(getch()==27) { printf("\n w[0]=%f w[1]=%f",w[0],w[1]); exit(1); } } } } Trên đĩa đi kèm đã có sẵn file dữ liệu có tên là "TINT.DAT" rút ra từ sơ đồ màu. Dùng  = 0.8 và  = 0.2, phải mất gần 200 lần lặp để làm cho sai số giảm từ 28 xuống 9,55. Sau 15,000 phép lặp sai số đã giảm xuống nhỏ hơn 1 và tiếp tục giảm xuống. Thay  = 0.2 và  = 0.8 sự hội tụ sẽ chậm hơn. Trước khi chúng ta nghiên cứu một phương pháp tốt hơn cho tính toán giá trị cảm nhận, chúng tôi sẽ cung cấp cho bạn công cụ thu nhập dữ liệu. 12.4 Thu nhập dữ liệu cho các lớp màu sắc Chương trình cho ở dưới đây chỉ làm việc trên vỉ mạch ATI PIB đã được đề cập đến trong chương 11. Bạn có thể sửa đổi làm cho nó tương thích với các phần cứng thông dụng; các sửa đổi này không có gì là khó khăn lắm. Chương trình này có sử dụng chuột. Nếu bạn có vỉ mạch ATI PIB , đầu tiên bạn cần nạp một ảnh trên màn hình PIB. Chạy chương trình và con trỏ sẽ xuất hiện trên màn hình. Dùng chuột, thay thế con trỏ trên sắc màu mà bạn muốn tách ra (một perceptron đơn thì sẽ không thể tách ra được một sắc màu; chúng ta sẽ đề cập đến việc tách các sắc màu ở phần cuối chương nà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 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 265 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. 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 266 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) #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); 267 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(); 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) { 268 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"); } 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); 269 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': 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; { 270 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. */ 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); 271 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); 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); 272 printf("blue. "); } else if(cyan) { gotoxy(11,2); printf("cyan. "); } for(i=0;i<100;i++) read_mouse(&row,&col,&button); if(button==LBUTTON) { 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 { . X=2.769*R+1.7518*G+1. 130 0*B; Y= R+4.5907*G+0.0601*B; Z=0.0565*G+5.59 43* B; D=X +Y+ Z ; x=X/D; y= Y/D; circ=sqr(x-0 .33 3)+sqr (y- 0 .33 3)-sqr(r); 271 for(i=0;i<7;i++) { lt=m[i]*x+c[i] -y; if(lt<0.0). 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.6 633 17, -1.029762, -61.75, 0 .38 4, -0.875}; float c[]={-0.785880, -0.086671,. { 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);

Ngày đăng: 10/07/2014, 22:20

Từ khóa liên quan

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

Tài liệu liên quan