Image-Leptonica
view release on metacpan or search on metacpan
lib/Image/Leptonica/Func/morphdwa.pm view on Meta::CPAN
- Recompile the library.
- Make prog/fmorphautogen.
- Run prog/fmorphautogen, to generate new versions of the
dwa code in fmorphgen.1.c and fmorphgenlow.1.c.
- Copy these two files to src.
- Recompile the library again.
- Use the new brick Sels in your program and compile it.
(2) Make both the new Sels and dwa code outside the library,
and link it directly to an executable:
- Write a function to generate the new Sels in a Sela, and call
fmorphautogen(sela, <N>, filename) to generate the code.
- Compile your program that uses the newly generated function
pixMorphDwa_<N>(), and link to the two new C files.
(3) Make the new Sels in the library and use the dwa code outside it:
- Add code in the library to generate your new brick Sels.
(It is suggested that you NOT add these Sels to the
selaAddBasic() function; write a new function that generates
a new Sela.)
- Recompile the library.
- Write a small program that generates the Sela and calls
fmorphautogen(sela, <N>, filename) to generate the code.
- Compile your program that uses the newly generated function
pixMorphDwa_<N>(), and link to the two new C files.
As an example of this approach, see prog/dwamorph*_reg.c:
- added selaAddDwaLinear() to sel2.c
- wrote dwamorph1_reg.c, to generate the dwa code.
- compiled and linked the generated code with the application,
dwamorph2_reg.c. (Note: because this was a regression test,
dwamorph1_reg also builds and runs the application program.)
=head1 FUNCTIONS
=head2 getExtendedCompositeParameters
l_int32 getExtendedCompositeParameters ( l_int32 size, l_int32 *pn, l_int32 *pextra, l_int32 *pactualsize )
getExtendedCompositeParameters()
Input: size (of linear Sel)
&pn (<return> number of 63 wide convolutions)
&pextra (<return> size of extra Sel)
&actualsize (<optional return> actual size used in operation)
Return: 0 if OK, 1 on error
Notes:
(1) The DWA implementation allows Sels to be used with hits
up to 31 pixels from the origin, either horizontally or
vertically. Larger Sels can be used if decomposed into
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
The extra part is decomposed into two factors f1 and f2,
and the actual size of the extra part is
e' = f1 * f2
Then the actual width is:
w' = 63 + (n - 1) * 62 + f1 * f2 - 1
=head2 pixCloseBrickDwa
PIX * pixCloseBrickDwa ( PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize )
pixCloseBrickDwa()
Input: pixd (<optional>; this can be null, equal to pixs,
or different from pixs)
pixs (1 bpp)
hsize (width of brick Sel)
vsize (height of brick Sel)
Return: pixd
Notes:
(1) This is a 'safe' closing; we add an extra border of 32 OFF
pixels for the standard asymmetric b.c.
(2) These implement 2D brick Sels, using linear Sels generated
with selaAddBasic().
(3) A brick Sel has hits for all elements.
(4) The origin of the Sel is at (x, y) = (hsize/2, vsize/2)
(5) Do separably if both hsize and vsize are > 1.
(6) It is necessary that both horizontal and vertical Sels
of the input size are defined in the basic sela.
(7) Note that we must always set or clear the border pixels
before each operation, depending on the the b.c.
(symmetric or asymmetric).
(8) There are three cases:
(a) pixd == null (result into new pixd)
(b) pixd == pixs (in-place; writes result back to pixs)
(c) pixd != pixs (puts result into existing pixd)
(9) For clarity, if the case is known, use these patterns:
(a) pixd = pixCloseBrickDwa(NULL, pixs, ...);
(b) pixCloseBrickDwa(pixs, pixs, ...);
(c) pixCloseBrickDwa(pixd, pixs, ...);
(10) The size of the result is determined by pixs.
(11) If either linear Sel is not found, this calls
the appropriate decomposible function.
=head2 pixCloseCompBrickDwa
PIX * pixCloseCompBrickDwa ( PIX *pixd, PIX *pixs, l_int32 hsize, l_int32 vsize )
pixCloseCompBrickDwa()
( run in 0.738 second using v1.01-cache-2.11-cpan-d7f47b0818f )