I'd like to add complex image support to vil2. My main motivation is to be
able to use the FFT on image data without moving back and forth between
images and vnl_matrix. Here are the main points of the plan. I'm looking
for comments, suggestions and for someone to 2nd my motion that this is a
good thing.
I've already got this to work very well with a surprisingly small number of
modifications. Diffs to vil2_pixel_format.*, vil2_print.h are below. After
these simple additions, vil2_view_as_planes() worked as it was -- a
testament to the solid design of vil2. All vil2_view_as_planes() required
was that sizeof(complex<double>)/sizeof<double) == 2, and it worked.
I've attached example_complex.cxx, which is a sort of a development scratch
pad at the moment. It contains a few lines that will end up in Templates
files, and a few functions which will go into vil2_view_as.h, some fft
functions that will go into vil2/algo/vil2_fft.cxx, and some example code.
I only plan to add complex support for doubles and float, no complex
integral types. The chance of them being used is so low that I don't think
its worth adding them.
I think it is worth having a 2D FFT algorithm for both vnl_matrix and
vil2_image_view. It's a small amount of additional code.
This could be taken to the extreme, adding support for images of
rgb<complex<double>>, but I don't think that would be useful enough to
warrant the code bloat. With these small changes I'd like to make, you can
have a 3 plane image of complex<doubles>, get a view of the real part and
convert to a view as rgb<double>. Again, the ease of doing this shows how
well vil2 was designed.
I'll add a test for complex images and a test for the FFT of images.
Anybody see any problems? I'm hesitant to add to core without airing the
plan.
Regards,
Fred Wheeler
Index: vil2_pixel_format.cxx
===================================================================
RCS file: /cvsroot/vxl/vxl/core/vil2/vil2_pixel_format.cxx,v
retrieving revision 1.12
diff -r1.12 vil2_pixel_format.cxx
7a8
> #include <vcl_complex.h>
46a48,51
>
> sizeof(vcl_complex<float>), // VIL2_PIXEL_FORMAT_COMPLEX_FLOAT
> sizeof(vcl_complex<double>), // VIL2_PIXEL_FORMAT_COMPLEX_DOUBLE
>
88a94,97
>
> 1, // VIL2_PIXEL_FORMAT_COMPLEX_FLOAT
> 1, // VIL2_PIXEL_FORMAT_COMPLEX_DOUBLE
>
130a140,143
>
> VIL2_PIXEL_FORMAT_COMPLEX_FLOAT, // VIL2_PIXEL_FORMAT_COMPLEX_FLOAT
> VIL2_PIXEL_FORMAT_COMPLEX_DOUBLE, //
VIL2_PIXEL_FORMAT_COMPLEX_DOUBLE
>
188a202,204
>
> case VIL2_PIXEL_FORMAT_COMPLEX_FLOAT: os << "complex<float>";
break;
> case VIL2_PIXEL_FORMAT_COMPLEX_DOUBLE: os << "complex<double>";
break;
Index: vil2_pixel_format.h
===================================================================
RCS file: /cvsroot/vxl/vxl/core/vil2/vil2_pixel_format.h,v
retrieving revision 1.20
diff -r1.20 vil2_pixel_format.h
11a12
> #include <vcl_complex.h>
52a54,57
>
> VIL2_PIXEL_FORMAT_COMPLEX_FLOAT = 35,
> VIL2_PIXEL_FORMAT_COMPLEX_DOUBLE = 36,
>
56c61
< VIL2_PIXEL_FORMAT_ENUM_END = 35
---
> VIL2_PIXEL_FORMAT_ENUM_END = 37
116a122,124
>
> vil2_pixel_format_macro(vcl_complex<float>,
VIL2_PIXEL_FORMAT_COMPLEX_FLOAT)
> vil2_pixel_format_macro(vcl_complex<double>,
VIL2_PIXEL_FORMAT_COMPLEX_DOUBLE)
Index: vil2_print.cxx
===================================================================
RCS file: /cvsroot/vxl/vxl/core/vil2/vil2_print.cxx,v
retrieving revision 1.5
diff -r1.5 vil2_print.cxx
8a9
> #include <vcl_complex.h>
97a99,105
> {
> os<<value;
> }
>
> //: Explicit overload for complex double
> VCL_DEFINE_SPECIALIZATION
> void vil2_print_value(vcl_ostream& os, const vcl_complex<double>& value)
begin 600 example_complex.cxx
M+R\Z#0HO+R!<9FEL90T*+R\@7&)R:65F($5X86UP;&5S('5S:6YG(&-O;7!L
M97@...
M92`\=GAL7V-O;F9I9RYH/@T*(VEN8VQU9&4@...*
M(VEN8VQU9&4@...
M7VEM86=E7W9I97<N:#X-"B-I;F-L=61E(#QV:6PR+W9I;#)?=FEE=U]A<RYH
M/@T*(VEN8VQU9&4@...
M;#(O=FEL,E]C;VYV97)T+F@...
M:#X-"B-I;F-L=61E(#QV;FPO=FYL7W9E8W1O<BYH/@T*(VEN8VQU9&4@...
M;"]V;FQ?=F5C=&]R7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/B`J(&0@...`@
M("`@("`@("!V;FQ?=F5C=&]R7W)E9CQV8VQ?8V]M<&QE>#Q4/B`^('8@...
M+"!D*3L-"B`@("`@("`@("!F9G1?,60N=')A;G-F;W)M("AV+"!D:7(I.PT*
M("`@("`@("`@(&EF("@Q(#T](&1I<BD-"B`@("`@("`@("`@("`@=B`O/2!N
M,#L-"B`@("`@('T-"B`@?0T*("!E;'-E('L-"B`@("`@('9N;%]V96-T;W(\
M=F-L7V-O;7!L97@...
M(&DQ/3`[(&DQ/&XQ.R!I,2LK*0T*("`@("`@9F]R("AU;G-I9VYE9"!I,CTP
M.R!I,CQN,CL@...@
M9"`](&1A=&$@*R!I,2IS=&5P,2`K(&DR*G-T97`R.PT*("`@("`@("`@(&9O
M<B`H=6YS:6=N960@...*("`@
M("`@("`@("`@("!V*&DP*2`]("ID.PT*("`@("`@("`@(&9F=%\Q9"YT<F%N
M<V9O<FT@...*("`@
M("`@("`@("`@("!V("\](&XP.PT*("`@("`@("`@(&0@...
M<W1E<#$@*R!I,BIS=&5P,CL-"B`@("`@("`@("!F;W(@*'5N<VEG;F5D(&DP
M/3`[(&DP/&XP.R!I,"LK+"!D*SUS=&5P,"D-"B`@("`@("`@("`@("`@*F0@
M/2!V*&DP*3L-"B`@("`@('T-"B`@?0T*?0T*#0HO+SH@...
M;&%C92!F;W)W87)D($9&5`T*=&5M<&QA=&4\8VQA<W,@5#X-"G9O:60-"G9I
M;#)?9F9T7S)D7V9W9"`H=FEL,E]I;6%G95]V:65W/'9C;%]C;VUP;&5X/%0^
M(#X@...
M=%]P='(H*2P-"B`@("`@("`@("`@("`@("`@("`@:6UG+FYI*"DL(&EM9RYI
M<W1E<"@I+`T*("`@("`@("`@("`@("`@("`@("!I;6<N;FHH*2P@...
M=&5P*"DL#0H@...
M9RYP;&%N97-T97`H*2P-"B`@("`@("`@("`@("`@("`@("`@,2D[#0H@...
M;#)?9F9T7S)D7V)A<V4@...`@("`@("`@
M("`@("`@("`@("`@:6UG+FYJ*"DL(&EM9RYJ<W1E<"@I+`T*("`@("`@("`@
M("`@("`@("`@("!I;6<N;FDH*2P@...@("`@("`@("`@
M("`@("`@("`@(&EM9RYN<&QA;F5S*"DL(&EM9RYP;&%N97-T97`H*2P-"B`@
M("`@("`@("`@("`@("`@("`@,2D[#0I]#0H-"B\O.B!097)F;W)M(&EN('!L
M86-E(&)A8VMW87)D($9&5`T*=&5M<&QA=&4\8VQA<W,@5#X-"G9O:60-"G9I
M;#)?9F9T7S)D7V)W9"`H=FEL,E]I;6%G95]V:65W/'9C;%]C;VUP;&5X/%0^
M(#X@...
M=%]P='(H*2P-"B`@("`@("`@("`@("`@("`@("`@:6UG+FYJ*"DL(&EM9RYJ
M<W1E<"@I+`T*("`@("`@("`@("`@("`@("`@("!I;6<N;FDH*2P@...
M=&5P*"DL#0H@...
M9RYP;&%N97-T97`H*2P-"B`@("`@("`@("`@("`@("`@("`@+3$I.PT*("!V
M:6PR7V9F=%\R9%]B87-E("AI;6<N=&]P7VQE9G1?<'1R*"DL#0H@("`@("`@
M("`@("`@("`@("`@(&EM9RYN:2@...`@("`@("`@
M("`@("`@("`@("`@:6UG+FYJ*"DL(&EM9RYJ<W1E<"@I+`T*("`@("`@("`@
M("`@("`@("`@("!I;6<N;G!L86YE<R@...@
M("`@("`@("`@("`@("`@("`@("TQ*3L-"GT-"@T*+R\O+R\O+R\O+R\O+R\O
M+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O
M+R\O+R\O+R\O+R\O+R\O+PT*#0II;G0-"FUA:6X@...
M*BH@...
M=6)L93X@...
M;7!L97@...
M;FDH*3L@...@
M:BLK*0T*("!F;W(@*'5N<VEG;F5D('`],#L@...
M*RLI#0H@...
M<&QE>#QD;W5B;&4^("@Q,3$K:2LQ,"IJ*S$P,"IP*S`N,2P@...
M:BLQ,#`J<"LP+C(I.PT*#0H@...
M('9I97<-"B`@=F-L7V-O=70@...
M(#P\('9C;%]E;F1L.PT*("!V:6PR7W!R:6YT7V%L;"`H=F-L7V-O=70L(&EM
M9RD[#0H@...,@
M<&QA;F5S#0H@...
M;6%G92!H87,@;VYL>2`Q('!L86YE#0H@...
M;&4^(&EM9U]P(#T@...
M+R!P<FEN="!T:&4@...
M8V]M<&QE>"!I;6%G92!V:65W960@...
M"B`@=FEL,E]P<FEN=%]A;&P@...
M;W5T(#P\('9C;%]E;F1L.PT*#0H@...
M86-K('1O(&-O;7!L97@...
M;7!L97@...@@
M*&EM9U]P*3L-"@T*("`O+R!P<FEN="!T:&4@...
M92!V:65W#0H@...
M86-K('1O(&-O;7!L97@...
M;G1?86QL("AV8VQ?8V]U="P@...?
M96YD;#L-"@T*("`O+R!G970@...@
M86YD(&EM86=I;F%R>2!P87)T<R!O9B!T:&4@...
M95]V:65W/&1O=6)L93X@...
M;6<I.PT*("!V:6PR7VEM86=E7W9I97<\9&]U8FQE/B!I;6=?:2`]('9I;#)?
M=FEE=U]I;6%G7W!A<G0@...
M871E('9I97=S(&]F('1H92!R96%L(&%N9"!I;6%G:6YA<GD@...`@
M=F-L7V-O=70@...
M"B`@=FEL,E]P<FEN=%]A;&P@...
M;W5T(#P\('9C;%]E;F1L.PT*("!V8VQ?8V]U="`\/"`B=FEE=R!O9B!I;6%G
M('!A<G0B(#P\('9C;%]E;F1L.PT*("!V:6PR7W!R:6YT7V%L;"`H=F-L7V-O
M=70L(&EM9U]I*3L-"B`@=F-L7V-O=70@...\@
M8VAA;F=E('9A;'5E<R!V:6$@=&AE('-E<&%R871E('9I97=S#0H@...
M*#`L,"PP*2`](#@X."XX.PT*("!I;6=?:2@...*
M("`O+R!P<FEN="!T:&4@...
M92!T:&4@...
M86YG960@...
M;#)?<')I;G1?86QL("AV8VQ?8V]U="P@...@
M=F-L7V5N9&P[#0H-"B`@+R\@;6%K92!A(&-O<'D-"B`@=FEL,E]I;6%G95]V
M:65W/'9C;%]C;VUP;&5X/&1O=6)L93X@...!?
M8V]P>2`H:6UG*3L-"@T*("`O+R!F;W)W87)D($9&5`T*("!V:6PR7V9F=%\R
M9%]F=V0@...
M('9I97<@86=A:6X@...@
M(D9&5"!O9B!C;VUP;&5X(&EM86=E(B`\/"!V8VQ?96YD;#L-"B`@=FEL,E]P
M<FEN=%]A;&P@...
M7V5N9&P[#0H-"B`@+R\@8F%C:W=A<F0@...
M9"`H:6UG,BD[#0H-"B`@+R\@<')I;G0@...
M=R!A9V%I;B!T;R!S964@...
M97)S92!&1E0@...
M.PT*("!V:6PR7W!R:6YT7V%L;"`H=F-L7V-O=70L(&EM9S(I.PT*("!V8VQ?
M8V]U="`\/"!V8VQ?96YD;#L-"@T*("`O+R!C;VYV97)T(')E86P@...
M;R!A;B!I;G1E9W)A;"!T>7!E#0H@...
M=%\Q-CX@...
M;6=?<BP@...
M<G0@...;#)?
M<')I;G1?86QL("AV8VQ?8V]U="P@...@
M=F-L7V5N9&P[#0H-"B`@=FEL,E]S879E("AI;6=?<FDL(")F;V\N<&YG(BD[
4#0H-"B`@<F5T=7)N(#`[#0I]#0H=
`
end
|