Image Processing Program using TEO library A Beginners s Guide TEO ライブラリによる画像処理プログラミング入門 菅谷保之著 THE TEO PROJECT
PROGRAMMER S NOTEBOOK TEO THE TEO PROJECT
iii libteo. libteo, TEO C TEO. TEO,. TEO. TEO. TEO, TEO. TEO,, MMX,.. 1, Linux TEO. Linux Vine Linux 3.2,. TEO 2, TEO. TEO. TEO TEO..
iv TEO - 4, TEO.,. TEO - 5, TEO.. 6, 5,,,. A libteo A TEO libteo. B TEO B TEO, TEO,. C TEO TeoEyes C TEO teoeyes. D TEO D libteo TEO. E MMX E MMX., Vine Linux 3.2., Vine Linux 3.2,. 1 Vine Linux 3.2 TEO, Vine Linux 3.2,.,. sugaya@suri.it.okayama-u.ac.jp. http://www.suri.it.okayama-u.ac.jp/~sugaya/documents/teoprogrammingguide/
v 1 1 1.1 libteo........................................... 1 1.2 libteo....................................... 2 1.2.1 TAR............................ 3 1.2.2 RPM............................ 4 1.3 TEO TeoEyes.......................... 5 1.3.1 3.2.4............................. 5 1.4............................................. 7 2 TEO 9 2.1..................................... 9 2.2 TEO.................................. 11 2.3....................................... 12 2.3.1.......................................... 12 2.3.2.......................................... 13 2.3.3.......................................... 14 2.4 TEO......................................... 14 3 TEO 15 3.1....................................... 15 3.2 libteo.............................. 17 3.2.1 TEOFILE..................................... 17 3.2.2 TEOIMAGE................................... 18 3.2.3......................................... 19 3.3............................................. 19 3.4.......................................... 20 3.5............................................ 21 3.6....................................... 24 4 TEO - 27 4.1............................ 27 4.2 - RGB YCrCb -............... 31 4.3 - -...................... 35
vi 4.4 - -........................... 39 5 TEO - 45 5.1.................................. 45 5.2................................... 48 5.3.................................... 52 5.4....................................... 54 5.5................................... 58 6 61 6.1............................................ 61 6.1.1.................................... 61 6.1.2..................................... 62 6.1.3...................................... 62 6.2..................................... 64 6.2.1............................... 64 6.2.2.............................. 64 6.3............................................ 65 6.3.1......................................... 65 6.3.2..................................... 65 6.3.3.......................................... 66 6.3.4................................ 67 6.4...................................... 68 6.4.1.......................................... 68 6.4.2................................. 68 6.5 2 -........................ 70 6.5.1................................ 70 6.5.2...................................... 70 A libteo 73 A.1...................................... 73 A.2........................................ 76 A.3........................................ 79 A.4...................................... 81 B TEO 89 B.1 pnm2teo............................................. 89 B.2 teo2pnm............................................. 90 B.3 teo2avi.............................................. 90 B.4 teogzip.............................................. 91 B.5 teo get extension........................................ 91 B.6 teocast.............................................. 92
vii B.7 teodiff.............................................. 92 B.8 teorange............................................. 93 C TEO TeoEyes 95 D TEO 97 D.1 libteopp............................................. 97 D.2 ruby-teo............................................. 97 D.3 libteo2ipl............................................. 97 D.4 libteo+.............................................. 97 D.5 libteo draw............................................ 98 D.6 libteo2gdk-pixbuf........................................ 98 E MMX 101 107
1 1, TEO libteo., libteo. 1.1 libteo libteo, TEO C.,.,, Windows Linux., TEO,,., BMP, JPEG, PNG, GIF.,.,,,. BMP JPEG,. TEO. TEO, libteo, (Tsukuba), *1 (ETL), (Okayama) 1997. TEO. TEO, libteo *1,
2 1.,, The FreeBSD libteo 1997, TEO., libteo,. SourceForge WEB, 2003 11 TEO SourceForge, ( 1.1). TEO 1.1 sourceforge TEO 1.2 libteo libteo. libteo https:// sourceforge.jp/project/teo/. 18 4 1 1.2.5.,. TAR rpm
1.2 libteo 3 1.2.1 TAR TAR libteo-1.2.5.tar.gz,.,,.. % cd /tmp % tar xvfz libteo-1.2.5.tar.gz configure Makefile., /usr/local., /usr/local/include, /usr/local/lib. % cd libteo-1.2.5 %./configure --prefix=/usr/local configure make,. % make % su [ ] % make install OK. /usr/local/include +--- teo.h +--- teo_debug.h /usr/local/lib +--- libteo.a +--- libteo.la +--- libteo.so +--- libteo.so.1 +--- libteo.so.1.0.4 /usr/local/lib/pkgconfig +--- teo.pc
4 1 1.2.2 RPM rpm libteo-1.2.5-1vl1.src.rpm,. /usr/local. rpm ( rpmbuild ). rpm VineLinux3.2 % rpm --rebuild libteo-1.2.5-1vl1.src.rpm rpm, % rpmbuild --rebuild libteo-1.2.5-1vl1.src.rpm ( 1.2). % rpm -ivh libteo-1.2.5-1vl1.src.rpm % cd $HOME/rpm/SPECS % emacs libteo.spec libteo.spec prefix. 1.2 libteo.spec
1.3 TEO TeoEyes 5. % rpm -ba libteo.spec rpm, % rpmbuild -ba libteo.spec. libteo-1.2.5-1vl1.i386.rpm, libteo-1.2.5-devel-1vl1.i386.rpm. $HOME/rpm/RPMS/i386 +--- libteo-1.2.5-1vl1.i386.rpm +--- libteo-devel-1.2.5-1vl1.i386.rpm rpm libteo-1.2.5-1vl1.i386,rpm. % rpm -qpl../rpms/i386/libteo-devel-1.2.5-1vl1.i386.rpm /usr/local/include/teo.h /usr/local/include/teo_debug.h /usr/local/lib/libteo.la. % rpm -ivh../rpms/i386/libteo-1.2.5-1vl1.i386.rpm % rpm -ivh../rpms/i386/libteo-devel-1.2.5-1vl1.i386.rpm 1.3 TEO TeoEyes TEO TeoEyes., TeoEyes. 18 4 1 3.2.4. https://sourceforge.jp/project/ teo/. 1.3.1 3.2.4 TeoEyes,. gtk+-2.2 (ftp://ftp.gtk.org/pub/gtk/v2.2/) GNOME-2.2 (http://ftp.gnome.org/pub/gnome/desktop/)
6 1 GConf2-2.2.0 libgnomeui-2.2.0.1 libgnomeprint-2.2.1.1 libgnomeprintui-2.2.1.1 gtkhtml2-2.2.0 gtk+, GNOME.. % cd /tmp % tar xvfz teoeyes-3.2.4.tar.bz2 % cd teoeyes-3.2.4 %./configure --prefix=/usr/local % make % su [ ] % make install teoeyes, 1.3. % teoeyes 1.3 TeoEyes
1.4 7 1.4 Vine Linux 3.2. C, (GCC). glibc-2.3.3 gcc-3.3.2, libteo /usr/local., pkg-config.
9 2 TEO TEO,. TEO,. 2.1,. 2.1, () (). 3,... ( 2.2),.,., 0 255 8., 2.2 X, Y.,, X, Y,.
10 2 TEO 2.1 ( 0, 0) x y 2.2, JPEG, GIF, PNG, PPM, BMP. (),., Linux Free BSD UNIX OS PPM, Windows BMP., 2.1. JPEG (Joint Photographic Experts Group)., DCT. GIF (Graphic Interchange Format) 8 (256 ) 256., ().. GIF, GIF, GIF. PNG (Portable Network Graphics), ( ).,, *1. PPM (Portable PixMap) Linux Free BSD UNIX OS. *1 http://tech.millto.net/~pngnews/kndh/pngspec1.2/pngcontents.html
2.2 TEO 11. BMP (Windows Bitmap) Windows. Device Independent Bitmap DIB., RLE., BMP. 2.2 TEO TEO PPM. TEO,., 0 255 8., TEO.,.,,. PPM 0 255 8.,.,. TEO,. 3.2.3., X, Y. TEO, ( ),. PPM (PGM) 1, 3., TEO,,.,.. ()., TEO. TEO. TEO,. (User Extension) TEO,.
12 2 TEO 2.3 TEO 2.3,,.. 2.2 2.4. 1 4.. 2.3.1, ( 2.5).. <D>, (0x20) TAB(0x09), <CR> (0x0a). [ ]. 0x54, 0x45, 0x4f 3, T, E, O., 0, 1. 1.,,., (0, 0)., U/S/F,, U, S, F. 1, 8, 16, 32, 64.,,. 2. #.. #. #. #%. -. "#! $ %'& " (" ')+*+, 2.3 TEO
2.3 13 TEO 1 # generated by TEO library version Version 0.4. 225 225 0 0 U 8 3 1 5;b2>g5Aj7Cl5Aj0;h2=j2:h5Bg7Di:Fo:Fo9Bl9Bl7Bo5@m5@m5@m:Er<Al7<g9Bl9Bl7@j7Cl5Aj7Cl 7Cl9Bl9Bl5@m5@m2?d<Fl7Ag4=g7@j9Ci<Fl7Di:Gl5Bg2<b0: 5Bg5Bg2?d5Bg7Di9Ci<Fl5Aj5Aj?El 7=d9Ci:@g7=d:@g<Bi5Bg5Bg:Fo7Cl2>g4>d9Ci4?a4?a7Ag9Ci<Bi9Bl9Bl5Aj2>g:Fo5Aj0;h2=j>Ft ENx<Eo2<b4>d:@g5;b:Ad4>d4>d5Bg5Bg7Bd7Bd:@g<Bi9Ao7@j9Bl5Bg:Gl7=d<Bi<>g<Gi9Df2=_2=_ )4V0;]?ElFLs7>a+6T2=[5<_:Ad:Ad:Ad:Ad:@g<Bi9Df9Df<Gi9Df7Bd9Df7B 2@]5C 9Df4?a7Bd9Df <Cf<Cf?Fi<Bi:@g:@g<Bi7Ag7Ag7=d7>a:Ad7Ag7Ag7Di7Di?El5;b:@g7Bd4?a9Df7Bd:A :A 7Bd7Bd 7Bd2@a2@a2=_7Bd:@g:@g7=d7=d:@g:@g:@g:@... -.;8-B?4B?4LI0> NL=XVGZXIZXIXVG_]NcaR^WNWQDWQD]TD_VF_VF_VFSN=SN=a\KUTAUTA\WF\WF\WF\WFdZN^XK\VI\[H ZYFWQDZTGWPGWPG\YN_\Q\YNXUNXUNWWSYYUTYSMQSAEG07@$+4+0A).?)2E,5H)2E 2.4 TEO <D> [<D>#]<CR> [#<CR>[#<CR>...]] <D> [<D>X <D>Y ][<D>#]<CR> [#<CR>[#<CR>...]] <D> [<D>#]<CR> [#<CR>[#<CR>...]] <D> [<D>#]<CR> 2.5 2.3.2.. (/8) [ ] (2.1) 1. ( ) ( 1)/8 + 1 [ ] (2.2), (floor). RGB 3, 2.3, RGB.,.
14 2 TEO 16, 32, 64,, TEO., 1, 8., 8. 8,. 2.3.3.. 2.4 TEO TEO GZIP yes, TEO.,. 3.3. libteo TEO. TEO,, teogzip, teogunzip.
15 3 TEO. libteo,., Makefile. 3.1 3.1.,. 3.1. 1 2 7 10 13 23 26 39 40 45 2 libteo teo.h. libteo. 7 10 libteo,. 3.2. 13 TEO. TEO TeoOpenFile. 16 TEO TEO. TeoCreateSimilarFile TEO (TEOFILE ), TEO. 19, 20 TeoAllocSimilarImage,
16 3 TEO. 23 TeoReadFrame,. TeoAllocSimilarImage,. 26 27. TeoXstart, TeoXend, TeoYstart, TeoYend,.,. TeoGetPixel, TeoPutPixel., 28. TeoPlane., TeoWriteFrame. TeoReadFrame,,,., 40 45 (TeoFreeImage), (TeoClose- File). 3.1, copy.c,. % gcc copy.c -o copy -I/usr/local/include -L/usr/local/lib -lteo pkg-config,. % gcc copy.c -o copy pkg-config --cflags --libs teo, copy,. teoeyes.. %./copy color.teo color-copy.teo % teoeyes color-copy.teo 3.1 1 # include <stdio. h> 2 #include <teo.h> /* T E O */ 3 4 int 5 main ( int argc, 6 char **argv) { 7 TEOFILE * src_ teofp, * dst_ teofp; 8 TEOIMAGE * src_img, * dst_ img; 9 int x, y, p; 10 TEO_ UINT8 val;
3.2 libteo 17 11 12 /* */ 13 src_ teofp = TeoOpenFile ( argv[ 1]); 14 15 /* */ 16 dst_ teofp = TeoCreateSimilarFile ( argv[2], src_ teofp); 17 18 /* */ 19 src_ img = TeoAllocSimilarImage ( src_ teofp); 20 dst_ img = TeoAllocSimilarImage ( dst_ teofp); 21 22 /* */ 23 TeoReadFrame ( src_ teofp, src_ img); 24 25 /* */ 26 for ( y = TeoYstart ( src_ img); y <= TeoYend ( src_ img); y++) { 27 for ( x = TeoYstart ( src_ img); x <= TeoYend ( src_ img); x++) { 28 for ( p = 0; p < TeoPlane ( src_ img); p++) { 29 /* */ 30 val = TeoGetPixel ( src_img, x, y, p, TEO_ UINT8); 31 /* */ 32 TeoPutPixel ( dst_img, x, y, p, TEO_ UINT8, val); 33 } 34 } 35 } 36 /* */ 37 TeoWriteFrame ( dst_ teofp, dst_ img); 38 39 /* */ 40 TeoCloseFile ( src_ teofp); 41 TeoCloseFile ( dst_ teofp); 42 43 /* */ 44 TeoFreeImage ( src_ img); 45 TeoFreeImage ( dst_ img); 46 47 return 0; 48 } 3.2 libteo libteo. 3.2.1 TEOFILE TEOFILE TEO.,. TEOFILE., TEOFILE,
18 3 TEO TEOIMAGE. TEOFILE 3.2. libteo TEOFILE ( ). 3.2 TEOFILE typedef struct { int width; /* */ int height; /* */ int xoffset; /* X */ int yoffset; /* Y */ int type; /* */ int bit; /* */ int plane; /* */ int frame; /* */ int current; /* */ int extc; /* */ char **extv; /* */ int fsize; /* 1 */ int hsize; /* */ FILE *fp; /* */ int ac_type; /* */ char *filename; /* */ char *tmpfile; /* */ } TEOFILE; 3.2.2 TEOIMAGE TEOIMAGE 3.3. TEOIMAGE TEO. TEO, TEOFILE, 1 TEOIMAGE 2. TeoData.,.,. 3.3 TEOIMAGE typedef struct { int width; /* */ int height; /* */ int xoffset; /* X */ int yoffset; /* Y */ int type; /* */ int bit; /* */ int plane; /* */ char *data; /* */ int fsize; /* 1 */ } TEOIMAGE;
3.3 19 3.2.3 libteo,., libteo.,. TEO BIT... 0, 1 2 TEO UINT8... 8bit TEO SINT8... 8bit TEO UINT16... 16bit TEO SINT16... 16bit TEO UINT32... 32bit TEO SINT32... 32bit TEO FLOAT32... 32bit TEO FLOAT64... 64bit,. TeoCreateFile TeoAllocImage. TEO UNSIGNED... TEO SIGNED... TEO FLOAT... 3.3 libteo., TEO,. TEO GZIP TEO. yes, no (). % setenv TEO GZIP yes TEO GZIP COMMAND., (/usr/bin/gzip ). % setenv TEO GZIP COMMAND "/usr/bin/gzip -c" TEO GUNZIP COMMAND TEO. (/usr/bin/gzip
20 3 TEO ). % setenv TEO GUNZIP COMMAND "/bin/zcat" TEO TMP DIR., /tmp. % setenv TEO TMP DIR "$HOME/tmp",.login. 3.1.login. 3.1.login 3.4 libteo 1.1. 3. 1 TeoGetPixel, TeoPutPixel, TeoGetPixel, TeoPutPixel TEOIMAGE NULL TeoAllocImage TeoGetPixel, TeoPutPixel, TeoGetBit, TeoPutBit 2 TeoCloseFile (TeoWriteFrame ) TeoAllocImage (100MB ) TeoOpenFile, TeoCreateFile *.teo 3
3.5 21,. -DTEO DEBUG1 -DTEO DEBUG2 -DTEO DEBUG3 -DTEO DEBUG ALL 1, 2, 3. -DTEO DEBUG ALL. -DTEO DEBUG3. -DTEO DEBUG ERROR,.,,. 3.5 libteo.,., 3.1,. 3.4.. 1.., argc, USAGE. 2., TeoOpenFile NULL.. 3. TEO UINT8 8., TeoIsUINT8. 4., TeoCreate{Similar}File NULL.. 5. TeoAlloc{Similar}Image, NULL.. 6. 4..
22 3 TEO 56, TeoXstart, TeoYstart, TeoXend, TeoYend, (x, y).,,., libteo, *1. TEO ERROR CODE. TEO ERROR MESSAGE. TEO ERROR MESSAGE, 3.4 4 extern. 3.4 teo TEO ERROR MESSAGE. 3.4 copy2,,. %./copy2 nofile.teo output.teo Read error! Can t open file nofile.teo. (error code:1) 3.4 () 1 # include <stdio. h> 2 #include <teo.h> /* T E O */ 3 4 extern char TEO_ ERROR_ MESSAGE[]; 5 6 int 7 main ( int argc, 8 char **argv) { 9 TEOFILE * src_ teofp, * dst_ teofp; 10 TEOIMAGE * src_img, * dst_ img; 11 int x, y, p; 12 TEO_ UINT8 val; 13 14 /* */ 15 if (argc!= 3) { 16 fprintf (stderr, "Usage: %s in.teo out.teo\n", argv[0]); 17 exit (1); *1 teo.h. teo.h. TEO ERROR MESSAGE.
3.5 23 18 } 19 /* */ 20 src_ teofp = TeoOpenFile ( argv[ 1]); 21 if (! src_ teofp) { 22 fprintf ( stderr, 23 "%s (error code:%d)\n", TEO_ERROR_MESSAGE, TEO_ERROR_CODE); 24 goto settle; 25 } 26 /* */ 27 if (! TeoISUINT8( src_ teofp)) { 28 fprintf ( stderr, 29 " Pixel type UINT8 is only supported in this program.\ n"); 30 goto settlel 31 } 32 /* */ 33 dst_ teofp = TeoCreateSimilarFile ( argv[2], src_ teofp); 34 if (! dst_ teofp) { 35 fprintf ( stderr, 36 "%s (error code:%d)\n", TEO_ERROR_MESSAGE, TEO_ERROR_CODE); 37 goto settle; 38 } 39 /* */ 40 src_ img = TeoAllocSimilarImage ( src_ teofp); 41 if (!src_img) { 42 fprintf ( stderr, 43 "%s (error code:%d)\n", TEO_ERROR_MESSAGE, TEO_ERROR_CODE); 44 goto settle; 45 } 46 dst_ img = TeoAllocSimilarImage ( dst_ teofp); 47 if (!dst_img) { 48 fprintf ( stderr, 49 "%s (error code:%d)\n", TEO_ERROR_MESSAGE, TEO_ERROR_CODE); 50 goto settle; 51 } 52 /* */ 53 TeoReadFrame ( src_ teofp, src_ img); 54 55 /* */ 56 for ( y = TeoYstart ( src_ img); y <= TeoYend ( src_ img); y++) { 57 for ( x = TeoYstart ( src_ img); x <= TeoYend ( src_ img); x++) { 58 for ( p = 0; p < TeoPlane ( src_ img); p++) { 59 /* */ 60 val = TeoGetPixel ( src_img, x, y, p, TEO_ UINT8); 61 /* */ 62 TeoPutPixel ( dst_img, x, y, p, TEO_ UINT8, val); 63 } 64 } 65 } 66 /* */ 67 TeoWriteFrame ( dst_ teofp, dst_ img);
24 3 TEO 68 69 settle: 70 /* */ 71 if ( src_ teofp) TeoCloseFile ( src_ teofp); 72 if ( dst_ teofp) TeoCloseFile ( dst_ teofp); 73 74 /* */ 75 if ( src_ img) TeoFreeImage ( src_ img); 76 if ( dst_ img) TeoFreeImage ( dst_ img); 77 78 return 0; 79 } 3.6, gcc. make. make Makefile. Makefile, make., Makefile, Makefile, libteo. 3.5 Makefile., 3 libteo TEODIR., 4 CFLAGS libteo (teo.h), 5 LDFLAGS. LIBS, libteo -lteo., copy.c, teo copy, SRCS, PROGRAM,. libteo, make. 3.5 Makefile 1 CC = gcc 2 INSTALL = / usr/ bin/ install 3 TEODIR = / usr/ local 4 CFLAGS = -O2 -I$( TEODIR)/ include -Wall -DTEO_ DEBUG_ ALL 5 LDFLAGS = -L$( TEODIR)/ lib 6 LIBS = -lteo -lm 7 DEST = $( HOME)/ bin 8 SRCS = copy. c 9 OBJS = $(SRCS:.c=.o) 10 PROGRAM = teo_ copy 11 all: $( PROGRAM) 12 $( PROGRAM): $( OBJS) 13 $( CC) $( OBJS) $( LDFLAGS) $( LIBS) -o $( PROGRAM) 14 clean:; rm -f *. o * ~ $( PROGRAM)
3.6 25 15 install: $( PROGRAM) 16 $( INSTALL) -s $( PROGRAM) $( DEST) 17 strip $( DEST)/ $( PROGRAM)
27 4 TEO -, TEO,.,. 1. RGB. 2. (RGB YCrCb ).,., RGB YCrCb. 3. ( 2 ) 2, 1 TEO. 4. () 1.. 4.1 RGB,. RGB. gray = 0.299 R + 0.587 G + 0.114 B (4.1) R, G, B RGB. (4.1) RGB 0 255
28 4 TEO -.. RGB, TEO UINT8 3., TEO UINT8 1.,.,. teo rgb2gray. teo rgb2gray : RGB TEO ( :TEO UINT8, : ) : TEO ( :TEO UINT8, :1) : RGB, 1 TEO. 4.1.,...,. ( ).,.,. 50. RGB,. 3 TEO UINT8 func rgb2gray, TEOIMAGE, TEOIM- AGE..,.. (13 19 ).,,, 1. (21 29 ).. RGB (23 25 ) 1, 2, 3 ( 1 0
4.1 29 ), TeoGetPixel, TEOIMAGE (x, y). (26 ) (4.1) RGB, gray.,, TEO UINT8. (27 ) gray TeoPutPixel, (x, y) 1. 4.1 RGB. 4.1 RGB 1 # include <stdio. h> 2 #include <teo.h> /* T E O */ 3 4 static TEOIMAGE* func_ rgb2gray ( TEOIMAGE * src); 5 6 static TEOIMAGE* 7 func_ rgb2gray ( TEOIMAGE * src) { 8 TEOIMAGE * dst; 9 int row, col; 10 TEO_ UINT8 r, g, b, gray; 11 12 /* */ 13 dst = TeoAllocImage ( TeoWidth ( src), 14 TeoHeight ( src), 15 TeoXoffset ( src), 16 TeoYoffset ( src), 17 TeoType (src), 18 TeoBit (src), 19 1); 20 /* */ 21 for ( row = TeoYstart ( src); row <= TeoYend ( src); row++) { 22 for ( col = TeoXstart ( src); col <= TeoXend ( src); col++) { 23 r = TeoGetPixel ( src, col, row, 0, TEO_ UINT8); 24 g = TeoGetPixel ( src, col, row, 1, TEO_ UINT8); 25 b = TeoGetPixel ( src, col, row, 2, TEO_ UINT8); 26 gray = ( TEO_ UINT8) ( 0. 299 * r + 0. 587 * g + 0. 114 * b); 27 TeoPutPixel ( dst, col,row, 0, TEO_ UINT8, gray); 28 } 29 } 30 return dst; 31 } 32 33 int 34 main ( int argc, 35 char **argv) { 36 TEOFILE * src_ teofp = NULL, * dst_ teofp = NULL; 37 TEOIMAGE * src_ img = NULL, * dst_ img = NULL; 38
30 4 TEO - 39 /* */ 40 if (argc!= 2) { 41 fprintf (stderr, "Usage: %s in.teo\n", argv[0]); 42 exit (1); 43 } 44 /* */ 45 src_teofp = TeoOpenFile (argv[1]); /* T E O */ 46 src_img = TeoAllocSimilarImage (src_teofp);/* */ 47 TeoReadFrame (src_teofp, src_img); /* */ 48 49 /* */ 50 if ( TeoPlane ( src_ img) < 3! TeoIsUINT8 ( src_ img)) { 51 fprintf ( stderr, " Wrong image type!\ n"); 52 goto settle; 53 } 54 /* */ 55 dst_ teofp = TeoCreateFile (" -", 56 TeoWidth ( src_ img), 57 TeoHeight ( src_ img), 58 TeoXoffset ( src_ img), 59 TeoYoffset ( src_ img), 60 TeoType ( src_ img), 61 TeoBit ( src_ img), 62 1, 63 1); 64 /* */ 65 dst_ img = func_ rgb2gray ( src_ img); 66 67 /* */ 68 TeoWriteFrame ( dst_ teofp, dst_ img); 69 settle: 70 /* */ 71 if ( src_ teofp) TeoCloseFile ( src_ teofp); 72 if ( dst_ teofp) TeoCloseFile ( dst_ teofp); 73 74 /* */ 75 if ( src_ img) TeoFreeImage ( src_ img); 76 if ( dst_ img) TeoFreeImage ( dst_ img); 77 78 return 0; 79 }
4.2 - RGB YCrCb - 31 (a) (b) 4.1 RGB 4.2 - RGB YCrCb -. RGB YCrCb. YCrCb, Y() Cr, Cb( ). Y, Cr, Cb. NTSC YCrCb. RGB YCrCb. Y = 0.2989 R + 0.5866 G + 0.1145 B Cr = 0.5000 R 0.4183 G 0.0816 B Cb = 0.1687 R 0.3312 G + 0.5000 B (4.2) (4.2), YCrCb TEO UINT8., YCrCb TEO FLOAT64.. teo rgb2yc. 4.2 RGB YCrCb. teo rgb2yc : RGB TEO ( :TEO UINT8, :3) : YCrCbTEO ( :TEO FLOAT64, :3) : RGB YCrCb, YCrCb TEO FLOAT64 3 TEO. 4.2..,., 62. TEO UINT8 TEO FLOAT64, 1 3.
32 4 TEO -. (11 ) Y, Cr, Cb TEO FLOAT64. (14 20 ).,, TEO FLOAT64, 3. (22 23 ).. RGB (24 26 ) 1, 2, 3 ( 1 0 ), TeoGetPixel, TEOIMAGE (x, y). YCrCb (28 30 ) (4.2) RGB YCrCb,. (32 34 ) YCrCb TeoPutPixel (x, y)., TEO FLOAT64, TeoPutPixel TEO FLOAT64. 4.2 RGB YCrCb 1 # include <stdio. h> 2 #include <teo.h> /* T E O */ 3 4 static TEOIMAGE* func_ rgb2yc ( TEOIMAGE * src); 5 6 static TEOIMAGE* 7 func_ rgb2yc ( TEOIMAGE * src) { 8 TEOIMAGE * dst; 9 int row, col; 10 TEO_ UINT8 r, g, b; 11 TEO_ FLOAT64 Y, Cr, Cb; 12 13 /* Y C r C b */ 14 dst = TeoAllocImage ( TeoWidth ( src), 15 TeoHeight ( src), 16 TeoXoffset ( src), 17 TeoYoffset ( src), 18 TEO_ FLOAT, 19 64, 20 3); 21 /* Y C r C b */ 22 for ( row = TeoYstart ( src); row <= TeoYend ( src); row++) { 23 for ( col = TeoXstart ( src); col <= TeoXend ( src); col++) { 24 r = TeoGetPixel ( src, col, row, 0, TEO_ UINT8); 25 g = TeoGetPixel ( src, col, row, 1, TEO_ UINT8); 26 b = TeoGetPixel ( src, col, row, 2, TEO_ UINT8); 27
4.2 - RGB YCrCb - 33 28 Y = 0. 2989 * r + 0. 5866 * g + 0. 1145 * b; 29 Cr = 0. 5000 * r - 0. 4183 * g - 0. 0816 * b; 30 Cb = - 0. 1687 * r - 0. 3312 * g + 0. 5000 * b; 31 32 TeoPutPixel ( dst, col, row, 0, TEO_ FLOAT64, Y); 33 TeoPutPixel ( dst, col, row, 1, TEO_ FLOAT64, Cr); 34 TeoPutPixel ( dst, col, row, 2, TEO_ FLOAT64, Cb); 35 } 36 } 37 return dst; 38 } 39 40 int 41 main ( int argc, 42 char **argv) { 43 TEOFILE * src_ teofp, * dst_ teofp; 44 TEOIMAGE * src_img, * dst_ img; 45 46 /* */ 47 if (argc!= 2) { 48 fprintf (stderr, "Usage: %s in.teo\n", argv[0]); 49 exit (1); 50 } 51 /* */ 52 src_teofp = TeoOpenFile (argv[1]); /* T E O */ 53 src_img = TeoAllocSimilarImage (src_teofp);/* */ 54 TeoReadFrame (src_teofp, src_img); /* */ 55 56 /* */ 57 if ( TeoPlane ( src_ img) < 3! TeoIsUINT8 ( src_ img)) { 58 fprintf ( stderr, " Wrong image type!\ n"); 59 goto settle; 60 } 61 /* */ 62 dst_ teofp = TeoCreateFile (" -", 63 TeoWidth ( src_ img), 64 TeoHeight ( src_ img), 65 TeoXoffset ( src_ img), 66 TeoYoffset ( src_ img), 67 TEO_ FLOAT, 68 64, 69 3, 70 1); 71 /* */ 72 dst_ img = func_ rgb2yc ( src_ img); 73 74 /* */ 75 TeoWriteFrame ( dst_ teofp, dst_ img); 76 settle: 77 /* */
34 4 TEO - 78 if ( src_ teofp) TeoCloseFile ( src_ teofp); 79 if ( dst_ teofp) TeoCloseFile ( dst_ teofp); 80 81 /* */ 82 if ( src_ img) TeoFreeImage ( src_ img); 83 if ( dst_ img) TeoFreeImage ( dst_ img); 84 85 return 0; 86 } (a) (b) YCrCb (c) Y (d) Cr (e) Cb 4.2 RGB YCrCb
4.3 - - 35 4.3 - -. 1, 1 1,. 2. 2 1, 1 2,. 2. 0, 1. 2., RGB, 2. 4.3 2 teo binary. 4.3 teo binary,. teo binary 1 2 : RGB TEO, TEO : : ( :TEO UINT8, :1) :,.,.,. B n = 0 A YES!#"$%&? NO *+, " -. n < '0/? YES NO n '(!#"$ ) n 12 n 3 n + 1 B A 4.3 2
36 4 TEO - 70 79. (70 ) for. n (71 ) n. (72 74 ), 1 (RGB ),. (75 ) dst img 2. dst img. n (78 ) 2. TeoReadFrame TeoWriteFrame,.,,. func rgb2gray RGB. TEOIMAGE,,.. func binary 2., 255, 0. 2 2. 4.4 2, 4.5 2. 2 128. 4.4 2 () :, :2
4.3 - - 37 4.5 2 ( ) :, :2 4.3 2 1 # include <stdio. h> 2 #include <teo.h> /* T E O */ 3 4 static void func_ rgb2gray ( TEOIMAGE * src, 5 TEOIMAGE *dst); 6 static void func_ binary ( TEOIMAGE * src, 7 TEO_ UINT8 threshold); 8 9 static void 10 func_ rgb2gray ( TEOIMAGE * src, 11 TEOIMAGE * dst) { 12 int row, col; 13 TEO_ UINT8 r, g, b, gray; 14 15 for ( row = TeoYstart ( src); row <= TeoYend ( src); row++) { 16 for ( col = TeoXstart ( src); col <= TeoXend ( src); col++) { 17 r = TeoGetPixel ( src, col, row, 0, TEO_ UINT8); 18 g = TeoGetPixel ( src, col, row, 1, TEO_ UINT8); 19 b = TeoGetPixel ( src, col, row, 2, TEO_ UINT8); 20 gray = ( TEO_ UINT8) ( 0. 299 * r + 0. 587 * g + 0. 114 * b); 21 TeoPutPixel ( dst, col,row, 0, TEO_ UINT8, gray); 22 } 23 } 24 } 25 26 static void 27 func_ binary ( TEOIMAGE * src, 28 TEO_ UINT8 threshold) { 29 int row, col; 30 TEO_ UINT8 val; 31 32 for ( row = TeoYstart ( src); row <= TeoYend ( src); row++) { 33 for ( col = TeoXstart ( src); col <= TeoXend ( src); col++) { 34 val = TeoGetPixel ( src, col, row, 0, TEO_ UINT8);
38 4 TEO - 35 val = ( val > threshold)? 255 : 0; 36 TeoPutPixel ( src, col, row, 0, TEO_ UINT8, val); 37 } 38 } 39 } 40 41 int 42 main ( int argc, 43 char **argv) { 44 TEOFILE * src_ teofp, * dst_ teofp; 45 TEOIMAGE * src_img, * dst_ img; 46 TEO_ UINT8 threshold; 47 int n; 48 49 /* */ 50 if (argc!= 3) { 51 fprintf (stderr, "Usage: %s in.teo #threshold\n", argv[0]); 52 exit (1); 53 } 54 /* */ 55 src_teofp = TeoOpenFile (argv[1]); /* T E O */ 56 src_img = TeoAllocSimilarImage (src_teofp);/* */ 57 58 /* 2 */ 59 threshold = ( TEO_ UINT8) atoi ( argv[ 2]); 60 61 /* */ 62 dst_ teofp = TeoCreateFile (" -", 63 TeoWidth ( src_ img), TeoHeight ( src_ img), 64 TeoXoffset ( src_ img), TeoYoffset ( src_ img), 65 TEO_UNSIGNED, 8, 1, TeoFrame (src_teofp)); 66 /* */ 67 dst_ img = TeoAllocSimilarImage ( dst_ teofp); 68 69 /* - */ 70 for ( n = 0; n < TeoFrame ( src_ teofp); n++) { 71 TeoReadFrame ( src_ teofp, src_ img); 72 if (TeoPlane (src_img) == 1) { /* R G B */ 73 func_ rgb2gray ( src_img, dst_ img); 74 } 75 func_binary (dst_img, threshold); /* 2 */ 76 77 /* */ 78 TeoWriteFrame ( dst_ teofp, dst_ img); 79 } 80 /* */ 81 if ( src_ teofp) TeoCloseFile ( src_ teofp); 82 if ( dst_ teofp) TeoCloseFile ( dst_ teofp); 83 84 /* */
4.4 - - 39 85 if ( src_ img) TeoFreeImage ( src_ img); 86 if ( dst_ img) TeoFreeImage ( dst_ img); 87 88 return 0; 89 } 4.4 - -.,... ( 4.6)., ( ) ( 4.6)., 1.,, ( 4.6)..,., [ ][].teo., image00.teo, image01.teo,, image09.teo, image%02d.teo, n = 0,, 9.. 4.4 4.6
40 4 TEO - int n; char name[ 1024]; for ( n = 0; n < 10; n++) { sprintf (name, "image%02d.teo", n); printf ("%s\n", name); } teo detect motion 1 2 3 : : : : :. 1,.,. 4.5. (67 70 ),, 3. (72 ). (75 82 ).., (84 90 ),., -1 (92 94 ) func sub image,. (96 106 ).,. (108 112 ). func sub image. threshold 1, 0. threshold = 8. func detect motion, 1,. ( 255). 4.7..
4.4 - - 41 4.7 :, : 4.5 1 # include <stdio. h> 2 #include <teo.h> /* T E O */ 3 4 static void func_ and_ image ( TEOIMAGE * src1, 5 TEOIMAGE * src2, 6 TEOIMAGE * color, 7 TEOIMAGE *dst); 8 static void func_ sub_ image ( TEOIMAGE * src1, 9 TEOIMAGE * src2, 10 TEOIMAGE * dst); 11 12 static void 13 func_ and_ image ( TEOIMAGE * src1, 14 TEOIMAGE * src2, 15 TEOIMAGE * color, 16 TEOIMAGE * dst) { 17 TEO_ UINT8 val1, val2; 18 int row, col, p; 19 20 for ( row = TeoYstart ( src1); row <= TeoYend ( src1); row++) { 21 for ( col = TeoXstart ( src1); col <= TeoXend ( src1); col++) { 22 val1 = TeoGetPixel ( src1, col, row, 0, TEO_ UINT8); 23 val2 = TeoGetPixel ( src2, col, row, 0, TEO_ UINT8); 24 if (val1 && val2) { 25 for ( p = 0; p < TeoPlane ( color); p++) { 26 TeoPutPixel ( dst, col,row, p, TEO_ UINT8, 27 TeoGetPixel ( color, col, row, p, TEO_ UINT8)); 28 } 29 } else {
42 4 TEO - 30 for ( p = 0; p < TeoPlane ( color); p++) { 31 TeoPutPixel ( dst, col,row, p, TEO_ UINT8, 255); 32 } 33 } 34 } 35 } 36 } 37 38 static void 39 func_ sub_ image ( TEOIMAGE * src1, 40 TEOIMAGE * src2, 41 TEOIMAGE * dst) { 42 TEO_ UINT8 val1, val2, threshold = 8; 43 int row, col; 44 45 for ( row = TeoYstart ( src1); row <= TeoYend ( src1); row++) { 46 for ( col = TeoXstart ( src1); col <= TeoXend ( src1); col++) { 47 val1 = TeoGetPixel ( src1, col, row, 0, TEO_ UINT8); 48 val2 = TeoGetPixel ( src2, col, row, 0, TEO_ UINT8); 49 if ( abs ( val1 - val2) > threshold) { 50 TeoPutPixel ( dst, col,row, 0, TEO_ UINT8, 1); 51 } else { 52 TeoPutPixel ( dst, col,row, 0, TEO_ UINT8, 0); 53 } 54 } 55 } 56 } 57 58 int 59 main ( int argc, 60 char **argv) { 61 TEOFILE * src_ teofp, * dst_ teofp; 62 TEOIMAGE **src_img, **sub_img, *dst_img; 63 int n, frame; 64 char name[ 1024]; 65 66 /* */ 67 if (argc!= 4) { 68 fprintf ( stderr, " Usage: % s in_ header # frame out_ header\ n", argv[ 0]); 69 exit (1); 70 } 71 /* */ 72 frame = atoi ( argv[ 2]); 73 74 /* */ 75 src_ img = ( TEOIMAGE **) malloc ( sizeof ( TEOIMAGE *) * frame); 76 for ( n = 0; n < frame; n++) { 77 sprintf ( name, argv[1], n); 78 src_ teofp = TeoOpenFile ( name); 79 src_ img[ n] = TeoAllocSimilarImage ( src_ teofp);
4.4 - - 43 80 TeoReadFrame ( src_ teofp, src_ img[ n]); 81 TeoCloseFile ( src_ teofp); 82 } 83 /* */ 84 dst_ img = TeoAllocSimilarImage ( src_ img[ 0]); 85 86 /* */ 87 sub_img = (TEOIMAGE **) malloc (sizeof (TEOIMAGE *) * (frame - 1)); 88 for ( n = 0; n < frame - 1; n++) { 89 sub_ img[ n] = TeoAllocSimilarImage ( src_ img[ n]); 90 } 91 /* */ 92 for ( n = 0; n < frame - 1; n++) { 93 func_sub_image (src_img[n+1], src_img[n], sub_img[n]); 94 } 95 /* A N D */ 96 for ( n = 1; n < frame - 1; n++) { 97 func_and_image (sub_img[n-1], sub_img[n], src_img[n], dst_img); 98 sprintf ( name, argv[3], n); 99 dst_ teofp = TeoCreateFile ( name, 100 TeoWidth ( dst_ img), TeoHeight ( dst_ img), 101 TeoXoffset ( dst_ img), TeoYoffset ( dst_ img), 102 TeoType ( dst_ img), TeoBit ( dst_ img), 103 TeoPlane ( dst_ img), 1); 104 TeoWriteFrame ( dst_ teofp, dst_ img); 105 TeoCloseFile ( dst_ teofp); 106 } 107 /* */ 108 for ( n = 0; n < frame; n++) TeoFreeImage ( src_ img[ n]); 109 for ( n = 0; n < frame - 1; n++) TeoFreeImage ( sub_ img[ n]); 110 free ( src_ img); 111 free ( sub_ img); 112 TeoFreeImage ( dst_ img); 113 114 return 0; 115 }
45 5 TEO - TEO.,,.,.,,.,.. 1. 2. 3. 4. 5. 5.1 2 2 5.1 B A, C f x (B A), f x (C B) I(x, y) (x, y) f x (B A) = I(x, y) I(x 1, y) (5.1) f x (C B) = I(x + 1, y) I(x, y) (5.2)
46 5 TEO - A B C f ( B - A ) x f ( C - B ) x f ( C - B ) - f ( B - A ) x x 5.1 2 B 2 1 ( (5.3)) f xx (x, y) = f x (B A) f x (C B) = I(x 1, y) + I(x + 1, y) 2I(x, y) (5.3) B 2 2 f(x, y) = I(x 1, y) + I(x + 1, y) + I(x, y 1) + I(x, y + 1) 4I(x, y) (5.4) 5.2(a) 5.2(b) 5.1 5.2(b) 8 3 3 1 1 1 1 1 1-4 1 1-8 1 1 1 1 1 5.2 (a) (a) 4 (b) 8 (b)
5.1 47 5.1 8 1 # include <stdio. h> 2 #include <teo.h> /* T E O */ 3 4 static TEOIMAGE* func_ laplacian ( TEOIMAGE * src); 5 6 static TEOIMAGE* func_ laplacian ( TEOIMAGE * src) { 7 TEOIMAGE * dst; 8 TEO_ FLOAT64 sum; 9 int row, col; 10 11 dst = TeoAllocImage ( TeoWidth ( src), TeoHeight ( src), 12 TeoXoffset ( src), TeoYoffset ( src), 13 TEO_FLOAT, 64, 1); 14 15 for ( row = TeoYstart ( src) + 1; row <= TeoYend ( src) - 1; row++) { 16 for ( col = TeoXstart ( src) + 1; col <= TeoXend ( src) - 1; col++) { 17 sum = ( TEO_ FLOAT64) TeoGetPixel ( src, col -1, row -1, 0, TEO_ UINT8); 18 sum += ( TEO_ FLOAT64) TeoGetPixel ( src, col, row -1, 0, TEO_ UINT8); 19 sum += ( TEO_ FLOAT64) TeoGetPixel ( src, col+1, row -1, 0, TEO_ UINT8); 20 sum += ( TEO_ FLOAT64) TeoGetPixel ( src, col -1, row, 0, TEO_ UINT8); 21 sum += ( TEO_ FLOAT64) TeoGetPixel ( src, col+1, row, 0, TEO_ UINT8); 22 sum += ( TEO_ FLOAT64) TeoGetPixel ( src, col -1, row+1, 0, TEO_ UINT8); 23 sum += ( TEO_ FLOAT64) TeoGetPixel ( src, col, row+1, 0, TEO_ UINT8); 24 sum += ( TEO_ FLOAT64) TeoGetPixel ( src, col+1, row+1, 0, TEO_ UINT8); 25 sum -= ( TEO_ FLOAT64) TeoGetPixel ( src, col, row, 0, TEO_ UINT8)* 8; 26 TeoPutPixel ( dst, col,row, 0, TEO_ FLOAT64, sum); 27 } 28 } 29 return dst; 30 } 31 32 int main ( int argc, char ** argv) { 33 TEOFILE * src_ teofp, * dst_ teofp; 34 TEOIMAGE * srcimg, * dstimg; 35 36 /* */ 37 if (argc!= 2) { 38 fprintf (stderr, "Usage: %s in.teo\n", argv[0]); 39 exit (1); 40 } 41 /* */ 42 src_teofp = TeoOpenFile (argv[1]); /* T E O */ 43 srcimg = TeoAllocSimilarImage (src_teofp);/* */ 44 TeoReadFrame (src_teofp, srcimg); /* */ 45 46 /* */ 47 if ( TeoPlane ( src_ teofp) < 3! TeoIsUINT8 ( src_ teofp)) { 48 fprintf ( stderr, " This image trowpe is not supported.\ n"); 49 TeoCloseFile ( src_ teofp);
48 5 TEO - 50 TeoFreeImage ( srcimg); 51 exit (1); 52 } 53 /* */ 54 dst_ teofp = TeoCreateFile (" -", 55 TeoWidth ( src_ teofp), 56 TeoHeight ( src_ teofp), 57 TeoXoffset( src_ teofp), 58 TeoYoffset( src_ teofp), 59 TEO_FLOAT, 64, 1, 1); 60 61 /* */ 62 dstimg = func_ laplacian ( srcimg); 63 64 /* */ 65 TeoWriteFrame ( dst_ teofp, dstimg); 66 67 /* */ 68 TeoCloseFile ( src_ teofp); 69 TeoCloseFile ( dst_ teofp); 70 71 /* */ 72 TeoFreeImage ( srcimg); 73 TeoFreeImage ( dstimg); 74 75 return 0; 76 } 5.2 5.3 2 w(x, y) = e (x2 +y 2 )/2σ 2 σ (5.5) I (x, y) = 1 σ σ w(k, l) I(x + k, y + l) (5.5) C k= σ l= σ C
5.2 49 1 1 0.5 0.5 0 0-3 -2-1 0 1 2 3-3 -2-1 0 1 2 3-4 -2 0 2 4-4 -2 0 2 4 (a) (b) 5.3 2 w(x, y) = e (x2 +y 2 )/2σ 2 (a) σ = 1 (b) σ = 2 σ σ C = w(k, l) (5.6) k= σ l= σ 5.2 exp math.h math.h -lm. 5.4 5.2 1 # include <stdio. h> 2 # include <stdlib. h> 3 # include <math. h> 4 # include <teo. h> 5 6 static TEOIMAGE* func_ gaussian ( TEOIMAGE * src, int sigma); 7 (a) (b) (c) 5.4 (a) (b) (c)
50 5 TEO - 8 static TEOIMAGE* func_ gaussian ( TEOIMAGE * src, int sigma) { 9 TEOIMAGE * dst; 10 double ** gauss; 11 double sum = 0. 0; 12 int kernel_ size, x, y, row, col, p; 13 14 /* */ 15 dst = TeoAllocImage ( TeoWidth ( src), TeoHeight ( src), 16 TeoXoffset ( src), TeoYoffset ( src), 17 TEO_ UNSIGNED, 8, TeoPlane ( src)); 18 19 /* */ 20 kernel_ size = sigma * 2 + 1; 21 gauss = ( double **) malloc ( sizeof ( double *) * kernel_ size) + sigma; 22 for ( y = -sigma; y <= sigma; y++) { 23 gauss[ y] = ( double *) malloc ( sizeof ( double) * kernel_ size) + sigma; 24 for ( x = -sigma; x <= sigma; x++) { 25 gauss[ y][ x] = exp ( -(x * x + y * y) / ( 2. 0 * sigma * sigma)); 26 sum += gauss[y][x]; 27 } 28 } 29 /* 1 */ 30 for ( y = -sigma; y <= sigma; y++) { 31 for ( x = -sigma; x <= sigma; x++) { 32 gauss[y][x] /= sum; 33 } 34 } 35 /* */ 36 for ( row = TeoYstart( src) +sigma; row <= TeoYend( src) -sigma; row++) { 37 for ( col = TeoXstart( src) +sigma; col <= TeoXend( src) -sigma; col++) { 38 for ( p = 0; p < TeoPlane ( src); p++) { 39 sum = 0. 0; 40 for ( y = -sigma; y <= sigma; y++) { 41 for ( x = -sigma; x <= sigma; x++) { 42 sum += gauss[ y][ x] * TeoGetPixel ( src, 43 col+x, row+y, p, TEO_ UINT8); 44 } 45 } 46 TeoPutPixel ( dst, col, row, p, TEO_ UINT8, ( TEO_ UINT8) sum); 47 } 48 } 49 } 50 /* */ 51 for ( y = -sigma; y <= sigma; y++) { 52 gauss[ y] -= sigma; 53 free (gauss[y]); 54 } 55 gauss -= sigma; 56 free (gauss); 57
5.2 51 58 return dst; 59 } 60 61 int main ( int argc, char * argv) { 62 TEOFILE * src_ teofp, * dst_ teofp; 63 TEOIMAGE * srcimg, * dstimg; 64 int sigma; 65 66 /* */ 67 if (argc!= 3) { 68 fprintf (stderr, "Usage: %s in.teo #sigma\n", argv[0]); 69 exit (1); 70 } 71 /* */ 72 src_teofp = TeoOpenFile (argv[1]); /* T E O */ 73 srcimg = TeoAllocSimilarImage (src_teofp);/* */ 74 TeoReadFrame (src_teofp, srcimg); /* */ 75 76 /* */ 77 if ( TeoPlane ( src_ teofp) < 3! TeoIsUINT8 ( src_ teofp)) { 78 fprintf ( stderr, " This image trowpe is not supported.\ n"); 79 TeoCloseFile ( src_ teofp); 80 TeoFreeImage ( srcimg); 81 exit (1); 82 } 83 /* */ 84 dst_ teofp = TeoCreateFile (" -", 85 TeoWidth( src_ teofp), TeoHeight( src_ teofp), 86 TeoXoffset( src_ teofp), TeoYoffset( src_ teofp), 87 TEO_UNSIGNED, 8, 3, 1); 88 89 /* */ 90 sigma = atoi ( argv[ 2]); 91 92 /* */ 93 dstimg = func_ gaussian ( srcimg, sigma); 94 95 /* */ 96 TeoWriteFrame ( dst_ teofp, dstimg); 97 98 /* */ 99 TeoCloseFile ( src_ teofp); 100 TeoCloseFile ( dst_ teofp); 101 102 /* */ 103 TeoFreeImage ( srcimg); 104 TeoFreeImage ( dstimg); 105 106 return 0; 107 }
52 5 TEO - 5.3 2 2 (x, y) (x, y ) x = 2x (5.7) y = 2y (5.8) 5.5 (i, 0), i = 0,, N (2i, 0) (2i + 1, 0) x = x /2 (5.9) y = y /2 (5.10) 5.3 int 5.5
5.3 53 5.3 1 # include <stdio. h> 2 # include <stdlib. h> 3 # include <teo. h> 4 5 static TEOIMAGE* 6 TeoScaleImage ( TEOIMAGE * src, 7 TEOIMAGE * dst, 8 double xscale, 9 double yscale) { 10 int row, col, in_row, in_col, p; 11 12 for ( row = TeoYstart ( dst); row <= TeoYend ( dst); row++) { 13 for ( col = TeoXstart ( dst); col <= TeoXend ( dst); col++) { 14 in_ row = ( int) ( row / yscale); 15 in_ col = ( int) ( col / xscale); 16 for ( p = 0; p < TeoPlane ( dst); p++) { 17 TeoPutPixel ( dst, col, row, p, TEO_ UINT8, 18 TeoGetPixel ( src, in_col, in_row, p, TEO_ UINT8)); 19 } 20 } 21 } 22 } 23 24 int 25 main ( int argc, 26 char **argv) { 27 TEOFILE *src_teofp; /* T E O */ 28 TEOFILE *dst_teofp; /* T E O */ 29 TEOIMAGE *srcimg; /* T E O */ 30 TEOIMAGE *dstimg; /* T E O */ 31 double xscale, yscale; /* */ 32 33 /* */ 34 if (argc!= 4) { 35 fprintf (stderr, "Usage: %s in.teo #xscale #yscale\n", argv[0]); 36 exit (1); 37 } 38 39 /* */ 40 src_teofp = TeoOpenFile (argv[1]); /* T E O */ 41 srcimg = TeoAllocSimilarImage (src_teofp);/* */ 42 TeoReadFrame (src_teofp, srcimg); /* */ 43 44 /* */ 45 xscale = (double) atof (argv[2]); /* */ 46 yscale = (double) atof (argv[3]); /* */ 47 48 /* */ 49 dst_ teofp
54 5 TEO - 50 = TeoCreateFile (" -", /* */ 51 (int) (TeoWidth (srcimg) * xscale),/* */ 52 (int) (TeoHeight(srcimg) * yscale),/* */ 53 0, 0, /* */ 54 TEO_UNSIGNED, /* */ 55 8, /* B i t */ 56 3, /* */ 57 1); /* */ 58 dstimg = TeoAllocSimilarImage ( dst_ teofp); 59 60 /* */ 61 TeoScaleImage ( srcimg, dstimg, xscale, yscale); 62 63 /* */ 64 TeoWriteFrame ( dst_ teofp, dstimg); 65 66 /* */ 67 TeoCloseFile ( src_ teofp); 68 TeoCloseFile ( dst_ teofp); 69 70 /* */ 71 TeoFreeImage ( srcimg); 72 TeoFreeImage ( dstimg); 73 74 return 0; 75 } 5.4? 2 (1, 0) (0.5, 0) (0, 0) (1, 0) 1 5.6 (x, y), (x + 1, y) α : 1 α (x, y), (x, y + 1) β : 1 β (5.11) I(x + α, y + β) = (1 β) + β ( ) (1 α)i(x, y) + αi(x + 1, y) ( ) (5.11) (1 α)i(x, y + 1) + αi(x + 1, y + 1) (ˆx, ŷ) (5.11) x, y, α, β floor ˆx ( double)
5.4 55 ( x, y ) α 1 α ( x+1, y ) β 1 β ( x, y+1 ) ( x+1, y+1 5.6 ( 1 ) math.h floor int x = floor(ˆx) (5.12) y = floor(ŷ) (5.13) α = ˆx x (5.14) β = ŷ y (5.15) 5.4 TEO UINT8 5.5 5.7 5.4 1 static TEO_ UINT8 2 TeoGetLinearPixel ( TEOIMAGE * img, 3 double x, 4 double y, 5 int plane) { 6 TEO_ UINT8 pix[ 4]; 7 int ix, iy; 8 double a, b; 9 10 ix = ( int) x; 11 iy = ( int) y;
56 5 TEO - 12 a = x - ix; 13 b = y - iy; 14 15 pix[ 0] = TeoGetPixel ( img, ix, iy, plane, TEO_ UINT8); 16 pix[ 1] = TeoGetPixel ( img, 17 (ix >= TeoXend (img))? ix : ix + 1, 18 iy, 19 plane, TEO_ UINT8); 20 pix[ 2] = TeoGetPixel ( img, 21 ix, 22 (iy >= TeoYend (img))? iy : iy + 1, 23 plane, TEO_ UINT8); 24 pix[ 3] = TeoGetPixel ( img, 25 (ix >= TeoXend (img))? ix : ix + 1, 26 (iy >= TeoYend (img))? iy : iy + 1, 27 plane, TEO_ UINT8); 28 29 return ( TEO_ UINT8) (( 1. 0 - b) * ( 1. 0 - a) * pix[ 0] + 30 ( 1. 0 - b) * a * pix[ 1] + 31 b * (1.0 - a) * pix[2] + 32 b * a * pix[3]); 33 } 34 35 static void 36 TeoScaleImage2 ( TEOIMAGE * src, 37 TEOIMAGE * dst, 38 double xscale, 39 double yscale) { 40 int row, col, p; 41 double in_row, in_ col; 42 43 for ( row = TeoYstart ( dst); row <= TeoYend ( dst); row++) { 44 for ( col = TeoXstart ( dst); col <= TeoXend ( dst); col++) { 45 in_ row = ( double) row / yscale; 46 in_ col = ( double) col / xscale; 47 for ( p = 0; p < TeoPlane ( dst); p++) { 48 TeoPutPixel ( dst, col, row, p, TEO_ UINT8, 49 TeoGetLinearPixel ( src, in_col, in_row, p)); 50 } 51 } 52 } 53 }
5.4 57 5.5 1 # define TeoGetLinearPixel( image, index_x, index_y, index_p, ETYPE)\ 2 (((index_x) -((int) (index_x))) * \ 3 (((index_y) -((int) (index_y))) * \ 4 ( double) TeoGetPixel( image, \ 5 (((int) (index_x)) == (teo_xend(image)))? \ 6 ((int) (index_x)) : (((int) (index_x))+1), \ 7 (((int) (index_y)) == (teo_yend(image)))? \ 8 ((int) (index_y)) : (((int) (index_y))+1), \ 9 ( index_ p),etype) + \ 10 (1.0 -((index_y) -((int) (index_y)))) * \ 11 ( double) TeoGetPixel( image, \ 12 (((int) (index_x)) == (teo_xend(image)))? \ 13 ((int) (index_x)) : (((int) (index_x))+1), \ 14 ((int) (index_y)), \ 15 ( index_ p),etype)) + \ 16 (1.0 -((index_x) -((int) (index_x)))) * \ 17 (((index_y) -((int) (index_y))) * \ 18 ( double) TeoGetPixel( image, \ 19 ((int) (index_x)), \ 20 (((int) (index_y)) == (teo_yend(image)))? \ 21 ((int) (index_y)) : (((int) (index_y))+1), \ 22 ( index_ p),etype) + \ 23 (1.0 -((index_y) -((int) (index_y)))) * \ 24 ( double) TeoGetPixel( image, \ 25 ((int) (index_x)),((int) (index_y)), \ 26 (index_p),etype))) (a) (b) 5.7 (a) (b)
58 5 TEO - 5.5 () 2 2 (5.16) (5.17) 3 3 Z[ ] 3 1 ( 3 ) x = a 11x + a 12 y + a 13 a 31 x + a 32 y + a 33 y = a 21x + a 22 y + a 23 a 31 x + a 32 y + a 33 (5.16) x y 1 = Z[ a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33 x y 1 ] (5.17) 1 2 H 1. H 1 2 4 1 1 4 2 4 ( 5.8) 1 2 5.8
5.5 例題9 パノラマ画像の生成 59 この際 出力画像の左上の座標が (0, 0) でない場合も生じますが TEO 画像フォーマットではオフセッ ト機能により そのような場合も問題なく扱うことができるので便利です 2. 第 1 画像データを出力画像にコピーします 第 1 画像と出力画像の座標系は一致していますので 第 1 画像上の画素値を出力画像の同一座標に書き 込みます 3. 第 2 画像データを出力画像にコピーします a 出力画像の各点について 射影変換行列 H により第 2 画像での座標を計算します b このとき 計算された座標が第 2 画像の範囲外であれば何もしません c 計算された座標が第 2 画像の範囲内であれば 双 1 次補間によって出力画像の画素値を計算し 書 き込みます モザイク画像生成の例を図 5.9に示します (a) (b) (c) 図 5.9 モザイク画像の生成結果 (a) 入力画像 1 (b) 入力画像 2 (c) モザイク画像
61 6 1. 2. 3. 4. 5. 2 6.1,,.. 6.1.1 θ. (x, y), (x, y ), (). { x = x cos θ + y sin θ y = x sin θ + y cos θ (6.1), (x, y ) (x, y)..
62 6 { x = x cos θ y sin θ y = x sin θ + y cos θ (6.2),. 6.1.2. x = cos θ sin θ 0 sin θ cos θ 0 0 0 1 x (6.3) x, x (x, y), (x, y ). x = x y 1, x = x y 1 (6.4) 3 3. 6.1.3. 6.1. (t x, t y ) x = 1 0 t x 0 1 t y 0 0 1 x, x = 1 0 t x 0 1 t y 0 0 1 x (6.5) θ x = cos θ sin θ 0 sin θ cos θ 0 0 0 1 x, x = cos θ sin θ 0 sin θ cos θ 0 0 0 1 x (6.6) s x = s 0 0 0 s 0 0 0 1 x, x = 1/s 0 0 0 1/s 0 0 0 1 x (6.7)
6.1 63 θ, (t x, t y ) x = cos θ sin θ t x sin θ cos θ t y 0 0 1 x, x = cos θ sin θ t x cos θ + t y sin θ sin θ cos θ t x sin θ t y cos θ 0 0 1 x (6.8) s, θ, (t x, t y ) x = s cos θ s sin θ t x s sin θ s cos θ t y 0 0 1 x, x = 1 s cos θ sin θ t x cos θ + t y sin θ sin θ cos θ t x sin θ t y cos θ 0 0 s x (6.9) x = a 11 a 12 a 13 a 21 a 22 a 23 0 0 1 x, x = a 11 a 12 a 13 a 21 a 22 a 23 0 0 1 1 x (6.10), {a ij } a 11 a 22 a 21 a 12 0. (a) (b) (c) (d) (e) (f) 6.1 (a) (b) (c) (d) (e) (f)
64 6 6.2, ( ).. 6.2.1, W (k, l). W (k, l) = W 1 (k)w 2 (l) (6.11) ()., 2. 1. I, Î. Î(x, y) = W 1 (k)i(x + k, y) (6.12) s k s 2. Î, I. I (x, y) = s l s W 2 (l)î(x, y + l) (6.13) 6.2.2 W (k, l) = e (k2 +l 2 )/2σ 2. W (k, l) = e (k2 +l 2 )/2σ 2 = W 1 (k)w 2 (l) (6.14) W 1 (k) = e k2 /2σ 2, W 2 (l) = e l2 /2σ 2 (6.15). 1. W (k) = e k2 /2σ 2, s k s. 2. I, Î..
6.3 65 Î(x, y) = W (k)i(x + k, y) (6.16) s k s 3. Î, I. I (x, y) = s l s W (l)î(x, y + l) (6.17) 6.3,.,. 6.3.1 I(x, y) (). I = ( Ix I y ) (6.18), I x, I y x, y. I, I. I = I 2 x + I 2 y (6.19)., I. 6.3.2.,.,,. 1. I(x, y) w(x, y) x,. I x(x, y) w x (t x, s y)i(t, s)dtds
66 6 = w x (t, s )I(x + t, y + s )dt ds (6.20), t = t x, s = s y.. I x(x, y) = 1 w x (k, l)i(x + k, y + l) (6.21) C (k,l) N C,. C = w x (k, l)k (6.22) (k,l) N x, y. w x (x, y) = x σ 2 e (x2 +y 2 )/2σ 2, w y (x, y) = y σ 2 e (x2 +y 2 )/2σ 2 (6.23) x. I x(x, y) = D x (k, l)i(x + k, y + l) (6.24) (k,l) N +l 2 )/2σ 2 D x (k, l) = ke (k2, C = C (k,l) N k 2 e (k2 +l 2 )/2σ 2 (6.25) y. I y(x, y) = D y (k, l)i(x + k, y + l) (6.26) (k,l) N +l 2 )/2σ 2 D y (k, l) = le (k2, C = C (k,l) N l 2 e (k2 +l 2 )/2σ 2 (6.27) 6.3.3 1.
6.3 67 I = I xx + I yy (6.28),. I I(x, y), I(x, y), I(x + 1, y), I(x, y + 1), I(x + 1, y + 1) 1, 0. 6.3.4,,. I(x, y) w(x, y),. I (x, y) = w(t x, s y)i(t, s)dtds w(t, s )I(x + t, y + s )dt ds (6.29), t = t x, s = s y.. I (x, y) = 1 w(k, l)i(x + k, y + l) (6.30) C (k,l) N C,. C = 1 4 w(k, l)i(k 2 + l 2 ) (6.31) (k,l) N 2,. w(x, y) = 2 ( σ 2 1 x2 + y 2 ) 2σ 2 e (x2 +y 2 )/2σ 2 (6.32). G(k, l) = 1 C (1 x2 + y 2 2σ 2 I (x, y) = (k,l) N ) e (x2 +y 2 )/2σ 2, C = 1 4 G(k, l)i(x + k, y + l) (6.33) (k,l) N (k 2 + l 2 ) (1 k2 + l 2 ) 2σ 2 e (k2 +l 2 )/2σ 2 (6.34)
68 6 6.4 3 CG,.,. 6.4.1 3 A : (x A, y A ), B : (x B, y B ), C : (x C, y C ), (x, y). 6.2 α, β, γ. ( x y ) ( xa = α y A ) ( xb + β y B ) ( xc + γ y C ), α + β + γ = 1 (6.35) (6.35). x A x B x C y A y B y C 1 1 1 α β γ = x y 1 (6.36), (x, y) (α, β, γ). D = α = 1 D β = 1 D γ = 1 D x x B x C y y B y C 1 1 1 x A x x C y A y y C 1 1 1 x A x B x y B y B y 1 1 1 x A x B x C y B y B y C 1 1 1 = (y B y C )x (x B x C )y + (x B y C y B x C ) D = (y C y A )x (x C x A )y + (x C y A y C x A ) D = (y A y B )x (x A x B )y + (x A y B y A x B ) D (6.37) (6.38) (6.39) = (x By C y B x C ) + (x C y A y C x A ) + (x A y B y A x B ) (6.40) 6.4.2 ABC A B C. 1. A B C.
6.4 69 β = 0 α > 0 β < 0 γ < 0 γ = 0 α > 0 A β > 0 γ < 0 α > 0 β < 0 α > 0 γ > 0 β > 0 α = 0 B γ > 0 α < 0 C β > 0 γ < 0 α < 0 α < 0 β > 0 β < 0 γ > 0 γ > 0 6.2 x min x x max, y min y y max (6.41) 2.. a 11 = y B y C, a 12 = x B x C, a 13 = x B y C y B x C a 21 = y C y A, a 22 = x C x A, a 23 = x C y A y C x A (6.42) D = a 11 + a 23 + x A y B y A x B (6.43) 3. (x min, y min ) (x max, y max ) (x, y),. a (x, y) (α, β, γ). α = a 11x a 12 y + a 13 D, β = a 21x a 22 y + a 23, γ = 1 α β (6.44) D b α 0, β 0, γ 0 ABC (x, y ) (6.35). c (x, y ) (x, y).
70 6 6.5 2-2 ( ) ( ) ( ) σw 2 σ2 B σw 2 /σ2 B 6.5.1 M N L 1. L w(l), l = 0,..., L 1 0 2. l w(l) w(l) + 1 1 3. l = 0 w(l) w(l) > 0 l l min 4. l = L 1 w(l) w(l) > 0 l l max 6.5.2 l = l min 1 (6.45) n 1 = 0, n 2 = MN (6.46) s 1 = 0.0, s 2 = t 1 = 0.0, t 2 = l max i=l min i w(i) (6.47) l max i=l min i i w(i) (6.48) λ = 0.0 (6.49) 1. l = l max l 2. w(l) = 0 l l + 1 1 3. l l + 1 (6.50) z = w(l), z = w(l) l, z = w(l) l l (6.51) n 1 n 1 + z, s 1 s 1 + z, t 1 t 1 + z (6.52)
6.5 2-71 n 2 n 2 z, s 2 s 2 z, t 2 t 2 z (6.53) 4. 2 µ 1, µ 2 σ 1, σ 2 µ 1 = s 1 n 1, σ 2 1 = t 1 n 1 µ 2 1, µ 2 = s 2 n 2, σ 2 2 = t 2 n 2 µ 2 2 (6.54) 5. σ 2 B σ2 W σ 2 B = n 1 n 2 (µ 1 µ 2 ) 2, σ 2 W = n 1 σ 2 1 + n 2 σ 2 2 (6.55) 6. λ = σ2 B σ 2 W (6.56) 7. λ < λ l λ λ 1 6.3 2 2. (a) (b) 2 6.3 2
73 A libteo A.1 TEOFILE* TeoOpenFile (char *filename); filename : TEO TEO - PNM TEO TEOFILE NULL int TeoCloseFile (TEOFILE *teofp); teofp : TEOFILE TEOFILE TEOFILE 1 0
74 A libteo TEOFILE* TeoCreateFile (char *filename, int width, int height, int xoffset, int yoffset, int type, int bit, int plane, int frame); filename : width : height : xoffset : X yoffset : Y type : bit : plane : frame : TEO - TEOFILE TEOFILE NULL TeoCreateFileWithUserExtension TEOFILE* TeoCreateSimilarFile (char *filename, TEOFILE *teofp); filename : teofp : TEOFILE TEOFILE teofp TEO - TEOFILE TEOFILE NULL
A.1 75 TEOFILE* TeoCreateFileWithUserExtension (char *filename, int width, int height, int xoffset, int yoffset, int type, int bit, int plane, int frame, int extc, char **extv); filename : width : height : xoffset : X yoffset : Y type : bit : plane : frame : extc : extv : TEO - extc extv extc TEOFILE TEOFILE NULL TeoCreateFile TeoGetUserExtension
76 A libteo A.2 TEOIMAGE* TeoAllocImage (int int int int int int int width, height, xoffset, yoffset, type, bit, plane); width : height : xoffset : X yoffset : Y type : bit : plane : NULL TEOIMAGE* TeoAllocSimilarImage (TEOFILE *teofp); teofp : TEOFILE TEOFILE teofp NULL
A.2 77 TEOIMAGE* TeoAllocSimilarImage (TEOIMAGE *teoimg); teoimg : TEOIMAGE TEOIMAGE teoimg NULL int TeoFreeImage (TEOIMAGE *teoimg); teoimg : TEOIMAGE TEOIMAGE 1 0 int TeoReadFrame (TEOFILE *teofp, TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE 1 TEOIMAGE 1 0
78 A libteo int TeoWriteFrame (TEOFILE *teofp, TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE 1 1 0 int TeoSetAbsFrame (TEOFILE *teofp, int frame); teofp : TEOFILE frame : 0 1 0 TeoSetRelFrame int TeoSetRelFrame (TEOFILE *teofp, int frame); teofp : TEOFILE frame : 0 1 0 TeoSetAbsFrame
A.3 79 int TeoCheckFrame (TEOFILE *teofp); teofp : TEOFILE ( 0 ) (0) A.3 ETYPE TeoGetPixel (TEOIMAGE *teoimg, int x, int y, int plane, ETYPE); teoimg : TEOIMAGE x : x y : y plane : ETYPE : (x, y) plane ETYPE teoimg 0 (x, y) plane
80 A libteo void TeoPutPixel (TEOIMAGE *teoimg, int x, int y, int plane, ETYPE, ETYPE val); teoimg : TEOIMAGE x : x y : y plane : ETYPE : val : (x, y) plane val ETYPE teoimg 0 (void) TEO_BIT TeoGetBit (TEOIMAGE *teoimg, int x, int y, int plane); teoimg : TEOIMAGE x : x y : y plane : 2 (TEO BIT ) (x, y) plane 0 (x, y) plane (0 or 1)
A.4 81 void TeoPutBit (TEOIMAGE *teoimg, int x, int y, int plane, TEO BIT val); teoimg : TEOIMAGE x : x y : y plane : val : 2 (TEO BIT ) (x, y) plane val 0 (void) A.4 int TeoWidth (TEOFILE *teofp); int TeoWidth (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE int TeoHeight (TEOFILE *teofp); int TeoHeight (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE
82 A libteo int TeoType (TEOFILE *teofp); int TeoType (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE (TEO SIGNED, TEO UNSIGNED, TEO FLOAT) int TeoBit (TEOFILE *teofp); int TeoBit (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE int TeoPlane (TEOFILE *teofp); int TeoPlane (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE int TeoFsize (TEOFILE *teofp); int TeoFsize (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE ( )
A.4 83 int TeoXoffset (TEOFILE *teofp); int TeoXoffset (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE X int TeoYoffset (TEOFILE *teofp); int TeoYoffset (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE Y int TeoXstart (TEOFILE *teofp); int TeoXstart (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE X int TeoYstart (TEOFILE *teofp); int TeoYstart (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE Y
84 A libteo int TeoXend (TEOFILE *teofp); int TeoXend (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE X int TeoYend (TEOFILE *teofp); int TeoYend (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE Y int TeoIsBIT (TEOFILE *teofp); int TeoIsBIT (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE TEO BIT ( 0 ) (0) int TeoIsUINT8 (TEOFILE *teofp); int TeoIsUINT8 (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE TEO UINT8 ( 0 ) (0)
A.4 85 int TeoIsSINT8 (TEOFILE *teofp); int TeoIsSINT8 (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE TEO SINT8 ( 0 ) (0) int TeoIsUINT16 (TEOFILE *teofp); int TeoIsUINT16 (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE TEO UINT16 ( 0 ) (0) int TeoIsSINT16 (TEOFILE *teofp); int TeoIsSINT16 (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE TEO SINT16 ( 0 ) (0) int TeoIsUINT32 (TEOFILE *teofp); int TeoIsUINT32 (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE TEO UINT32 ( 0 ) (0)
86 A libteo int TeoIsSINT32 (TEOFILE *teofp); int TeoIsSINT32 (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE TEO SINT32 ( 0 ) (0) int TeoIsFLOAT32 (TEOFILE *teofp); int TeoIsFLOAT32 (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE TEO FLOAT32 ( 0 ) (0) int TeoIsFLOAT64 (TEOFILE *teofp); int TeoIsFLOAT64 (TEOIMAGE *teoimg); teofp : TEOFILE teoimg : TEOIMAGE TEO FLOAT64 ( 0 ) (0) int TeoFrame (TEOFILE *teofp); teofp : TEOFILE
A.4 87 int TeoHsize (TEOFILE *teofp); teofp : TEOFILE FILE* TeoFp (TEOFILE *teofp); teofp : TEOFILE TEO int TeoExtc (TEOFILE *teofp); teofp : TEOFILE char** TeoExtv (TEOFILE *teofp); teofp : TEOFILE char* TeoGetUserExtension (TEOFILE *teofp, char *key); teofp : TEOFILE key :
88 A libteo int TeoCurrent (TEOFILE *teofp); teofp : TEOFILE void* TeoData (TEOIMAGE *teoimg); teoimg : TEOIMAGE
89 B TEO B.1 pnm2teo pnm2teo [input.pnm]... input.pnm : PNM ( ) PNM TEO TEO % cat input.ppm pnm2teo > output.teo % pnm2teo input1.ppm input2.ppm > output.teo
90 B TEO B.2 teo2pnm teo2pnm #frame number [input.teo] frame number : input.teo : TEO ( ) TEO PNM % cat input.teo teo2pnm 0 > output.ppm % teo2pnm 0 input.teo > output.ppm B.3 teo2avi teo2avi [-c code][-q quality][-s start end step][-r frame rate] input.teo output.avi input.teo : TEO output.avi : AVI -c codec : -q quality : (0 100) -s start end step : -r frame rate : ( 30[fps]) TEO AVI -s ( ) % teo2avi input.teo output.avi % teo2avi input%02d.teo output.avi -s 0 10 1
B.4 teogzip 91 B.4 teogzip teogzip [-d] input.teo input.teo : TEO -d : TEO -d TEO % teogzip uncompressed.teo % teogzip -d compressed.teo B.5 teo get extension teo get extension input.teo [keyword] input.teo : TEO keyword : ( ) TEO % teo get extension has extension.teo HasAlpha YES % teo get extension has extension.teo HasAlpha YES
92 B TEO B.6 teocast teocast pixel-type bits [input.teo] pixel-type : (U, S, F ) bits : (1, 8, 16, 32, 64 ) input.teo : ( ) % teocast U 8 FLOAT64.teo > UINT8.teo % cat FLOAT64.teo teocast U 8 > UINT8.teo B.7 teodiff teodiff [-s -l1 -l2 -c] [-abs] input1.teo input2.teo input1.teo : TEO 1 input2.teo : TEO 2 -s : -l1 : L1 -l2 : L2 -c : -abs : 2 TEO FLOAT64 % teodiff input.teo background.teo > diff.teo
B.8 teorange 93 B.8 teorange teorange srcmin srcmax destmin destmax [input.teo] srcmin : srcmax : destmin : destmax : input.teo : TEO ( ) [srcmin:srcmax] [destmin:destmax] TEO FLOAT64 % teorange 0 100 0 255 input.teo > output.teo % cat input.teo teorange 0 100 0 255 > output.teo
95 C TEO TeoEyes TeoEyes TEO TEO TEO TEO TeoEyes C.1 TeoEyes C.2 ( C.3) C.1 TeoEyes
96 C TEO TeoEyes C.2 C.3
97 D TEO TEO libteo D.1 libteopp libteopp libteo TEOFILE TEOIMAGE C++ TEO D.2 ruby-teo ruby-teo libteo ruby Ruby D.3 libteo2ipl libteo2ipl TEO OpenCV OpenCV OpenCV D.4 libteo+ libteo+ libteo libteo+ 1
98 D TEO XY XY X Y XY TeoOpenXYFile, TeoCreateXYFile libteo XY TEO D.5 libteo draw libteo draw TEO libteo draw... TeoDrawPoint... TeoDrawLine... TeoDrawLines... TeoDrawSegments... TeoDrawRectangle... TeoDrawConvex... TeoDrawArc... TeoDrawEllipse 2... TeoDrawConic libteo draw D.1 D.6 libteo2gdk-pixbuf libteo2gdk-pixbuf TEO GdkPixbuf GdkPixbuf GTK+ GTK+ GUI
D.6 libteo2gdk-pixbuf 99 (a) 線分 矩形の描画 (b) 円の描画 図 D.1 (c) 楕円の描画 libteo draw を用いた図形の描画 にたちます TEO 画像データから GdkPixbuf 形式に変換するだけではなく 反対に GdkPixbuf 形式から TEOIMAGE 形式への変換も行うことができます これにより gdk-pixbuf 関数により読み込んだ JPEG, PNG 等の画像 データを TEO 画像データに変換することが可能になります 図 D.2 libteo2gdk-pixbuf を利用した GUI ツール (ggetpixel)
101 E MMX MMX MMX *1 MMX MMX MMX 64 8 8 MMX 1/8 MMX E.1 E.1(a) ( E.1(b)) MMX E.1 E.1 MMX MMX paddw mm1, mm0 mm0 F000h a2 a1 a0 + + + + mm1 3000h b2 b1 b0 paddusw mm1, mm0 mm0 F000h a2 a1 a0 + + + + mm1 3000h b2 b1 b0 mm0 2000h a2+b2 a1+b1 a0+b0 mm0 FFFFh a2+b2 a1+b1 a0+b0 E.1 (a) (b) MMX (a) (b) *1 MMX MMX
102 E MMX C C C MMX E.1 MMX E.2 MMX (12 ) MMX 8 (14 16 ) (18 31 ) 1 8 n (?) 8 1 (19 ) src ptr1 MMX mm0 *2 asm ( operand source, destination ); or asm ( operand source ); src ptr1 64 mm0 asm ( operand (%0), destination :: *3 ()); MMX mm0 mm7 8 1 (20 ) src ptr2 MMX mm1 (21 ) 1(22 ) mm0 mm2 mm0 mm1 mm0 psubusb 0 (23 ) mm1 mm2 mm1 (24 ) mm0, mm1 or mm0 1 2 (25 ) 0FFh 0 mm0 (26 ) mm2( 2 ) AND 2 0 *2 http://www.sra.co.jp/wingnut/gcc/gcc-j.html#extended%20asm *3 http://www.sra.co.jp/wingnut/gcc/gcc-j.html#constraints
103 (27 ) MMX asm ( operand source, (%0) :: ()); (28 30 ) 8 (32 ) MMX E.1 MMX 1 # include <stdio. h> 2 # include <stdlib. h> 3 # include <teo. h> 4 5 static void 6 func_ subtract_ mmx ( unsigned char * src1, 7 unsigned char * src2, 8 unsigned char * dst, 9 int size) { 10 int n; 11 unsigned char * src_ ptr1, * src_ ptr2, * dst_ ptr; 12 unsigned char threshold[ 8] = {16, 16, 16, 16, 16, 16, 16, 16}; 13 14 src_ ptr1 = src1; 15 src_ ptr2 = src2; 16 dst_ ptr = dst; 17 18 for ( n = size; n > 0; n -= 8) { 19 asm ("movq (%0), %%mm0"::"r"(src_ptr1)); 20 asm ("movq (%0), %%mm1"::"r"(src_ptr2)); 21 asm ("movq %mm0, %mm2"); 22 asm ("psubusb %mm1, %mm0"); 23 asm ("psubusb %mm2, %mm1"); 24 asm ("por %mm1, %mm0"); 25 asm ("pcmpgtb (%0), %%mm0"::"r"(threshold)); 26 asm ("pand %mm2, %mm0"); 27 asm ("movq %%mm0, (%0)"::"r"(dst_ptr)); 28 src_ ptr1 += 8; 29 src_ ptr2 += 8; 30 dst_ ptr += 8; 31 } 32 asm ("emms"); 33 } 34 35 int 36 main ( int argc, 37 char **argv) { 38 TEOFILE * src_ teofp[2], * dst_ teofp; 39 TEOIMAGE * src_ img[2], * dst_ img; 40 int n; 41 42 /* */
104 E MMX 43 for ( n = 0; n < 2; n++) { 44 src_ teofp[ n] = TeoOpenFile ( argv[ n+1]); 45 src_ img[ n] = TeoAllocSimilarImage ( src_ teofp[ n]); 46 TeoReadFrame (src_teofp[n], src_img[n]); 47 } 48 /* */ 49 dst_ teofp = TeoCreateSimilarFile (" -", src_ teofp[ 0]); 50 dst_ img = TeoAllocSimilarImage ( dst_ teofp); 51 52 /* */ 53 func_ subtract_ mmx (( unsigned char *) TeoData ( src_ img[ 1]), 54 ( unsigned char *) TeoData ( src_ img[ 0]), 55 ( unsigned char *) TeoData ( dst_ img), 56 TeoFsize (src_teofp[0])); 57 58 TeoWriteFrame ( dst_ teofp, dst_ img); 59 TeoCloseFile ( src_ teofp[ 0]); 60 TeoCloseFile ( src_ teofp[ 1]); 61 TeoCloseFile ( dst_ teofp); 62 TeoFreeImage ( src_ img[ 0]); 63 TeoFreeImage ( src_ img[ 1]); 64 TeoFreeImage ( dst_ img); 65 66 return 0; 67 }
105 movq (src_ptr1)... (3) movq (src_ptr1)... (4) mm0 20 100 80 70 0 0 255 200 (5) mm1 10 108 100 40 0 20 200 175 psubusb... (6) psubusb... (7) mm1 10 108 100 40 0 20 200 175 mm2 20 100 80 70 0 0 255 200 mm0 10 0 0 30 0 0 55 25 mm1 0 8 20 0 0 20 0 0 por... (8) mm0 10 8 20 30 0 20 55 25 pcmpgtb... (9) threshold 16 16 16 16 16 16 16 16 mm0 0 0 255 255 0 255 255 255 pand... (10) mm2 20 100 80 70 0 0 255 200 mm0 0 0 80 70 0 0 255 200 movq (dst_ptr)... (11) E.2 MMX E.3 (a) (b) (c) MMX (a) (b) (c)
106 E MMX E.1 MMX b w d q b w d q b w d q emms padd b w d sb sw usb usw psub b w d sb sw usb usw pmul(l h) w pmadd wd pand pandn por pxor ps(ll rl) w d q psra w d pcmp(eq gt) b w d pack sswb ssdw uswb punpack(l h) bw wd dq mov d q
107 BMP................................................. 10 GdkPixbuf........................................... 97 GIF.................................................. 10 GTK+............................................... 97 JPEG................................................ 10 libteo.................................................. 1 libteo+............................................... 95 libteo draw........................................... 96 libteo2gdk-pixbuf..................................... 97 libteo2ipl............................................. 95 libteopp.............................................. 95 MMX............................................ 99 OpenCV............................................. 95 pixel................................................... 9 PNG................................................. 10 pnm2teo.............................................. 89 PPM................................................. 10 Ruby................................................. 95 ruby-teo.............................................. 95 TEO BIT............................................ 19 TEO FLOAT......................................... 19 TEO FLOAT32...................................... 19 TEO FLOAT64...................................... 19 teo get extension..................................... 91 TEO GUNZIP COMMAND.......................... 20 TEO GZIP....................................... 14, 20 TEO GZIP COMMAND............................. 20 TEO SIGNED....................................... 19 TEO SINT16......................................... 19 TEO SINT32......................................... 19 TEO SINT8.......................................... 19 TEO TMP DIR...................................... 20 TEO UINT16........................................ 19 TEO UINT32........................................ 19 TEO UINT8......................................... 19 TEO UNSIGNED.................................... 19 teo2avi............................................... 90 teo2pnm.............................................. 89 TeoAllocImage....................................... 76 TeoAllocSimilarImage............................. 15, 76 TeoBit............................................... 81 teocast............................................... 91 TeoCheckFrame...................................... 78 TeoCloseFile...................................... 16, 73 TeoCreateFile........................................ 74 TeoCreateFileSimilarFile............................. 74 TeoCreateFileWithUserExtension..................... 75 TeoCreateSimilarFile................................. 15 TeoCurrent........................................... 87 TeoData.......................................... 19, 87 teodiff................................................ 92 TeoExtc.............................................. 86 TeoExtv.............................................. 87 TeoEyes............................................... 4 TEOFILE..................................... 18 TeoFp................................................ 86 TeoFrame............................................ 86 TeoFreeImage..................................... 16, 77 TeoFsize............................................. 82 TeoGetBit............................................ 80 TeoGetPixel...................................... 16, 79 TeoGetUserExtension................................. 87 teogunzip............................................. 14 teogzip........................................... 14, 90 TeoHeight............................................ 81 TeoHsize............................................. 86 TEOIMAGE................................... 18 TeoIsBIT............................................. 84 TeoIsFLOAT32....................................... 85 TeoIsFLOAT64....................................... 86 TeoIsSINT16......................................... 85 TeoIsSINT32......................................... 85 TeoIsSINT8.......................................... 84 TeoIsUINT16......................................... 84 TeoIsUINT32......................................... 85 TeoIsUINT8.......................................... 84 TeoOpenFile...................................... 15, 73 TeoPlane......................................... 16, 82 TeoPutBit............................................ 80 TeoPutPixel...................................... 16, 79 teorange.............................................. 92 TeoReadFrame.................................... 15, 77 TeoSetAbsFrame..................................... 78 TeoSetRelFrame...................................... 78 TeoType............................................. 81 TeoWidth............................................ 81 TeoWriteFrame................................... 16, 77 TeoXend.......................................... 15, 83 TeoXoffset............................................ 82 TeoXstart........................................ 15, 83 TeoYend.......................................... 15, 83 TeoYoffset............................................ 82 TeoYstart........................................ 15, 83 TEO.............................. 1, 11 User Extension....................................... 11 YCrCb........................................ 32.......................................... 63................................................ 66............................................ 66......................................... 47, 66.............................................. 48.................................................. 62.................................... 50............................................ 50............................................ 62................................................... 9.......................................... 47................................................. 9.......................................... 55
108................................................. 9.......................................... 66................................ 64.............................................. 62.................................................. 66.............................................. 58.............................................. 69.............................................. 67 1............................................ 55.............................................. 62.................................. 69.................................... 21........................................ 21........................................ 21............................................ 62 2................................................ 36.............................................. 27................................................ 27.............................................. 99............................................... 9........................................ 41............................................... 9........................................ 50...................................... 66.............................. 67.................................................. 62................................................ 48.................................... 36............................................ 11........................................ 91....................................... 91.................................. 47
5TEO 2002 3 22 2006 3 22 E-mail sugaya@suri.it.okayama-u.ac.jp