-
Notifications
You must be signed in to change notification settings - Fork 4
/
integrate-dx.bsh
55 lines (45 loc) · 1.24 KB
/
integrate-dx.bsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import ij.*;
import ij.process.*;
/**
*
*/
float mean( FloatProcessor source, int first, int last )
{
double sum = 0;
for ( int i = first; i < last; ++i )
sum += source.getf( i );
return ( float )( sum / ( last - first ) );
}
/**
* source and target are assumed to have identical dimensions.
*/
void integrateRow( FloatProcessor source, FloatProcessor target, int row )
{
final int first = row * source.getWidth();
final int last = first + source.getWidth();
final float dxMean = mean( source, first, last );
/* integrate */
double x = 0;
double xMean = 0;
for ( int i = first; i < last; ++i )
{
final float dx = source.getf( i );
x += dx - dxMean;
target.setf( i, ( float )x );
xMean += x;
}
xMean /= last - first;
/* normalize */
for ( int i = first; i < last; ++i )
target.setf( i, target.getf( i ) - ( float )xMean );
}
ImagePlus impSource = IJ.getImage();
FloatProcessor source = impSource.getProcessor().convertToFloat();
FloatProcessor target = new FloatProcessor( source.getWidth(), source.getHeight() );
ImagePlus impTarget = new ImagePlus( "I " + impSource.getTitle(), target );
impTarget.show();
for ( int i = 0; i < source.getHeight(); ++i )
{
integrateRow( source, target, i );
impTarget.updateAndDraw();
}