Debian Codegraph @

test/check2tif.cc

raw symbols SCIP
1 /**********************************************************************
2 check2tif.cc: test app for jiblib
3 Author(s): [email protected]
4 Copyright (C) 2016-2020 European Union (Joint Research Centre)
5
6 This file is part of jiplib.
7
8 jiplib is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 jiplib is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with jiplib. If not, see <https://www.gnu.org/licenses/>.
20 ***********************************************************************/
21 #include <memory>
22 #include "base/Optionjl.h"
23 #include "apps/AppFactory.h"
24 #include "imageclasses/ImgCollection.h"
25 #include "jim.h"
26
27 using namespace std;
28
29 int main(int argc, char *argv[])
30 {
31 Optionjl<string> input_opt("i", "input", "Input image file(s). If input contains multiple images, a multi-band output is created");
32 Optionjl<unsigned short> nodata_opt("nodata", "nodata", "Nodata value to check in image.",0);
33 Optionjl<string> output_opt("o", "output", "Output image file");
34 Optionjl<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate).","GTiff");
35 Optionjl<string> option_opt("co", "co", "Creation option for output file. Multiple options can be specified.");
36 Optionjl<unsigned long int> memory_opt("mem", "mem", "Buffer size (in MB) to read image data blocks in memory",0,1);
37
38 memory_opt.setHide(1);
39
40 bool doProcess;//stop process when program was invoked with help option (-h --help)
41 try{
42 doProcess=input_opt.retrieveOption(argc,argv);
43 nodata_opt.retrieveOption(argc,argv);
44 output_opt.retrieveOption(argc,argv);
45 oformat_opt.retrieveOption(argc,argv);
46 option_opt.retrieveOption(argc,argv);
47 memory_opt.retrieveOption(argc,argv);
48 }
49 catch(string predefinedString){
50 std::cout << predefinedString << std::endl;
51 exit(0);
52 }
53 if(doProcess){
54 if(input_opt.empty()){
55 std::cerr << "Error: no input file provided (use option -i). Use --help for help information" << std::endl;
56 exit(1);
57 }
58 }
59 try{
60 Jim inputImg(input_opt[0]);
61 inputImg.readData();
62 shared_ptr<Jim> mask=make_shared<Jim>(inputImg,true);
63 shared_ptr<Jim> marker=make_shared<Jim>(inputImg,false);
64 std::vector<unsigned short> lineBuffer(marker->nrOfCol());
65 std::vector<unsigned short> zeroBuffer(marker->nrOfCol());
66 marker->writeData(zeroBuffer,0,0);
67 for(int icol=0;icol<marker->nrOfCol();++icol){
68 if(icol<1||icol>marker->nrOfCol()-2)
69 lineBuffer[icol]=0;
70 else
71 lineBuffer[icol]=1;
72 }
73 for(int irow=1;irow<marker->nrOfRow()-1;++irow)
74 marker->writeData(lineBuffer,irow,0);
75 marker->writeData(zeroBuffer,marker->nrOfRow()-1,0);
76
77 mask->writeData(nodata_opt[0],1500,1500,0);
78 mask->pushNoDataValue(1);
79 mask->setThreshold(nodata_opt[0],nodata_opt[0],0);
80
81 marker->rero(mask,8,1);
82 marker->setFile("/scratch/test/marker_cc.tif",oformat_opt[0],memory_opt[0],option_opt);
83 mask->setFile("/scratch/test/mask_cc.tif",oformat_opt[0],memory_opt[0],option_opt);
84 if(marker->isEqual(mask))
85 std::cout << "Check passed for image " << input_opt[0] << std::endl;
86 else
87 std::cout << "Error: check not passed for image " << input_opt[0] << std::endl;
88 Jim outputImg(inputImg,true);
89 outputImg.setFile(output_opt[0],oformat_opt[0],memory_opt[0],option_opt);
90 if(inputImg==outputImg)
91 cout << "created image identical to input image" << endl;
92 else
93 cout << "Error: created image different then input image" << endl;
94 outputImg.close();
95 mask->close();
96 marker->close();
97 inputImg.close();
98 }
99 catch(string helpString){//help was invoked
100 std::cout << helpString << std::endl;
101 return(1);
102 }
103 return(0);
104 }