Image-Leptonica
view release on metacpan or search on metacpan
lib/Image/Leptonica/Func/binarize.pm view on Meta::CPAN
Notes:
(1) The window width and height are 2 * @whsize + 1. The minimum
value for @whsize is 2; typically it is >= 7..
(2) The local statistics, measured over the window, are the
average and standard deviation.
(3) The measurements of the mean and standard deviation are
performed inside a border of (@whsize + 1) pixels. If pixs does
not have these added border pixels, use @addborder = 1 to add
it here; otherwise use @addborder = 0.
(4) The Sauvola threshold is determined from the formula:
t = m * (1 - k * (1 - s / 128))
where:
t = local threshold
m = local mean
k = @factor (>= 0) [ typ. 0.35 ]
s = local standard deviation, which is maximized at
127.5 when half the samples are 0 and half are 255.
(5) The basic idea of Niblack and Sauvola binarization is that
the local threshold should be less than the median value,
and the larger the variance, the closer to the median
lib/Image/Leptonica/Func/binarize.pm view on Meta::CPAN
value for @whsize is 2; typically it is >= 7..
(2) For nx == ny == 1, this defaults to pixSauvolaBinarize().
(3) Why a tiled version?
(a) Because the mean value accumulator is a uint32, overflow
can occur for an image with more than 16M pixels.
(b) The mean value accumulator array for 16M pixels is 64 MB.
The mean square accumulator array for 16M pixels is 128 MB.
Using tiles reduces the size of these arrays.
(c) Each tile can be processed independently, in parallel,
on a multicore processor.
(4) The Sauvola threshold is determined from the formula:
t = m * (1 - k * (1 - s / 128))
See pixSauvolaBinarize() for details.
=head2 pixSauvolaGetThreshold
PIX * pixSauvolaGetThreshold ( PIX *pixm, PIX *pixms, l_float32 factor, PIX **ppixsd )
pixSauvolaGetThreshold()
Input: pixm (8 bpp grayscale; not colormapped)
pixms (32 bpp)
factor (factor for reducing threshold due to variance; >= 0)
&pixsd (<optional return> local standard deviation)
Return: pixd (8 bpp, sauvola threshold values), or null on error
Notes:
(1) The Sauvola threshold is determined from the formula:
t = m * (1 - k * (1 - s / 128))
where:
t = local threshold
m = local mean
k = @factor (>= 0) [ typ. 0.35 ]
s = local standard deviation, which is maximized at
127.5 when half the samples are 0 and half are 255.
(2) See pixSauvolaBinarize() for other details.
(3) Important definitions and relations for computing averages:
v == pixel value
lib/Image/Leptonica/Func/morphdwa.pm view on Meta::CPAN
a set of operations with Sels not exceeding 63 pixels
in either width or height (and with the origin as close
to the center of the Sel as possible).
(2) This returns the decomposition of a linear Sel of length
@size into a set of @n Sels of length 63 plus an extra
Sel of length @extra.
(3) For notation, let w == @size, n == @n, and e == @extra.
We have 1 < e < 63.
Then if w < 64, we have n = 0 and e = w.
The general formula for w > 63 is:
w = 63 + (n - 1) * 62 + (e - 1)
Where did this come from? Each successive convolution with
a Sel of length L adds a total length (L - 1) to w.
This accounts for using 62 for each additional Sel of size 63,
and using (e - 1) for the additional Sel of size e.
Solving for n and e for w > 63:
n = 1 + Int((w - 63) / 62)
e = w - 63 - (n - 1) * 62 + 1
lib/Image/Leptonica/Func/numafunc1.pm view on Meta::CPAN
Note: if naloc is given, there is no requirement that the
data points are evenly spaced. Lagrangian interpolation
handles that. The only requirement is that the
data points are ordered so that the values in naloc
are either increasing or decreasing. We test to make
sure that the sizes of na and naloc are equal, and it
is assumed that the correspondences na[i] as a function
of naloc[i] are properly arranged for all i.
The formula for Lagrangian interpolation through 3 data pts is:
y(x) = y1(x-x2)(x-x3)/((x1-x2)(x1-x3)) +
y2(x-x1)(x-x3)/((x2-x1)(x2-x3)) +
y3(x-x1)(x-x2)/((x3-x1)(x3-x2))
Then the derivative, using the constants (c1,c2,c3) defined below,
is set to 0:
y'(x) = 2x(c1+c2+c3) - c1(x2+x3) - c2(x1+x3) - c3(x1+x2) = 0
=head2 numaGetBinSortIndex
lib/Image/Leptonica/Func/numafunc1.pm view on Meta::CPAN
(1) The values in nax must be sorted in increasing order.
If they are not sorted, we do it here, and complain.
(2) If the values in nax are equally spaced, you can use
numaInterpolateEqxInterval().
(3) Caller should check for valid return.
(4) We don't call numaInterpolateArbxVal() for each output
point, because that requires an O(n) search for
each point. Instead, we do a single O(n) pass through
nax, saving the indices to be used for each output yval.
(5) Uses lagrangian interpolation. See numaInterpolateEqxVal()
for formulas.
=head2 numaInterpolateArbxVal
l_int32 numaInterpolateArbxVal ( NUMA *nax, NUMA *nay, l_int32 type, l_float32 xval, l_float32 *pyval )
numaInterpolateArbxVal()
Input: nax (numa of abscissa values)
nay (numa of ordinate values, corresponding to nax)
type (L_LINEAR_INTERP, L_QUADRATIC_INTERP)
xval
&yval (<return> interpolated value)
Return: 0 if OK, 1 on error (e.g., if xval is outside range)
Notes:
(1) The values in nax must be sorted in increasing order.
If, additionally, they are equally spaced, you can use
numaInterpolateEqxVal().
(2) Caller should check for valid return.
(3) Uses lagrangian interpolation. See numaInterpolateEqxVal()
for formulas.
=head2 numaInterpolateEqxInterval
l_int32 numaInterpolateEqxInterval ( l_float32 startx, l_float32 deltax, NUMA *nasy, l_int32 type, l_float32 x0, l_float32 x1, l_int32 npts, NUMA **pnax, NUMA **pnay )
numaInterpolateEqxInterval()
Input: startx (xval corresponding to first element in nas)
deltax (x increment between array elements in nas)
nasy (numa of ordinate values, assumed equally spaced)
lib/Image/Leptonica/Func/rotate.pm view on Meta::CPAN
sqrt(w*w + h*h).
(5) For an arbitrary angle, the expansion can be found by
considering the UL and UR corners. As the image is
rotated, these move in an arc centered at the center of
the image. Normalize to a unit circle by dividing by half
the image diagonal. After a rotation of T radians, the UL
and UR corners are at points T radians along the unit
circle. Compute the x and y coordinates of both these
points and take the max of absolute values; these represent
the half width and half height of the containing rectangle.
The arithmetic is done using formulas for sin(a+b) and cos(a+b),
where b = T. For the UR corner, sin(a) = h/d and cos(a) = w/d.
For the UL corner, replace a by (pi - a), and you have
sin(pi - a) = h/d, cos(pi - a) = -w/d. The equations
given below follow directly.
=head2 pixRotate
PIX * pixRotate ( PIX *pixs, l_float32 angle, l_int32 type, l_int32 incolor, l_int32 width, l_int32 height )
pixRotate()
lib/Image/Leptonica/Func/seedfill.pm view on Meta::CPAN
For some applications, the filled seed will later be OR'd
with the negative of the mask. This is used, for example,
when you flood fill into a 4-connected region of OFF pixels
and you want the result after those pixels are turned ON.
Note carefully that the mask we use delineates which pixels
are allowed to be ON as the seed is filled. We will call this
a "filling mask". As the seed expands, it is repeatedly
ANDed with the filling mask: s & fm. The process can equivalently
be formulated using the inverse of the filling mask, which
we will call a "blocking mask": bm = ~fm. As the seed
expands, the blocking mask is repeatedly used to prevent
the seed from expanding into the blocking mask. This is done
by set subtracting the blocking mask from the expanded seed:
s - bm. Set subtraction of the blocking mask is equivalent
to ANDing with the inverse of the blocking mask: s & (~bm).
But from the inverse relation between blocking and filling
masks, this is equal to s & fm, which proves the equivalence.
For efficiency, the pixels can be taken in larger units
lib/Image/Leptonica/Func/seedfill.pm view on Meta::CPAN
In pixSeedfillBinary(), the filling distance is unrestricted
and can be larger than pixs, depending on the topology of
th mask.
(2) There are occasions where it is useful not to permit the
fill to go more than a certain distance into the mask.
@xmax specifies the maximum horizontal distance allowed
in the fill; @ymax does likewise in the vertical direction.
(3) Operationally, the max "distance" allowed for the fill
is a linear distance from the original seed, independent
of the actual mask topology.
(4) Another formulation of this problem, not implemented,
would use the manhattan distance from the seed, as
determined by a breadth-first search starting at the seed
boundaries and working outward where the mask fg allows.
How this might use the constraints of separate xmax and ymax
is not clear.
=head2 pixSeedfillGray
l_int32 pixSeedfillGray ( PIX *pixs, PIX *pixm, l_int32 connectivity )
( run in 1.320 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )