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

9 221 0
Giáo trình xử lý ảnh y tế Tập 3 P3 pptx

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

Thông tin tài liệu

273 gotoxy(11,2); printf("black. "); } } /* Routine to translate mouse movements to PIB screen. */ void move_cursor(x,y) 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); 274 *display_mode=reg.h.al; *active_page=reg.h.bh; } /* Routine to change to one of the VGA/EGA modes. */ 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; } 275 while(x<=x_end) { set_pixel(x,y1,color); x++; } return; } else if(dx==0) { if(y1>y2) { y_end=y1; y=y2; } else y_end=y2 ; y=y1; } while(y<=y_end) { set_pixel(x1,y,color); y++; } return; } else { if(dy<=dx) { if(x1>x2) { x_end=x1; y_end=y1; x=x2; y=y2; } else { x=x1; y=y1; x_end=x2; y_end=y2; } 276 if(y_end>y) ind=1; else ind=0; p=2*dy-dx; const1=2*dy; const2=2*(dy-dx); set_pixel(x,y,color); while((x < x_end)) { x++; if(p<0) p+=const1; else { if(ind) y++; else y ; p+=const2; } set_pixel(x,y,color); } set_pixel(x,y,color); } else { if(y1>y2) { x_end=x1; y_end=y1; x=x2; y=y2; } else { x_end=x2; y_end=y2; x=x1; y=y1; } if(x_end>x) ind=1; else ind=0; p=2*dx-dy ; const1=2*dx; const2=2*(dx-dy); set_pixel(x,y,color); 277 while((y < y_end)) { y++; if(p<0) p+=const1; else { if(ind) x++: else x ; p+=const2; } set_pixel(x,y,color); } set_pixel(x,y,color); } } } /* Routine to draw a circle of any color given the radius, land cent re. It uses Bresenham's algorithm for circle drawing . */ void draw_circle(int x_centre, int y_centre, int radius,int color) { int p,x,y; x=0; y=radius; p=3-2*radius; while(x<y) { set_pixel(x_centre+x,y_centre+y,color); set_pixel(x_centre-x,y_centre+y,color); set_pixel(x_centre+x,y_centre-y,color); set_pixel(x_centre-x,y_centre-y,color); set_pixel(x_centre+y,y_centre+x,color); set_pixel(x_centre-y,y_centre+x,color); set_pixel(x_centre+y,y_centre-x,color); set_pixel(x_centre-y,y_centre-x,color); if(p<0) p+=4*x+6; 278 else { p+=4*(x-y)+10; y ; } x++; } if (x==y) { set_pixel(x_centre+x,y_centre+y,color); set_pixel(x_centre-x,y_centre+y,color); set_pixel(x_centre+x,y_centre-y,color); set_pixel(x_centre-x,y_centre-y,color); set_pixel(x_centre+y,y_centre+x,color); set_pixel(x_centre-y,y_centre+x,color); set_pixel(x_centre+y,y_centre-x,color); set_pixel(x_centre-y,y_centre-x,color); } } /* Routine to set a pixel on the VGA screen to any of the standard colors.*/ void set_pixel(int x,int y, int color) { union REGS reg; reg.h.ah=0x0c; reg.h.al=color; reg.h.bh=0; reg.x.cx=x; reg.x.dx=y: int86(0x10,&reg,&reg); } /* Routine to turn on cursor mouse on the VGA screen. */ void mouse_cursor_on(void) { union REGS reg; reg.x.ax=0x01; int86(0x33,&reg,&reg); 279 } /* Routine to turn off cursor mouse on the VGA screen.*/ void mouse_cursor_off(void) { union REGS reg; reg.x.ax=0x02; int86(0x33,&reg,&reg); } /* Routine to read mouse row and column location. It also provides mouse button status.*/ void read_mouse( int *row, int *col, int *button ) { union REGS reg: reg.x.ax=0x03; int86(0x33,&reg,&reg); *button=reg.x.bx; *col=reg.x.cx; *row=reg.x.dx; } /* Routine to set vertical range for mouse. */ void mouse_vrange(int min, int max) { union REGS reg; reg.x.ax=0x08; reg.x.cx=min; reg.x.dx=max; int86(0x33,&reg,&reg); } /* Routine to set horizontal range for mouse. */ void mouse_hrange(int min, int max) 280 { union REGS reg; reg.x.ax=0x07; reg.x.cx=min; reg.x.dx=max; int86(0x33,&reg,&reg); } /* Routine to move mouse cursor to a specified location. */ void set_mouse(int row, int col) { union REGS reg; reg.x.ax=0x04; reg.x.cx=col; reg.x.dx=row; int86(0x33,&reg,&reg); } /* Routine to draw the chromaticity diagram on the VGA screen. */ #define xxp(x) (int)((x)*400.0+200.0) #define yyp(y) (int)(400.0-(y)*250.0) float xx[]={ 0.7347, 0.2757, 0.1661 }; float yy[]={ 0.2653, 0.7147, 0.0094 }; struct coord { float xc; float yc; }; struct coord p[7]={ { 0.408, 0.585 }, {0.479, 0.517}, {0.532, 0.465},{ 0.501, 0.160 }, {0.337, 0.086}, 281 {0.208, 0.285}, {0.229, 0.424 }}; struct coord w={0.333, 0.333}; void CIE(void) { float x1,Y1,x2,y2; int i,radius; x1=xxp(xx[0]); y1=yyp(yy[0]); x2=xxp(xx[1]); y2=yyp(yy[1]); draw_line(x1,y1,x2,y2,LIGHTGRAY); x1=x2; y1=y2; x2=xxp(xx[2]); y2=yyp(yy[2]); draw_line(x1,y1,x2,y2,LIGHTGRAY); x1=x2; y1=y2; x2=xxp(xx[0]); y2=yyp(yy[0]); draw_line(x1,y1.x2,y2,LIGHTGRAY); x1=xxp(w.xc); y1=yyp(w.xc); for(i=0;i<7;i++) { x2=xxp(p[i].xc); y2=yyp(p[i].yc); draw_line(x1,y1,x2,y2,LIGHTGRAY); } radius=(int)((xxp(((float)(w.xc)+0.01))-x1)+0.5); draw_circle(x1,y1,radius,LIGHTGRAY); } /* Routine to draw a cross on the VGA screen. */ void draw_cross( float x. float y, int color) { int xx,yy; xx=xxp(x); yy=yyp(y); draw_line(xx-2,yy-2,xx+2,yy+2,color); draw_line(xx-2,yy+2,xx+2,yy-2,color); } 12.5 Dạy nhận biết bằng phương pháp tối thiểu hoá hàm sai lệch tổng Quy tắc delta như chúng ta đã chứng kiến, là sơ đồ lặp hội tụ rất chậm. Sự lựa chọn giá trị của  và  quyết định tốc tốc độ hội tụ. Phép hội tụ này chậm, đòi hỏi . x2=xxp(xx[1]); y2 =yyp(yy[1]); draw_line(x1 ,y1 ,x2 ,y2 ,LIGHTGRAY); x1=x2; y1 =y2 ; x2=xxp(xx[2]); y2 =yyp(yy[2]); draw_line(x1 ,y1 ,x2 ,y2 ,LIGHTGRAY); x1=x2; y1 =y2 ; x2=xxp(xx[0]); y2 =yyp(yy[0]); . 0.160 }, {0 .33 7, 0.086}, 281 {0.208, 0.285}, {0.229, 0.424 }}; struct coord w={0 .33 3, 0 .33 3}; void CIE(void) { float x1 ,Y1 ,x2 ,y2 ; int i,radius; x1=xxp(xx[0]); y1 =yyp(yy[0]); x2=xxp(xx[1]);. set_pixel(x ,y1 ,color); x++; } return; } else if(dx==0) { if (y1 > ;y2 ) { y_ end =y1 ; y= y2; } else y_ end =y2 ; y= y1; } while (y& lt; =y_ end) { set_pixel(x1 ,y, color); y+ +;

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

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

Tài liệu liên quan