IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 6, 2004, 11:31:30 AM (22 years ago)
Author:
desonia
Message:

work on FFT and convolution. Fourier-domain convolution is still
broken.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/image/psImageConvolve.c

    r1940 r1983  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2004-10-01 20:58:32 $
     7 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2004-10-06 21:31:30 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2020#include "psLogMsg.h"
    2121#include "psError.h"
     22#include "psImageIO.h"
    2223
    2324#include "psImageErrors.h"
     
    315316        int kRows = kernel->image->numRows;
    316317        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) {
    320319            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageConvolve",
    321320                       PS_ERR_BAD_PARAMETER_SIZE, true,
    322321                       PS_ERRORTEXT_psImageConvolve_KERNEL_TOO_LARGE,
    323                        kernel->image->numCols,kernel->image->numRows,
     322                       kCols,kRows,
    324323                       numCols, numRows);
    325324            psFree(out);
     
    350349        }
    351350
     351        psImageWriteSection(paddedImage,0,0,0,NULL,0,"paddedImage.fits");
     352
    352353        // pad the kernel to the same size of paddedImage
    353354        psImage* paddedKernel = psImageAlloc(paddedCols,paddedRows,PS_TYPE_KERNEL);
    354355        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;
    360362            }
    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");
    362375
    363376        psImage* kernelFourier = psImageFFT(NULL, paddedKernel, PS_FFT_FORWARD);
     
    380393
    381394        // convolution in fourier domain is just a pixel-wise multiplication
    382         psImage* 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);
    386399        if (complexOut == NULL) {
    387400            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageConvolve",
     
    392405        }
    393406
     407        {
     408            psImage* tmp = psImageReal(NULL,complexOut);
     409            psImageWriteSection(tmp,0,0,0,NULL,0,"complexOut.fits");
     410            psFree(tmp);
     411        }
     412
    394413        // subset out the padded area now.
    395414        psImage* complexOutSansPad = psImageSubset(complexOut,
     
    397416                                     FOURIER_PADDING+numCols,FOURIER_PADDING+numRows);
    398417
    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        }
    401427
    402428        psFree(complexOut); // frees complexOutSansPad, as it is a child.
Note: See TracChangeset for help on using the changeset viewer.