/* * ***************************************************************** * * * * * Copyright (c) Fast Corporation, 1997 * * * * * * All Rights Reserved. Unpublished rights reserved under * * * the copyright laws of the Japan. * * * * * * The software contained on this media is proprietary to * * * and embodies the confidential technology of Fast * * * Corporation. Possession, use, duplication or * * * dissemination of the software and media is authorized only * * * pursuant to a valid written license from Fast Corporation. * * * * * ***************************************************************** */ /* CSC90X ウインド内の平均、標準偏差、最大、最小、分散計測 STDDEVI.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 97/09/01 Ver 1.1 99/05/17 分散を標準偏差の2乗として算出するよう修正 Ver 1.2 99/06/24 処理時間の表示を追加 注記:m_menu.hをインクルードして下さい。 m_menu.c及びm_note.cをリンクして下さい。 */ /* * Include compiler runtime library */ #include #include /* * Include CSC90X library */ #include "f_stdlib.h" #include "f_time.h" #include "f_gui.h" #include "f_stdio.h" #include "f_graph.h" #include "f_image.h" #include "f_pinf.h" #include "f_video.h" #include "f_system.h" #include "f_bgray.h" #include "f_gray.h" #include "f_filter.h" #include "f_file.h" #include "f_binmem.h" /* * Include CSC90X common local */ #include "m_menu.h" /* * プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); void para_set( void ); void pdm_wind_set( int, int, PARADIGM * ); void wind_set( int *, int *, int *, int * ); void exec( void ); int xxx_freeze( int ); void cut_space( char *, char * ); void set_file_name( int, int, PARADIGM * ); int d4i5_d( double ); extern int message_note( void ); /* * メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 4 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " SET ", " 設 定 " }, { " EXEC ", " 試 行 " }, { " PROC3 ", " 処理3 " }, { " PROC4 ", " 処理4 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 #define FILENAME_SAIZE 12 char grayfile[FILENAME_SAIZE+1]; int pad_level; int pad_level_pre; PVAL value[5]; PVAL value_pre[10]; static char ss[70]; int gray_mem_no; int wxs, wys, wxe, wye; /*処理ウインド */ int pre_code; /*前処理 */ int fs0_image_sw; /*FS0画像入力スイッチ*/ /* * メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; /* パラメタ初期化 */ xpos = INIT_CUR_POS_X; ypos = INIT_CUR_POS_Y; s_xpos = INIT_CUR_POS_X; s_ypos = INIT_CUR_POS_Y; wxs = 0; wys = 0; wxe = 511; wye = 479; pre_code = 0; /*前処理コード*/ fs0_image_sw = OFF; strcpy( grayfile, "GRAYMEM1.DAT" ); /*FS0入力画像ファイル名*/ /* 入力ビデオ制御 */ Lib_input_video_control( GRAY_PLANE ); /* ビデオ出力表示項目制御 */ Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* ビデオ表示項目クリア */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* カーソル初期化 */ Lib_init_cursor(); /* メインメニューの表示 */ main_menu_disp(); /* マウスカーソルの表示 */ Lib_draw_cursor( INIT_CUR_POS_X, INIT_CUR_POS_Y ); gray_mem_no = Lib_alloc_gray_memory(); /* グレイメモリの確保 */ if ( -1 == gray_mem_no ) { Lib_display_message( 70, 200, "グレイメモリ アロケーションエラー", "処理打ち切り" ); return; } else Lib_gray_memory_cls( gray_mem_no ); /* メニュー制御 */ for (;;) { sts = 0; /* マウス位置読みとり */ sts = Lib_see_current_position( &xpos, &ypos ); if ( s_xpos != xpos || s_ypos != ypos ) { /* マウス表示位置移動 */ Lib_move_cursor( xpos, ypos ); s_xpos = xpos; s_ypos = ypos; } /* 処理振り分け */ if( CURSOR_EXECUTE == sts ) { if ( xpos > MENU_1_XS && xpos < MENU_1_XE && ypos > MENU_1_YS && ypos < MENU_1_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); para_set( ); /* 設定 */ main_menu_disp(); } else if ( xpos > MENU_2_XS && xpos < MENU_2_XE && ypos > MENU_2_YS && ypos < MENU_2_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); exec( ); /* 試行 */ main_menu_disp(); } else if ( xpos > MENU_H_XS && xpos < MENU_H_XE && ypos > MENU_H_YS && ypos < MENU_H_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); disp_help(); /* ヘルプ */ main_menu_disp(); } else if ( xpos > MENU_E_XS && xpos < MENU_E_XE && ypos > MENU_E_YS && ypos < MENU_E_YE ) { break; /* 終了 */ } } } Lib_free_gray_memory( gray_mem_no ); Lib_window( 0, 0, 511, 479 ); } /* * メインメニュー表示 */ static void main_menu_disp( void ) { int iLanguage; /* 日本語/英語表示文字列切替情報取得 */ iLanguage = Lib_get_disp_language(); /* 整列キー表示 -> ( m_menu.c ) */ SUB_menu_disp4he( (char *)str_main_menu[0][iLanguage], (char *)str_main_menu[1][iLanguage], (char *)NULL, (char *)NULL ); } /* * ヘルプ表示 */ static void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 STDDEVI" ); Lib_chrdisp( 11, 10, "処理ウインド内について平均、標準偏差、" ); Lib_chrdisp( 11, 12, "最大、最小、分散を計測します。" ); Lib_chrdisp( 11, 16, "○任意に下記の前処理がかけられます" ); Lib_chrdisp( 11, 18, " 最大値/最小値/鮮鋭化/ソ\ーベル微分" ); Lib_chrdisp( 11, 22, "○任意にFS0画像入力もできます" ); } /************************************************************************/ /* パラメータ設定 */ /************************************************************************/ static char *select_pre_code[7] = { "なし     ", "最大値    ", "ソ\ーベル X ", "最小値    ", "ソ\ーベル Y ", "鮮鋭化    ", "ソ\ーベル XY" }; void para_set() { int rtn; int i; Lib_set_pad_maxstring( 14 ); pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); value[1].select_type = pre_code; value[2].on_off_type = fs0_image_sw; i = 0; Lib_view_set_null ( pad_level, 5, 5, "処理範囲", i ); i++; Lib_view_set_select ( pad_level, 5, 35, "前処理" , value[i].select_type, 7, select_pre_code, i ); i++; Lib_view_set_uniq_alter( pad_level, 5, 65, "FS0画像入力", value[i].on_off_type, i ); i++; Lib_set_paradigm( pad_level, 0, START_TIMING, pdm_wind_set ); Lib_set_paradigm( pad_level, 2, END_TIMING, set_file_name ); Lib_view_set_size( pad_level, 20, 50, 5, 5 ); /* 設定パッドの表示 */ Lib_draw_menu( pad_level ); /* 設定値の読みとり */ if( PAD_EXECUTE == ( rtn = Lib_process_menu( pad_level, value ) ) ) { pre_code = value[1].select_type; fs0_image_sw = value[2].on_off_type; } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); Lib_set_pad_maxstring( 10 ); } /************************************************************************/ /* ウインド設定 */ /************************************************************************/ void pdm_wind_set( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { int rtn; Lib_window( 0, 0, 511, 479 ); if ( OFF == value[2].on_off_type ) rtn = Lib_freeze( TRANSMIT ); else rtn = xxx_freeze( TRANSMIT ); if ( NORMAL_RETURN == rtn ) { wind_set( &wxs, &wys, &wxe, &wye ); } Lib_window( wxs, wys, wxe, wye ); if ( OFF == value[2].on_off_type ) Lib_freerun(); } /************************************************************************/ /* 試行 */ /************************************************************************/ void exec() { struct _deviinfo devi; int wk; int rtn; /**/Lib_strtclk_count(); /*タイマーカウントモードのスタート*/ if ( OFF == fs0_image_sw ) rtn = Lib_freeze( NOT_TRANSMIT ); else rtn = xxx_freeze( TRANSMIT ); if ( NORMAL_RETURN == rtn ) { Lib_window( wxs, wys, wxe, wye ); /*処理ウインド*/ if ( 0 == pre_code ) /*なし*/ Lib_gray_memory_move( 0, gray_mem_no, 0xff ); else if ( 1 == pre_code ) Lib_max_filter( 0, gray_mem_no ); /*最大値*/ else if ( 2 == pre_code ) Lib_sobel( 0, gray_mem_no, X_DIRECTION ); /*ソーベル X*/ else if ( 3 == pre_code ) Lib_min_filter( 0, gray_mem_no ); /*最小値*/ else if ( 4 == pre_code ) Lib_sobel( 0, gray_mem_no, Y_DIRECTION ); /*ソーベル Y*/ else if ( 5 == pre_code ) Lib_sharp( 0, gray_mem_no ); /*鮮鋭化*/ else if ( 6 == pre_code ) Lib_sobel( 0, gray_mem_no, XY_DIRECTION ); /*ソーベル XY*/ Lib_xvideo_transmit( gray_mem_no, GRAY_PLANE ); Lib_window( wxs+1, wys+1, wxe-1, wye-1 ); /*処理ウインド*/ Lib_stddevi( gray_mem_no, &devi ); /*平均、標準偏差、最大、最小の取得*/ wk = d4i5_d( devi.average ); Lib_sprintf( ss, "平均 = %d", wk ); Lib_chrdisp( 1, 10, ss ); wk = d4i5_d( devi.stddeviation ); Lib_sprintf( ss, "標準偏差 = %d", wk ); Lib_chrdisp( 1, 11, ss ); Lib_sprintf( ss, "最大値 = %d", devi.max ); Lib_chrdisp( 1, 12, ss ); Lib_sprintf( ss, "最小値 = %d", devi.min ); Lib_chrdisp( 1, 13, ss ); Lib_sprintf( ss, "分散 = %d", wk*wk ); Lib_chrdisp( 1, 14, ss ); } Lib_time_disp( 0, 452 ); Lib_display_keyinput( 460, 0, "確認" ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); if ( OFF == fs0_image_sw ) Lib_freerun(); } /************************************************************************/ /* フリーズ */ /************************************************************************/ int xxx_freeze( flag ) int flag; /* バッファ転送フラグ */ { char wwstr[13]; char infile[20]; int status; status = ERROR_RETURN; Lib_freeze( NOT_TRANSMIT ); Lib_chrdisp( 1, 30, "画像ロード中..." ); cut_space( grayfile, wwstr ); Lib_sprintf( infile, "\\FS0\\%s", wwstr ); if ( 0 == Lib_fload( infile, Lib_adrs_gray_memory(0), Lib_get_fx_size()*Lib_get_fy_size() ) ) { Lib_chrdisp( 1, 30, "         " ); Lib_display_message( 70, 200, "fload_err", infile ); } else { Lib_chrdisp( 1, 30, "         " ); if ( ON == flag ) Lib_xvideo_transmit( 0, GRAY_PLANE ); /* モニタ表示 */ status = NORMAL_RETURN; } return( status ); } /*********************************************************************/ /* スペース除去                        */ /*********************************************************************/ void cut_space( instr, otstr ) char *instr; char *otstr; { for(;;) { if ( ' ' != *instr ) *otstr++ = *instr; if ( 0x00 == *instr ) break; instr++; } } /*********************************************************************/ /*  ファイル名設定                       */ /*********************************************************************/ void set_file_name( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { if ( ON == value[2].on_off_type ) Lib_get_string_by_keyboad( 50, 200, 12, grayfile ); } /*********************************************************************/ /*  ウインド設定                          */ /*********************************************************************/ void wind_set( xs, ys, xe, ye ) int *xs, *ys, *xe, *ye; /* 入出力:ウインド位置 */ { int pad_level_wind; PVAL value[3]; int no; int i; pad_level_wind = Lib_view_open(); Lib_view_set_title( pad_level_wind, "処理範囲" ); value[0].box_type.x = *xs; value[0].box_type.y = *ys; value[1].box_type.x = *xe - *xs + 1; value[1].box_type.y = *ye - *ys + 1; i=0; Lib_view_set_box( pad_level_wind, 5, 5, "始点" , value[i].box_type.x, value[i].box_type.y, 3, 1, i ); i++; Lib_view_set_box( pad_level_wind, 5, 35, "サイズ", value[i].box_type.x, value[i].box_type.y, 3, 0, i ); i++; Lib_view_set_size( pad_level_wind, 50, 80, 5, 5 ); Lib_draw_menu( pad_level_wind ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level_wind, value ) ) ) { if ( PAD_EXECUTE == no ) { *xs = value[0].box_type.x; *ys = value[0].box_type.y; *xe = value[0].box_type.x + value[1].box_type.x - 1; *ye = value[0].box_type.y + value[1].box_type.y - 1; } } else { Lib_chrdisp( 1, 28, "pad_level_wind ERR!" ); } Lib_erase_menu( pad_level_wind ); Lib_view_close( pad_level_wind ); } /***********************************************************************/ /* 入力数値(double)の4捨5入した数値(int)を返す */ /***********************************************************************/ int d4i5_d( in ) double in; /* 入力:浮動小数点数値 */ { int out; if ( in >= 0.0 ) out = (int)( in + 0.5 ); else out = (int)( in - 0.5 ); return( out ); }