Changeset 9927
- Timestamp:
- Nov 9, 2006, 10:20:27 AM (20 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 3 edited
-
imageops/psImageGeomManip.c (modified) (2 diffs)
-
imageops/psImageGeomManip.h (modified) (3 diffs)
-
mathtypes/psImage.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageGeomManip.c
r9865 r9927 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.3 1$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-11-0 6 02:02:59$12 * @version $Revision: 1.32 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-11-09 20:20:27 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 594 594 } 595 595 596 // XXX this function seems to work (except for edge pixels and masked pixels 597 // but the function below does not define the right 3x3 kernels. look this 598 // up 599 psImage *p_psImageShiftKernel_F32( 600 psImage *out, 601 const psImage *input, 602 const psImage *kernel) 603 { 604 605 PS_ASSERT_IMAGE_NON_NULL(input, NULL); 606 PS_ASSERT_IMAGE_NON_NULL(kernel, NULL); 607 608 if ((kernel->numCols % 2 == 0) || (kernel->numRows % 2 == 0)) { 609 psError(PS_ERR_BAD_PARAMETER_NULL, true, 610 _("kernel must have odd dimensions")); 611 return NULL; 612 } 613 int Xk = (kernel->numCols - 1) / 2; 614 int Yk = (kernel->numRows - 1) / 2; 615 616 int outRows = input->numRows; 617 int outCols = input->numCols; 618 out = psImageRecycle(out, outCols, outRows, input->type.type); 619 psImageInit (out, 0.0); 620 621 // need to handle the edge cases... 622 for (int row = 1; row < outRows-1; row++) { 623 psF32 *outRow = out->data.F32[row]; 624 psF32 **inValue = input->data.F32; 625 for (int col = 1; col < outCols-1; col++) { 626 double value = 0; 627 double norm = 0; 628 psF32 **kernValue = kernel->data.F32; 629 for (int yi = -Yk; yi <= Yk; yi++) { 630 for (int xi = -Xk; xi <= Xk; xi++) { 631 value += inValue[row+yi][col+xi]*kernValue[yi+Yk][xi+Xk]; 632 norm += kernValue[yi+Yk][xi+Xk]; 633 } 634 } 635 // include the mask tests and divide-by-zero test 636 outRow[col] = value / norm; 637 } 638 } 639 640 return (out); 641 } 642 643 // XXX fix the definition of the interpolation kernels and add integer shifts 644 psImage *psImageShiftKernel ( 645 psImage *out, 646 const psImage *input, 647 float dx, float dy, psImageInterpolateMode mode) 648 { 649 650 psImage *kernel = NULL; 651 652 switch (mode) { 653 case PS_INTERPOLATE_BICUBE: 654 kernel = psImageAlloc (3, 3, PS_TYPE_F32); 655 for (int iy = -1; iy <= +1; iy++) { 656 for (int ix = -1; ix <= +1; ix++) { 657 kernel->data.F32[iy+1][ix+1] = 5 - 3*PS_SQR(ix+dx) - 3*PS_SQR(iy+dy); 658 } 659 } 660 out = p_psImageShiftKernel_F32 (out, input, kernel); 661 break; 662 663 case PS_INTERPOLATE_GAUSS: 664 kernel = psImageAlloc (3, 3, PS_TYPE_F32); 665 for (int iy = -1; iy <= +1; iy++) { 666 for (int ix = -1; ix <= +1; ix++) { 667 kernel->data.F32[iy+1][ix+1] = exp(-0.5*PS_SQR(ix+dx) -0.5*PS_SQR(iy+dy)); 668 } 669 } 670 out = p_psImageShiftKernel_F32 (out, input, kernel); 671 break; 672 673 default: 674 psError(PS_ERR_BAD_PARAMETER_NULL, true, 675 _("shift kernel for %d not defined"), mode); 676 return NULL; 677 } 678 psFree (kernel); 679 return (out); 680 } 681 596 682 psImage* psImageShift(psImage* out, 597 683 const psImage* input, -
trunk/psLib/src/imageops/psImageGeomManip.h
r7380 r9927 8 8 * @author Robert DeSonia, MHPCC 9 9 * 10 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $11 * @date $Date: 2006- 06-07 03:22:06$10 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2006-11-09 20:20:27 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 100 100 psImageInterpolateMode mode ///< the interpolation mode to use 101 101 ); 102 103 /** Shift image by an arbitrary number of pixels (dx,dy) in either direction. 104 * 105 * If the shift values are fractional, the output pixel values should 106 * interpolate between the input pixel values. The output image has the same 107 * dimensions as the input image. Pixels which fall off the edge of the 108 * output image are lost. Newly exposed pixels are set to the value given by 109 * exposed. This function must be defined for the following types: psU8, 110 * psU16, psS8, psS16, psF32, psF64, psC32, psC64. 111 * 112 * This implementation uses a NxN kernel generated based on the interpolation method 113 * the image is first shifted by a fractional amount with the kernel, then 114 * shifted in place by an integer amount. 115 * 116 * XXX the integer shift portion is not implemented 117 * XXX the exposed pixels are not properly replaced 118 * XXX the algorithm can properly handle a mask, but the API does not include 119 * it (and it is not implemented) 120 * 121 * @return psImage* the shifted image result. 122 */ 123 psImage* psImageShiftKernel( 124 psImage* out, ///< an psImage to recycle. If NULL, a new image is created 125 const psImage* input, ///< input image 126 float dx, ///< the shift in x direction. 127 float dy, ///< the shift in y direction. 128 psImageInterpolateMode mode ///< the interpolation mode to use 129 ); 130 131 // XXX should this be global private or local static? 132 psImage *p_psImageShiftKernel_F32( 133 psImage *out, 134 const psImage *input, 135 const psImage *kernel); 102 136 103 137 /** Roll image by an integer number of pixels in either direction. … … 151 185 psRegion region, ///< the size of the transformed image 152 186 const psPixels* pixels, /**< if not NULL, consists of psPixelCoords and specifies 153 * which pixels in output image shall be transformed;154 * otherwise, entire image generated*/187 * which pixels in output image shall be transformed; 188 * otherwise, entire image generated*/ 155 189 psImageInterpolateMode mode, ///< the interpolation scheme to be used 156 190 double exposedValue ///< Exposed value to which non-corresponding pixels are set -
trunk/psLib/src/mathtypes/psImage.h
r9864 r9927 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.8 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-11-0 6 02:00:40$13 * @version $Revision: 1.83 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-11-09 20:20:27 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 35 35 PS_INTERPOLATE_BILINEAR, ///< bi-linear interpolation 36 36 PS_INTERPOLATE_BICUBE, ///< bi-cubic interpolation with 3x3 region (EAM) 37 PS_INTERPOLATE_GAUSS, ///< bi-cubic interpolation with 3x3 region (EAM) 37 38 PS_INTERPOLATE_LANCZOS2, ///< Sinc interpolation with 4x4 pixel kernel 38 39 PS_INTERPOLATE_LANCZOS3, ///< Sinc interpolation with 6x6 pixel kernel
Note:
See TracChangeset
for help on using the changeset viewer.
