Changeset 17726
- Timestamp:
- May 16, 2008, 3:38:20 PM (18 years ago)
- Location:
- trunk/psLib/src/imageops
- Files:
-
- 2 edited
-
psImageConvolve.c (modified) (2 diffs)
-
psImageConvolve.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageConvolve.c
r17365 r17726 7 7 /// @author Eugene Magnier, IfA 8 8 /// 9 /// @version $Revision: 1.6 6$ $Name: not supported by cvs2svn $10 /// @date $Date: 2008-0 4-07 20:30:38$9 /// @version $Revision: 1.67 $ $Name: not supported by cvs2svn $ 10 /// @date $Date: 2008-05-17 01:38:20 $ 11 11 /// 12 12 /// Copyright 2004-2007 Institute for Astronomy, University of Hawaii … … 755 755 return true; 756 756 } 757 758 759 760 761 psImage *psImageConvolveMask(psImage *out, const psImage *mask, psMaskType maskVal, 762 psMaskType setVal, int xMin, int xMax, int yMin, int yMax) 763 { 764 PS_ASSERT_IMAGE_NON_NULL(mask, NULL); 765 PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL); 766 if (out) { 767 PS_ASSERT_IMAGE_NON_NULL(out, NULL); 768 PS_ASSERT_IMAGE_TYPE(out, PS_TYPE_MASK, NULL); 769 PS_ASSERT_IMAGES_SIZE_EQUAL(out, mask, NULL); 770 if (out == mask && ((maskVal & setVal) || !setVal)) { 771 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 772 "Can't convolve mask in-place if values to set contains values to convolve."); 773 return NULL; 774 } 775 } 776 777 if (yMin > yMax) { 778 psWarning("Specified yMin, %d, was greater than yMax, %d. Values swapped.", 779 yMin, yMax); 780 781 int temp = yMin; 782 yMin = yMax; 783 yMax = temp; 784 } 785 if (xMin > xMax) { 786 psWarning("Specified xMin, %d, was greater than xMax, %d. Values swapped.", 787 xMin, xMax); 788 789 int temp = xMin; 790 xMin = xMax; 791 xMax = temp; 792 } 793 794 int numRows = mask->numRows; // Number of rows 795 int numCols = mask->numCols; // Number of columns 796 797 if (!out) { 798 // Propagate the non-masked values 799 out = (psImage*)psBinaryOp(NULL, (const psPtr)mask, "&", psScalarAlloc(~maskVal, PS_TYPE_MASK)); 800 } 801 802 if (!setVal) { 803 setVal = maskVal; 804 } 805 806 // Dereference mask images 807 psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA; 808 psMaskType **outData = out->data.PS_TYPE_MASK_DATA; 809 810 // Since we're just masking everything inside a square, it's separable 811 for (int y = 0; y < numRows; y++) { 812 int min = 0, max = 0; // Minimum and maximum points to mask 813 bool masking = false; // Currently masking? 814 for (int x = 0; x < numCols; x++) { 815 if (maskData[y][x] & maskVal) { 816 if (!masking) { 817 masking = true; 818 min = x + xMin; 819 max = x + xMax; 820 } else { 821 max++; 822 } 823 } else if (masking) { 824 // Do the masking 825 masking = false; 826 min = PS_MAX(0, min); 827 max = PS_MIN(numCols - 1, max); 828 for (int i = min; i < max; i++) { 829 outData[y][i] |= setVal; 830 } 831 } 832 } 833 } 834 for (int x = 0; x < numCols; x++) { 835 int min = 0, max = 0; // Minimum and maximum points to mask 836 bool masking = false; // Currently masking? 837 for (int y = 0; y < numRows; y++) { 838 if (maskData[y][x] & maskVal) { 839 if (!masking) { 840 masking = true; 841 min = y + yMin; 842 max = y + yMax; 843 } else { 844 max++; 845 } 846 } else if (masking) { 847 // Do the masking 848 masking = false; 849 min = PS_MAX(0, min); 850 max = PS_MIN(numRows - 1, max); 851 for (int i = min; i < max; i++) { 852 outData[i][x] |= setVal; 853 } 854 } 855 } 856 } 857 858 return out; 859 } -
trunk/psLib/src/imageops/psImageConvolve.h
r17320 r17726 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1.3 2$ $Name: not supported by cvs2svn $8 * @date $Date: 2008-0 4-04 22:44:56$7 * @version $Revision: 1.33 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2008-05-17 01:38:20 $ 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 10 10 */ … … 141 141 ); 142 142 143 /// Convolve a mask image with a kernel 144 /// 145 /// Returns a mask, grown by the supplied convolution bounds. Only those pixels specified by the maskVal are 146 /// grown, being ORed with setVal; the rest are simply propagated. If setVal is zero, uses maskVal; note that 147 /// the mode of growing individual bits in maskVal is NOT supported because this algorithm does not enable it. 148 psImage *psImageConvolveMask(psImage *out, ///< Output image, or NULL 149 const psImage *mask, ///< Mask to convolve 150 psMaskType maskVal, ///< Mask value to convolve 151 psMaskType setVal, ///< Mask value to set; 0 to propagate maskVal 152 int xMin, int xMax, int yMin, int yMax ///< Convolution bounds 153 ); 154 143 155 /// Convolve a mask image with a kernel, using direct convolution 144 156 ///
Note:
See TracChangeset
for help on using the changeset viewer.
