IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 30, 2004, 11:01:09 AM (22 years ago)
Author:
desonia
Message:

changes associated with adding psKernelAlloc tests.

File:
1 edited

Legend:

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

    r1863 r1936  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    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 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1515#include "psImageConvolve.h"
    1616#include "psImageFFT.h"
     17#include "psImageExtraction.h"
    1718#include "psMatrixVectorArithmetic.h"
    1819#include "psMemory.h"
     
    2122
    2223#include "psImageErrors.h"
     24
     25#define FOURIER_PADDING 32 /* padding amount in every side of the image for fourier convolution */
    2326
    2427static void freeKernel(psKernel* ptr);
     
    3235    // following is explicitly spelled out in the SDRS as a requirement
    3336    if (yMin > yMax) {
     37        psLogMsg(__func__, PS_LOG_WARN,
     38                 "Specified yMin, %d, was greater than yMax, %d.  Values swapped.",
     39                 yMin, yMax);
     40
    3441        int temp = yMin;
    3542        yMin = yMax;
    3643        yMax = temp;
    37 
    38         psLogMsg(__func__, PS_LOG_WARN,
    39                  "Found yMin > yMax (%d > %d).  Values swapped.",
    40                  yMin, yMax);
    4144    }
    4245
    4346    // following is explicitly spelled out in the SDRS as a requirement
    4447    if (xMin > xMax) {
     48        psLogMsg(__func__, PS_LOG_WARN,
     49                 "Specified xMin, %d, was greater than xMax, %d.  Values swapped.",
     50                 xMin, xMax);
     51
    4552        int temp = xMin;
    4653        xMin = xMax;
    4754        xMax = temp;
    48 
    49         psLogMsg(__func__, PS_LOG_WARN,
    50                  "Found xMin > xMax (%d > %d).  Values swapped.",
    51                  xMin, xMax);
    5255    }
    5356
     
    295298    } else {
    296299        // 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.
    297304        int kRows = kernel->image->numRows;
    298305        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;
    304308        if (x0 < 0 || y0 < 0) {
    305309            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageConvolve",
     
    312316        }
    313317
    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
    317344        for (int row=0;row<kRows;row++) {
    318345            psKernelType* padRow = paddedKernel->data.PS_TYPE_KERNEL_DATA[row+y0];
     
    332359        }
    333360
    334 
    335         psImage* inFourier = psImageFFT(NULL, in, PS_FFT_FORWARD);
     361        psImage* inFourier = psImageFFT(NULL, paddedImage, PS_FFT_FORWARD);
    336362        if (inFourier == NULL) {
    337363            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageConvolve",
     
    343369
    344370        // 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);
    346372        psBinaryOp(outFourier,inFourier,"*",kernelFourier);
    347373
     
    355381        }
    356382
    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.
    361392        psFree(kernelFourier);
    362393        psFree(inFourier);
     394        psFree(paddedImage);
    363395        psFree(paddedKernel);
    364396
Note: See TracChangeset for help on using the changeset viewer.