Changeset 1983 for trunk/psLib/src/image/psImageConvolve.c
- Timestamp:
- Oct 6, 2004, 11:31:30 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImageConvolve.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImageConvolve.c
r1940 r1983 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $8 * @date $Date: 2004-10-0 1 20:58:32$7 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2004-10-06 21:31:30 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 20 20 #include "psLogMsg.h" 21 21 #include "psError.h" 22 #include "psImageIO.h" 22 23 23 24 #include "psImageErrors.h" … … 315 316 int kRows = kernel->image->numRows; 316 317 int kCols = kernel->image->numCols; 317 int x0 = (paddedCols - kCols) / 2; 318 int y0 = (paddedRows - kRows) / 2; 319 if (x0 < 0 || y0 < 0) { 318 if (kRows >= numRows || kCols >= numCols) { 320 319 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageConvolve", 321 320 PS_ERR_BAD_PARAMETER_SIZE, true, 322 321 PS_ERRORTEXT_psImageConvolve_KERNEL_TOO_LARGE, 323 k ernel->image->numCols,kernel->image->numRows,322 kCols,kRows, 324 323 numCols, numRows); 325 324 psFree(out); … … 350 349 } 351 350 351 psImageWriteSection(paddedImage,0,0,0,NULL,0,"paddedImage.fits"); 352 352 353 // pad the kernel to the same size of paddedImage 353 354 psImage* paddedKernel = psImageAlloc(paddedCols,paddedRows,PS_TYPE_KERNEL); 354 355 memset(paddedKernel->data.U8[0],0,sizeof(psKernelType)*numCols*numRows); // zero-out image 355 for (int row=0;row<kRows;row++) { 356 psKernelType* padRow = paddedKernel->data.PS_TYPE_KERNEL_DATA[row+y0]; 357 psKernelType* kernelRow = kernel->image->data.PS_TYPE_KERNEL_DATA[row]; 358 for (int col=0;col<kCols;col++) { 359 padRow[col+x0] = kernelRow[col]; 356 int yMax = kernel->yMax; 357 int xMax = kernel->xMax; 358 for (int row = kernel->yMin; row <= yMax;row++) { 359 int padRow = row; 360 if (padRow < 0) { 361 padRow += paddedRows; 360 362 } 361 } 363 psKernelType* padData = paddedKernel->data.PS_TYPE_KERNEL_DATA[padRow]; 364 psKernelType* kernelRow = kernel->kernel[row]; 365 for (int col = kernel->xMin; col <= xMax; col++) { 366 if (col < 0) { 367 padData[col+paddedCols] = kernelRow[col]; 368 } else { 369 padData[col] = kernelRow[col]; 370 } 371 } 372 } 373 374 psImageWriteSection(paddedKernel,0,0,0,NULL,0,"paddedKernel.fits"); 362 375 363 376 psImage* kernelFourier = psImageFFT(NULL, paddedKernel, PS_FFT_FORWARD); … … 380 393 381 394 // convolution in fourier domain is just a pixel-wise multiplication 382 ps Image* outFourier = psImageAlloc(paddedCols,paddedRows,inFourier->type.type);383 psBinaryOp(outFourier,inFourier,"*",kernelFourier); 384 385 psImage* complexOut = psImageFFT(NULL, outFourier,PS_FFT_REVERSE);395 psBinaryOp(inFourier,inFourier,"*",kernelFourier); 396 397 psImage* complexOut = psImageFFT(NULL, inFourier, 398 PS_FFT_REVERSE); 386 399 if (complexOut == NULL) { 387 400 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageConvolve", … … 392 405 } 393 406 407 { 408 psImage* tmp = psImageReal(NULL,complexOut); 409 psImageWriteSection(tmp,0,0,0,NULL,0,"complexOut.fits"); 410 psFree(tmp); 411 } 412 394 413 // subset out the padded area now. 395 414 psImage* complexOutSansPad = psImageSubset(complexOut, … … 397 416 FOURIER_PADDING+numCols,FOURIER_PADDING+numRows); 398 417 399 // since our image was real, the result is to be real as well 400 out = psImageReal(out,complexOutSansPad); 418 out = psImageRecycle(out,numCols,numRows,PS_TYPE_F32); 419 float factor = 1.0f/numCols/numRows; 420 for (int row = 0; row < numRows; row++) { 421 psF32* outRow = out->data.F32[row]; 422 psC32* resultRow = complexOutSansPad->data.C32[row]; 423 for (int col = 0; col < numCols; col++) { 424 outRow[col] = crealf(resultRow[col])*factor; 425 } 426 } 401 427 402 428 psFree(complexOut); // frees complexOutSansPad, as it is a child.
Note:
See TracChangeset
for help on using the changeset viewer.
