Changeset 32725
- Timestamp:
- Nov 20, 2011, 3:55:38 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
-
psLib/src/imageops/psImageConvolve.c (modified) (10 diffs)
-
psLib/src/imageops/psImageConvolve.h (modified) (2 diffs)
-
psLib/test/imageops/Makefile.am (modified) (1 diff)
-
psLib/test/imageops/tap_psImageSmooth.c (modified) (5 diffs)
-
psModules/src/objects/pmPCM_MinimizeChisq.c (modified) (3 diffs)
-
psModules/src/objects/pmPCMdata.c (modified) (3 diffs)
-
psModules/src/objects/pmPCMdata.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageConvolve.c
r32724 r32725 569 569 // Generate normalised Gaussian vector 570 570 #define IMAGE_SMOOTH_GAUSS(TARGET, SIZE, SIGMA, TYPE) \ 571 psVector *TARGET = psVectorAlloc(2 * SIZE + 1, PS_TYPE_##TYPE); /* Gaussian */ \571 TARGET = psVectorAlloc(2 * SIZE + 1, PS_TYPE_##TYPE); /* Gaussian */ \ 572 572 double sum = 0.0; /* Sum of Gaussian, for normalisation */ \ 573 573 double factor = -0.5/PS_SQR(SIGMA); /* Multiplier for exponential */ \ … … 587 587 psKernel *kernel = psKernelAlloc(-size, size, -size, size); // Kernel to return 588 588 589 psVector *gaussNorm = NULL; 589 590 IMAGE_SMOOTH_GAUSS(gaussNorm, size, sigma, F32); 590 591 psF32 *gauss = &gaussNorm->data.F32[size]; // Convenient kernel-like indexing for Gaussian … … 602 603 bool psImageSmooth(psImage *image, double sigma, double Nsigma) 603 604 { 604 PS_ASSERT_IMAGE_NON_NULL(image, NULL);605 PS_ASSERT_IMAGE_NON_NULL(image, false); 605 606 606 607 // relevant terms … … 612 613 case PS_TYPE_##TYPE: { \ 613 614 /* generate normalized gaussian */ \ 615 psVector *gaussnorm = NULL; \ 614 616 IMAGE_SMOOTH_GAUSS(gaussnorm, Nrange, sigma, TYPE) \ 615 617 ps##TYPE *gauss = &gaussnorm->data.TYPE[Nrange]; \ … … 765 767 } 766 768 767 // XXX NOTE : work to do : figure out the actual containers needed in there, pre-allocate them 768 bool psImageSmooth_PreAlloc_F32(psImage *image, double sigma, double Nsigma) 769 { 770 PS_ASSERT_IMAGE_NON_NULL(image, NULL); 771 // assert on data type 769 void psImageSmooth_PreAlloc_DataFree (psImageSmooth_PreAlloc_Data *smdata) { 770 psFree (smdata->resultX); 771 psFree (smdata->resultY); 772 psFree (smdata->kernel); 773 } 774 775 psImageSmooth_PreAlloc_Data *psImageSmooth_PreAlloc_DataAlloc (psImage *image, double sigma, double Nsigma) { 776 777 psImageSmooth_PreAlloc_Data *smdata = psAlloc(sizeof(psImageSmooth_PreAlloc_Data)); 778 psMemSetDeallocator(smdata, (psFreeFunc) psImageSmooth_PreAlloc_DataFree); 779 780 if (!image) { 781 // relevant terms 782 smdata->Nrange = sigma*Nsigma + 0.5; // Number of pixels either side for convolution kernel 783 smdata->Nx = 0; 784 smdata->Ny = 0; 785 smdata->kernel = NULL; 786 smdata->resultX = NULL; 787 smdata->resultY = NULL; 788 return smdata; 789 } 772 790 773 791 // relevant terms 774 int Nrange = sigma*Nsigma + 0.5; // Number of pixels either side for convolution kernel 775 int Nx = image->numCols; // Number of columns 776 int Ny = image->numRows; // Number of rows 777 778 IMAGE_SMOOTH_GAUSS(gaussnorm, Nrange, sigma, F32); 779 psF32 *gauss = &gaussnorm->data.F32[Nrange]; 792 smdata->Nrange = sigma*Nsigma + 0.5; // Number of pixels either side for convolution kernel 793 smdata->Nx = image->numCols; // Number of columns 794 smdata->Ny = image->numRows; // Number of rows 795 796 IMAGE_SMOOTH_GAUSS(smdata->kernel, smdata->Nrange, sigma, F32); 780 797 781 798 // use a temp running buffer for X and Y directions. 782 psF32 *resultX = (psF32 *) psAlloc(Nx * sizeof(psF32)); 783 memset (resultX, 0, Nx*sizeof(psF32)); 784 psF32 *resultY = (psF32 *) psAlloc(Ny * sizeof(psF32)); 785 memset (resultY, 0, Ny*sizeof(psF32)); 786 799 smdata->resultX = psAlloc(smdata->Nx * sizeof(psF32)); 800 memset (smdata->resultX, 0, smdata->Nx*sizeof(psF32)); 801 802 smdata->resultY = psAlloc(smdata->Ny * sizeof(psF32)); 803 memset (smdata->resultY, 0, smdata->Ny*sizeof(psF32)); 804 805 return smdata; 806 } 807 808 // we can use the same DATA structure on multiple images of the same size 809 bool psImageSmooth_PreAlloc_F32(psImage *image, psImageSmooth_PreAlloc_Data *smdata) 810 { 811 PS_ASSERT_IMAGE_NON_NULL(image, false); 812 // assert on data type 813 814 // relevant terms 815 int Nrange = smdata->Nrange; // Number of pixels either side for convolution kernel 816 int Nx = smdata->Nx; // Number of columns 817 int Ny = smdata->Ny; // Number of rows 818 819 psF32 *gauss = &smdata->kernel->data.F32[Nrange]; 820 psF32 *resultX = smdata->resultX; 821 psF32 *resultY = smdata->resultY; 822 787 823 /* Smooth in X direction */ 788 824 { … … 881 917 } 882 918 } 883 884 psFree(resultX);885 psFree(resultY);886 psFree(gaussnorm);887 888 919 return true; 889 920 } … … 973 1004 974 1005 // Generate normalized gaussian 1006 psVector *gaussNorm = NULL; 975 1007 IMAGE_SMOOTH_GAUSS(gaussNorm, size, sigma, F32); 976 1008 … … 1098 1130 1099 1131 // Generate normalized gaussian 1132 psVector *gaussNorm = NULL; 1100 1133 IMAGE_SMOOTH_GAUSS(gaussNorm, size, sigma, F32); 1101 1134 const psF32 *gauss = &gaussNorm->data.F32[size]; // Gaussian convolution kernel … … 1309 1342 1310 1343 // Generate normalized gaussian 1344 psVector *gaussNorm = NULL; 1311 1345 IMAGE_SMOOTH_GAUSS(gaussNorm, size, sigma, F32); 1312 1346 … … 1445 1479 1446 1480 /* generate normalized gaussian */ 1481 psVector *gaussnorm = NULL; 1447 1482 IMAGE_SMOOTH_GAUSS(gaussnorm, Nrange, sigma, F32); 1448 1483 psF32 *gauss = &gaussnorm->data.F32[Nrange]; -
trunk/psLib/src/imageops/psImageConvolve.h
r30595 r32725 25 25 #define PS_TYPE_KERNEL_DATA F32 ///< the data member to use for kernel image */ 26 26 #define PS_TYPE_KERNEL_NAME "psF32" ///< the data type for kernel as a string */ 27 28 /// a structure to contain data related to image smoothing with a 1D gauss kernel 29 typedef struct { 30 int Nx; 31 int Ny; 32 int Nrange; 33 psF32 *resultX; 34 psF32 *resultY; 35 psVector *kernel; 36 } psImageSmooth_PreAlloc_Data; 27 37 28 38 /// A convolution kernel … … 277 287 ); 278 288 289 psImageSmooth_PreAlloc_Data *psImageSmooth_PreAlloc_DataAlloc (psImage *image, double sigma, double Nsigma); 290 bool psImageSmooth_PreAlloc_F32(psImage *image, psImageSmooth_PreAlloc_Data *smdata); 291 279 292 /// Control threading for image convolution functions 280 293 /// -
trunk/psLib/test/imageops/Makefile.am
r30595 r32725 17 17 tap_psImagePixelManip \ 18 18 tap_psImageSmooth \ 19 tap_psImageSmooth_PreAlloc \ 19 20 tap_psImageStructManip \ 20 21 tap_psImageConvolve \ -
trunk/psLib/test/imageops/tap_psImageSmooth.c
r12094 r32725 24 24 #define TS00_IM_F64 0x00000004 25 25 #define TS00_IM_S32 0x00000008 26 #define VERBOSE 026 #define VERBOSE 1 27 27 28 28 static psBool testImageSmoothGeneric( … … 64 64 } 65 65 } 66 if (VERBOSE) {67 p_psImagePrint(1, img, "The Smoothed Image");68 }69 70 66 if (flags & TS00_IM_F64) { 71 67 if (VERBOSE) … … 83 79 } 84 80 } 85 86 81 if (flags & TS00_IM_S32) { 87 82 if (VERBOSE) … … 100 95 } 101 96 if (VERBOSE) { 97 if (img) p_psImagePrint(1, img, "The Raw Image"); 102 98 printf(" %d columns\n", numCols); 103 99 printf(" %d rows\n", numRows); … … 160 156 ok(testImageSmoothGeneric(TS00_IM_F32, NUM_COLS, 1, SIGMA, NSIGMA, true), "testImageSmoothGeneric() successful"); 161 157 ok(testImageSmoothGeneric(TS00_IM_F32, 1, 1, SIGMA, NSIGMA, true), "testImageSmoothGeneric() successful"); 162 ok(testImageSmoothGeneric(TS00_IM_F64, NUM_COLS, NUM_ROWS, SIGMA, NSIGMA, true), "testImageSmoothGeneric() successful");163 ok(testImageSmoothGeneric(TS00_IM_S32, NUM_COLS, NUM_ROWS, SIGMA, NSIGMA, false), "testImageSmoothGeneric() successful");158 // ok(testImageSmoothGeneric(TS00_IM_F64, NUM_COLS, NUM_ROWS, SIGMA, NSIGMA, true), "testImageSmoothGeneric() successful"); 159 // ok(testImageSmoothGeneric(TS00_IM_S32, NUM_COLS, NUM_ROWS, SIGMA, NSIGMA, false), "testImageSmoothGeneric() successful"); 164 160 ok(testImageSmoothGeneric(TS00_IM_NULL, NUM_COLS, NUM_ROWS, SIGMA, NSIGMA, false), "testImageSmoothGeneric() successful"); 165 161 } -
trunk/psModules/src/objects/pmPCM_MinimizeChisq.c
r32347 r32725 324 324 // * threading takes place above this level 325 325 pcm->modelConvFlux = psImageCopy (pcm->modelConvFlux, pcm->modelFlux, pcm->modelFlux->type.type); 326 psImageSmooth (pcm->modelConvFlux, pcm->sigma, pcm->nsigma); 326 psImageSmooth_PreAlloc_F32 (pcm->modelConvFlux, pcm->smdata); 327 // psImageSmooth (pcm->modelConvFlux, pcm->sigma, pcm->nsigma); 327 328 } else { 328 329 psImageConvolveKernel (pcm->modelConvFlux, pcm->modelFlux, NULL, 0, pcm->psfFFT); … … 343 344 // * threading takes place above this level 344 345 dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type); 345 psImageSmooth (dmodelConv, pcm->sigma, pcm->nsigma); 346 psImageSmooth_PreAlloc_F32 (dmodelConv, pcm->smdata); 347 // psImageSmooth (dmodelConv, pcm->sigma, pcm->nsigma); 346 348 } else { 347 349 psImageConvolveKernel (dmodelConv, dmodel, NULL, 0, pcm->psfFFT); … … 363 365 // * threading takes place above this level 364 366 dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type); 365 psImageSmooth (dmodelConv, pcm->sigma, pcm->nsigma); 367 psImageSmooth_PreAlloc_F32 (dmodelConv, pcm->smdata); 368 // psImageSmooth (dmodelConv, pcm->sigma, pcm->nsigma); 366 369 } else { 367 370 psImageConvolveFFT (dmodelConv, dmodel, NULL, 0, pcm->psf); -
trunk/psModules/src/objects/pmPCMdata.c
r32347 r32725 57 57 psFree (pcm->psfFFT); 58 58 psFree (pcm->constraint); 59 psFree (pcm->smdata); // pre-allocated data for psImageSmooth_PreAlloc 59 60 return; 60 61 } … … 284 285 pcm->sigma = 0.5 * (FWHM_MAJOR + FWHM_MINOR) / 2.35; 285 286 pcm->nsigma = 2.0; 287 288 pcm->smdata = psImageSmooth_PreAlloc_DataAlloc (source->pixels, pcm->sigma, pcm->nsigma); 289 # else 290 pcm->smdata = NULL; 286 291 # endif 287 292 … … 393 398 pcm->dmodelsConvFlux->data[n] = psImageCopy (pcm->dmodelsConvFlux->data[n], source->pixels, PS_TYPE_F32); 394 399 } 400 psFree(pcm->smdata); 401 pcm->smdata = psImageSmooth_PreAlloc_DataAlloc (source->pixels, pcm->sigma, pcm->nsigma); 395 402 } 396 403 -
trunk/psModules/src/objects/pmPCMdata.h
r32347 r32725 39 39 float sigma; 40 40 float nsigma; 41 42 psImageSmooth_PreAlloc_Data *smdata; 41 43 } pmPCMdata; 42 44
Note:
See TracChangeset
for help on using the changeset viewer.
