Changeset 1936 for trunk/psLib/src/image/psImageConvolve.c
- Timestamp:
- Sep 30, 2004, 11:01:09 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImageConvolve.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImageConvolve.c
r1863 r1936 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $8 * @date $Date: 2004-09- 23 18:30:57$7 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2004-09-30 21:01:09 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 15 #include "psImageConvolve.h" 16 16 #include "psImageFFT.h" 17 #include "psImageExtraction.h" 17 18 #include "psMatrixVectorArithmetic.h" 18 19 #include "psMemory.h" … … 21 22 22 23 #include "psImageErrors.h" 24 25 #define FOURIER_PADDING 32 /* padding amount in every side of the image for fourier convolution */ 23 26 24 27 static void freeKernel(psKernel* ptr); … … 32 35 // following is explicitly spelled out in the SDRS as a requirement 33 36 if (yMin > yMax) { 37 psLogMsg(__func__, PS_LOG_WARN, 38 "Specified yMin, %d, was greater than yMax, %d. Values swapped.", 39 yMin, yMax); 40 34 41 int temp = yMin; 35 42 yMin = yMax; 36 43 yMax = temp; 37 38 psLogMsg(__func__, PS_LOG_WARN,39 "Found yMin > yMax (%d > %d). Values swapped.",40 yMin, yMax);41 44 } 42 45 43 46 // following is explicitly spelled out in the SDRS as a requirement 44 47 if (xMin > xMax) { 48 psLogMsg(__func__, PS_LOG_WARN, 49 "Specified xMin, %d, was greater than xMax, %d. Values swapped.", 50 xMin, xMax); 51 45 52 int temp = xMin; 46 53 xMin = xMax; 47 54 xMax = temp; 48 49 psLogMsg(__func__, PS_LOG_WARN,50 "Found xMin > xMax (%d > %d). Values swapped.",51 xMin, xMax);52 55 } 53 56 … … 295 298 } else { 296 299 // fourier convolution 300 int paddedCols = numCols+2*FOURIER_PADDING; 301 int paddedRows = numRows+2*FOURIER_PADDING; 302 303 // check to see if kernel is smaller, otherwise padding it up will fail. 297 304 int kRows = kernel->image->numRows; 298 305 int kCols = kernel->image->numCols; 299 int x0 = (numCols - kCols) / 2; 300 int y0 = (numRows - kRows) / 2; 301 psImage* paddedKernel; 302 303 // check to see if kernel is smaller, otherwise padding it up will fail. 306 int x0 = (paddedCols - kCols) / 2; 307 int y0 = (paddedRows - kRows) / 2; 304 308 if (x0 < 0 || y0 < 0) { 305 309 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageConvolve", … … 312 316 } 313 317 314 // pad the kernel to the same size of image 315 paddedKernel = psImageAlloc(numCols,numRows,PS_TYPE_KERNEL); 316 memset(paddedKernel->data.V,0,sizeof(psKernelType)*numCols*numRows); // zeroize image 318 // pad the image 319 psImage* paddedImage = psImageAlloc(paddedCols,paddedRows,in->type.type); 320 int elementSize = PSELEMTYPE_SIZEOF(in->type.type); 321 322 // zero out padded area on top and bottom 323 memset(paddedImage->data.U8[0],0,FOURIER_PADDING*paddedCols*elementSize); 324 memset(paddedImage->data.U8[FOURIER_PADDING+numRows-1],0,FOURIER_PADDING*paddedCols*elementSize); 325 326 // fill in the image-containing rows. 327 int sidePaddingSize = FOURIER_PADDING*elementSize; 328 int imageRowSize = numCols*elementSize; 329 psU8* paddedData = paddedImage->data.U8[FOURIER_PADDING]; 330 for (int row=0;row<numRows;row++) { 331 // zero out padded area on left edge. 332 memset(paddedData,0,sidePaddingSize); 333 paddedData += sidePaddingSize; 334 memcpy(paddedData,in->data.U8[row],imageRowSize); 335 paddedData += imageRowSize; 336 // zero out padded area on right edge. 337 memset(paddedData,0,sidePaddingSize); 338 paddedData += sidePaddingSize; 339 } 340 341 // pad the kernel to the same size of paddedImage 342 psImage* paddedKernel = psImageAlloc(paddedCols,paddedRows,PS_TYPE_KERNEL); 343 memset(paddedKernel->data.U8[0],0,sizeof(psKernelType)*numCols*numRows); // zero-out image 317 344 for (int row=0;row<kRows;row++) { 318 345 psKernelType* padRow = paddedKernel->data.PS_TYPE_KERNEL_DATA[row+y0]; … … 332 359 } 333 360 334 335 psImage* inFourier = psImageFFT(NULL, in, PS_FFT_FORWARD); 361 psImage* inFourier = psImageFFT(NULL, paddedImage, PS_FFT_FORWARD); 336 362 if (inFourier == NULL) { 337 363 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageConvolve", … … 343 369 344 370 // convolution in fourier domain is just a pixel-wise multiplication 345 psImage* outFourier = psImageAlloc( numCols,numRows,inFourier->type.type);371 psImage* outFourier = psImageAlloc(paddedCols,paddedRows,inFourier->type.type); 346 372 psBinaryOp(outFourier,inFourier,"*",kernelFourier); 347 373 … … 355 381 } 356 382 357 // since our image was real to start, the result is real 358 out = psImageReal(out,complexOut); 359 360 psFree(complexOut); 383 // subset out the padded area now. 384 psImage* complexOutSansPad = psImageSubset(complexOut, 385 FOURIER_PADDING,FOURIER_PADDING, 386 FOURIER_PADDING+numCols,FOURIER_PADDING+numRows); 387 388 // since our image was real, the result is to be real as well 389 out = psImageReal(out,complexOutSansPad); 390 391 psFree(complexOut); // frees complexOutSansPad, as it is a child. 361 392 psFree(kernelFourier); 362 393 psFree(inFourier); 394 psFree(paddedImage); 363 395 psFree(paddedKernel); 364 396
Note:
See TracChangeset
for help on using the changeset viewer.
