Giáo trình xử lý ảnh y tế Tập 1b P6 - Pdf 17

{
if(zn2>max) max=zn2;
if(zn2<min) min=zn2;
}
fprintf(fptr_tmp,"%f ",zn2);
/* The buffer is implicit in this
last statement.*/
}

/* shift rows of w */
temp=*w;
for(j=0; j<N2; j++)
*(w+j)=*(w+j+1);
*(w+N2)=temp;
}

fclose(fptr); /* close input image file */
gotoxy(70,25);
textattr(WHITE+(BLACK<<4));
cputs(" ");
gotoxy(1,10);
printf("Filtering is now completed.");
printf("\nMax. and min. values in filtered image
=>%f,%f",max, min);
printf("\n Next, bias will be adjusted and the final
");
printf("\n filtered image will be saved in a file.");
rewind(fptr_tmp);
again:
gotoxy(1,15);
printf( " ");

scanf("%s",file_name);
ind=access(file_name,0);
}
}
fptr1=fopen(file_name, "wb");
gotoxy(70,25);
textattr(WHITE+(GREEN<<4)+BLINK);
cputs("WAIT");
for(n1=0; n1<image_length; n1++)
{
gotoxy(1,17);
printf("scaling line %-4d.",n1);
for(n2=0; n2<image_width; n2++)
{
fscanf(fptr_tmp,"%f", &zn2);
/*scaling output image between 0 and 255. */

zn2= (zn2-min)*(float)255.0/(max-min) +
(float)0.4;
putc((unsigned char)zn2,fptr1);
}
}

fclose(fptr_tmp);
remove("temp_img.dat");
gotoxy(70,25);
textattr(WHITE+(BLACK<<4));
cputs(" ");
fclose(fptr1); /* close output-image file */
gotoxy(1,20);
Hình 3.2 (a) Ảnh IKRAM.IMG gốc.
(b) Ảnh lọc thông cao của IKRAM.IMG.
(c) Ảnh lọc thông thấp của IKRAM.IMG.

Bài tập 3.1
Viết chương trình C để trung bình 2 ảnh. Nếu ảnh thứ hai là kết quả của lọc ảnh
thứ nhất, thì ảnh thứ hai sẽ được dịch dọc và/hoặc ngang so với ảnh thứ nhất.
Chương trình sẽ nhắc nhở người sử dụng nhập lượng dịch chuyển. Hình 3.3 Ảnh gốc đã thêm ảnh lọc thông cao.

Chương trình 3.2 "FIRSYM.C". Lọc ảnh dùng bộ lọc tuần hoàn đối xứng.

/*Program 3.2 “FIRSYM.C”. Filltering of digital images
using circular symmetricals.*/

/*This Program is for filtering images using the
algorithm described in the text. The filter type
is FIR. Circular symmetry is assumed.
The FIR filter coefficients can be obtained using the
Simpson's double integration program described in
Chapter II. */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <alloc.h>

while(fscanf(fptr,"%f ", &tmp)!=EOF) nsq++;
rewind(fptr);

NT=sqrt(nsq);
printf("Order of filter %d x %d",NT,NT);
N=(NT-1)>>1;
N2=N<<1 ;

/* Allocating memory for filter coefficients h[i][j] */
h=(float **)malloc(NT*sizeof(float *));
for(i=0;i<NT;i++)
*(h+i)=(float *)calloc(NT,sizeof(float));
printf("\n FILTER COEFFICIENTS.\n");
for(i=0;i<NT;i++)
{
for(j=0;j<NT;j++)
{
fscanf(fptr,"%f ", &h[i][j]);
printf("%f ", *((*(h+i))+j));
}
printf("\n");
}
fclose(fptr);

printf
("\.n Press any key to continue. Screen w ill be
cleared.");
getch();
clrscr();
printf


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status