Article View: comp.sys.ibm.pc.programmer
Article #263Help needed
From: Fang Zhong
Date: Mon, 09 Apr 1990 08:05
Date: Mon, 09 Apr 1990 08:05
103 lines
2817 bytes
2817 bytes
I am doing some image processing on a IBM PC-AT.
I use subroutines from ImageTool by Werner Frei Associates
to grab images. I want to average several frames on an
image to increase S/N ratio. I wrote a program with MS
QuickC 2.0 (enclosed below). It takes 75 seconds to just
average over two frames. Normally I want to average at
least eight frames. That would take ten minutes during
which my image pattern may have changed.
Can some experts on the net tell me how to improve
the speed of the averaging through better programing?
Thanks in advance.
Fang
-----------------------------------------------------
#include <stdio.h>
#include <malloc.h>
include "imtool.h"
#define row 480
#define col 512
int **imatrix();
void free_imatrix();
int **ival;
void main()
{
long ms, crg;
int mode = 1, num, nframe, i, j, k, pval;
ival = imatrix(1, row, 1, col); /* allocate memory for ival */
for(k = 1; k <= row; k++) { /* initialize ival */
for(j = 1; j <= col; j++) {
ival[k][j] = 0;
}
}
/* initialize imtool routines */
ms = 0xd000;
crg = 0x300;
num = 1;
INITIM(&num,&ms,&crg); /* initialize the Frame Grabber Board */
BRDSEL(&num); /* initialize selected board */
CLKSEL(&num); /* initialize Clock mode to be PLL */
printf("How many frames do you want to average?\n");
scanf("%d", &nframe);
for(i = 0; i < nframe; ++i) {
DIGITZ(&mode);
printf("\aCollecting frame #%d\n", i+1);
for(k = 0; k < row; ++k) {
for(j = 0; j < col; ++j) {
RDPXL(&j, &k, &pval);
ival[k+1][j+1] += pval;
}
}
}
printf("\aDisplay averaged image\n");
for(k = 0; k < row; ++k) {
for(j = 0; j < col; ++j) {
pval = ival[k+1][j+1] / nframe;
WRPXL(&j, &k, &pval);
}
}
free_imatrix(ival, 1, row, 1, col);
}
int **imatrix(nrl,nrh,ncl,nch)
int nrl,nrh,ncl,nch;
{
int i,**m;
m=(int **)malloc((unsigned) (nrh-nrl+1)*sizeof(int*));
m -= nrl;
for(i=nrl;i<=nrh;i++) {
m[i]=(int *)malloc((unsigned) (nch-ncl+1)*sizeof(int));
m[i] -= ncl;
}
return m;
}
void free_imatrix(m,nrl,nrh,ncl,nch)
int **m;
int nrl,nrh,ncl,nch;
{
int i;
for(i=nrh;i>=nrl;i--) free((char*) (m[i]+ncl));
free((char*) (m+nrl));
}
--
Fang Zhong 1-919-684-8247
Duke University Dept. of Physics fang@phy.duke.edu
Durham, N.C. 27706
Technical Details
Message-ID:
<866@dukempd.phy.duke.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!xanth!mcnc!duke!dukempd!fangShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!xanth!mcnc!duke!dukempd!fang From: fang@dukempd.phy.duke.edu (Fang Zhong) Newsgroups: comp.sys.ibm.pc.programmer Subject: Help needed Message-ID: <866@dukempd.phy.duke.edu> Date: 9 Apr 90 08:05:10 GMT Organization: Duke University Physics Dept.; Durham, N.C. Lines: 103