int main(int argc, const char *argv[]) { const int nx = 32, ny = 32, nz = 32, dim = nx*ny*nz; const int dims[3] = {nx, ny, nz}; const float mmppixr[] = { 2, 2, 2 }, centerr[] = { 0, 0, 0}; const float blur_radius = 4.0; int iz, iy, ix, i; float *image, *mask, *roi; pf_log_all(1); image = calloc(dim, sizeof(float)); roi = calloc(dim, sizeof(float)); mask = malloc(dim * sizeof(float)); if (!image || !mask || !roi) { fprintf(stderr, "allocation failed"); exit(1); } /* start with a trivial mask and a gaussian image*/ float min = INT_MAX, max = INT_MIN; for (i = iz = 0; iz < nz; iz++) { for (iy = 0; iy < ny; iy++) { for (ix = 0; ix < nx; ix++, i++) { mask[i] = 1.0; image[i] = gauss3d(ix-(nx/2),iy-(ny/2),iz-(ny/2),nx/4); if (image[i] > max) { max = image[i]; } if (image[i] < min) { min = image[i]; } } } } fprintf(stdout, "image value range: [%g, %g]\n", min, max); display(image, dims, 17, max); sphereblur(image, dims, mmppixr, blur_radius); display(image, dims, 17, max); find_peaks(image, dims, mmppixr, centerr, 0, 0, 0, 0, 1, roi, 4, 0, 8, mask, 0, 0); puts("slice at peak:\n"); display(roi, dims, 17, max); puts("2 slices away from peak:\n"); display(roi, dims, 15, max); puts("4 slices away from peak:\n"); display(roi, dims, 13, max); }
RSFMat *calrsfmat(IMAGE_4dfp *image, ROIList *rois, float fhalf) { RSFMat *rsfmat = NULL; IMAGE_4dfp *tmp_img=NULL; int val, nx, ny, nz, i, j, nv; float cmppix[3], *fptr, l; IFH tmp_ifh; clock_t start, end; rsfmat = (RSFMat *) malloc((size_t)sizeof(RSFMat)); if (!rsfmat) errm("calrsfmat"); rsfmat->n = rois->NumberOfRegions; rsfmat->mat = matrix(1,rsfmat->n,1,rsfmat->n); nx = image->ifh.matrix_size[0]; ny = image->ifh.matrix_size[1]; nz = image->ifh.matrix_size[2]; cmppix[0]=image->ifh.scaling_factor[0]/10.; cmppix[1]=image->ifh.scaling_factor[1]/10.; cmppix[2]=image->ifh.scaling_factor[2]/10.; /* Converting roi values to consecutive numbers*/ start = clock(); nv = image->ifh.matrix_size[0]*image->ifh.matrix_size[1]*image->ifh.matrix_size[2]*image->ifh.matrix_size[3]; for (j=0; j<rois->NumberOfRegions; j++) { val = rois->List[j].MaskVal; fptr = image->image; for (i=0; i<nv; i++) { if (fabs(*fptr-(float)val)<1e-4) { *fptr=(float)j; } fptr++; } } fptr=image->image; l=(float)(rois->NumberOfRegions-.5); for (i=0; i<nv; i++) { if (*fptr>l) *fptr=0; fptr++; } end = clock(); printf("CPU TIME USED for roi preprocessing is %f\n",((double) (end - start)) / CLOCKS_PER_SEC); /* Calculate RSF Matrix */ for (i=1;i<=rsfmat->n;i++) { printf("%s\n", rois->List[i-1].Name); tmp_img=extract_roi_4dfp(image, i-1, tmp_img); start = clock(); gauss3d(tmp_img->image, &nx, &ny, &nz, cmppix, &fhalf); end = clock(); printf("CPU TIME USED for gauss3d is %f\n",((double) (end - start)) / CLOCKS_PER_SEC); start = clock(); getroismean_4dfp(tmp_img, image, rsfmat->n, rsfmat->mat[i]); /*for (j=1; j<=rsfmat->n; j++) { printf("%e\n",rsfmat->mat[i][j]); }*/ end = clock(); printf("CPU TIME USED for getroimeans is %f\n",((double) (end - start)) / CLOCKS_PER_SEC); } /* for (i=1;i<=rsfmat->n;i++) { printf("%s\n", rois->List[i-1].Name); val = rois->List[i-1].MaskVal; tmp_img=extract_roi_4dfp(image, val, tmp_img); start = clock(); gauss3d(tmp_img->image, &nx, &ny, &nz, cmppix, &fhalf); end = clock(); printf("CPU TIME USED for gauss3d is %f\n",((double) (end - start)) / CLOCKS_PER_SEC); start = clock(); for (j=1; j<=rsfmat->n; j++) { rsfmat->mat[i][j]=getroimean_4dfp(tmp_img, image, rois->List[j-1].MaskVal); printf("%e\n",rsfmat->mat[i][j]); } end = clock(); printf("CPU TIME USED for getroimean is %f\n",((double) (end - start)) / CLOCKS_PER_SEC); } */ return rsfmat; }