| 50 | } |
| 51 | |
| 52 | bool IPLFrequencyFilter::processInputData(IPLData* data , int, bool) |
| 53 | { |
| 54 | IPLComplexImage* complexImageData = data->toComplexImage(); |
| 55 | if (NULL == complexImageData) { |
| 56 | // TODO write an error message |
| 57 | return false; |
| 58 | } |
| 59 | _input = new IPLComplexImage(*complexImageData); |
| 60 | |
| 61 | // delete previous result |
| 62 | delete _result; |
| 63 | delete _filter; |
| 64 | |
| 65 | _result = new IPLComplexImage(*_input); |
| 66 | int width = _result->width(); |
| 67 | int height = _result->height(); |
| 68 | _filter = new IPLImage(IPL_IMAGE_GRAYSCALE, width, height); |
| 69 | |
| 70 | |
| 71 | // get properties |
| 72 | int maskType = getProcessPropertyInt("maskType"); |
| 73 | double lowCutoff = getProcessPropertyDouble("low_cutoff"); |
| 74 | double highCutoff = getProcessPropertyDouble("high_cutoff"); |
| 75 | bool keepDC = getProcessPropertyBool("keepDC"); |
| 76 | |
| 77 | int halfSize = _result->width()/2; |
| 78 | int size = _result->width(); |
| 79 | int lowRange = lowCutoff*lowCutoff*halfSize*halfSize; |
| 80 | int highRange = highCutoff*highCutoff*halfSize*halfSize; |
| 81 | |
| 82 | Complex c0 = Complex( 0.0, 0.0 ); |
| 83 | |
| 84 | for( int x=-halfSize; x<halfSize; x++ ) |
| 85 | { |
| 86 | for( int y=-halfSize; y<halfSize; y++ ) |
| 87 | { |
| 88 | int X = ( x < 0 )? size+x : x; |
| 89 | int Y = ( y < 0 )? size+y : y; |
| 90 | int range = x*x+y*y; |
| 91 | switch( maskType ) |
| 92 | { |
| 93 | case 0: if( range > lowRange ) |
| 94 | _result->c(X,Y) = c0; |
| 95 | break; |
| 96 | case 1: if( range < highRange ) |
| 97 | _result->c(X,Y) = c0; |
| 98 | break; |
| 99 | case 2: if( range < lowRange || range > highRange ) |
| 100 | _result->c(X,Y) = c0; |
| 101 | break; |
| 102 | case 3: if( range > lowRange && range < highRange ) |
| 103 | _result->c(X,Y) = c0; |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if( keepDC ) _result->c( 0, 0 ) = _input->c( 0, 0 ); |