|
NCBI C++ ToolKit
|
00001 /* $Id: sub_image.cpp 33815 2007-05-04 17:18:18Z kazimird $ 00002 * =========================================================================== 00003 * 00004 * PUBLIC DOMAIN NOTICE 00005 * National Center for Biotechnology Information 00006 * 00007 * This software/database is a "United States Government Work" under the 00008 * terms of the United States Copyright Act. It was written as part of 00009 * the author's official duties as a United States Government employee and 00010 * thus cannot be copyrighted. This software/database is freely available 00011 * to the public for use. The National Library of Medicine and the U.S. 00012 * Government have not placed any restriction on its use or reproduction. 00013 * 00014 * Although all reasonable efforts have been taken to ensure the accuracy 00015 * and reliability of the software and data, the NLM and the U.S. 00016 * Government do not and cannot warrant the performance or results that 00017 * may be obtained by using this software or data. The NLM and the U.S. 00018 * Government disclaim all warranties, express or implied, including 00019 * warranties of performance, merchantability or fitness for any particular 00020 * purpose. 00021 * 00022 * Please cite the author in any work or product based on this material. 00023 * 00024 * =========================================================================== 00025 * 00026 * Authors: Mike DiCuccio 00027 * 00028 * File Description: 00029 * Test app -- tests various aspects of image conversion / manipulation 00030 */ 00031 00032 00033 #include <ncbi_pch.hpp> 00034 #include <corelib/ncbiapp.hpp> 00035 #include <corelib/ncbiargs.hpp> 00036 #include <corelib/ncbienv.hpp> 00037 #include <corelib/ncbireg.hpp> 00038 #include <corelib/ncbitime.hpp> 00039 00040 #include <util/image/image_io.hpp> 00041 00042 USING_NCBI_SCOPE; 00043 00044 00045 00046 class CSubImageApp : public CNcbiApplication 00047 { 00048 public: 00049 virtual void Init(void); 00050 virtual int Run(void); 00051 virtual void Exit(void); 00052 }; 00053 00054 00055 00056 ///////////////////////////////////////////////////////////////////////////// 00057 // Init test for all different types of arguments 00058 00059 00060 void CSubImageApp::Init(void) 00061 { 00062 // Create command-line argument descriptions class 00063 auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); 00064 00065 // Specify USAGE context 00066 arg_desc->SetUsageContext(GetArguments().GetProgramBasename(), 00067 "Image read/write test application"); 00068 00069 arg_desc->AddDefaultPositional("image", "Image to crop", 00070 CArgDescriptions::eInputFile, "-", 00071 CArgDescriptions::fBinary); 00072 00073 arg_desc->AddOptionalKey("out", "OutFile", 00074 "File name of resultant image", 00075 CArgDescriptions::eString); 00076 00077 arg_desc->AddKey("x", "PosX", "Crop X Position", 00078 CArgDescriptions::eInteger); 00079 arg_desc->AddKey("y", "PosX", "Crop X Position", 00080 CArgDescriptions::eInteger); 00081 arg_desc->AddKey("wd", "Width", "Crop Width", 00082 CArgDescriptions::eInteger); 00083 arg_desc->AddKey("ht", "Height", "Crop Height", 00084 CArgDescriptions::eInteger); 00085 00086 // Setup arg.descriptions for this application 00087 SetupArgDescriptions(arg_desc.release()); 00088 } 00089 00090 00091 00092 int CSubImageApp::Run(void) 00093 { 00094 CArgs args = GetArgs(); 00095 00096 CNcbiIstream& istr = args["image"].AsInputFile(); 00097 int x = args["x"].AsInteger(); 00098 int y = args["y"].AsInteger(); 00099 int w = args["wd"].AsInteger(); 00100 int h = args["ht"].AsInteger(); 00101 00102 CStopWatch sw; 00103 sw.Start(); 00104 CRef<CImage> image(CImageIO::ReadSubImage(istr, x, y, w, h)); 00105 double read_time = sw.Elapsed(); 00106 00107 if ( !image ) { 00108 LOG_POST(Error << "error: can't get subimage"); 00109 return 1; 00110 } 00111 00112 LOG_POST(Info << "read (" << x << ", " << y << ", " << x+w 00113 << ", " << y+h << ") in " << read_time << " seconds"); 00114 00115 if (args["out"]) { 00116 CImageIO::WriteImage(*image, args["out"].AsString()); 00117 double write_time = sw.Elapsed(); 00118 LOG_POST(Info << "wrote image in " << write_time - read_time 00119 << " seconds"); 00120 } 00121 00122 return 0; 00123 } 00124 00125 00126 ///////////////////////////////////////////////////////////////////////////// 00127 // Cleanup 00128 00129 00130 void CSubImageApp::Exit(void) 00131 { 00132 SetDiagStream(0); 00133 } 00134 00135 00136 00137 ///////////////////////////////////////////////////////////////////////////// 00138 // MAIN 00139 00140 00141 int main(int argc, const char* argv[]) 00142 { 00143 // Execute main application function 00144 return CSubImageApp().AppMain(argc, argv, 0, eDS_Default, 0); 00145 }
1.7.5.1
Modified on Wed May 23 13:10:59 2012 by modify_doxy.py rev. 337098