@@ -27,7 +27,7 @@ using namespace TCLAP;
2727typedef std::vector< std::string >::iterator stringiterator;
2828
2929// Supported operations
30- enum operations {none = 0 , info, convert, labelinfo, rescale, invert, relabel, smooth, bilateral, median, gradmag, laplacian, distancemap, threshold, Otsu, crop, mask, resample, match, checker, add, diff, mean, merge, cast, flip};
30+ enum operations {none = 0 , info, convert, labelinfo, rescale, invert, relabel, smooth, bilateral, median, gradmag, laplacian, distancemap, threshold, Otsu, crop, mask, resample, match, checker, add, diff, mean, merge, cast, flip, subsample };
3131
3232// Image stuff
3333typedef unsigned char charPixelType;
@@ -106,6 +106,7 @@ int main(int argc, char *argv[])
106106 ValueArg<size_t > OtsuArg (" " , " Otsu" , " Otsu multiple threshold with the number of bins to use." , false , 128 , " Otsu" );
107107 ValueArg<size_t > paddingArg (" " , " padding" , " Number of pixels to pad in the operation in question (such as crop)." , false , 1 , " Padding" );
108108 ValueArg<size_t > flipArg (" f" , " flip" , " Flip the image about origin at axis indicated (0: x-axis, 1:y-axis, 2:z-axis)." , false , 0 , " Flip" );
109+ ValueArg<size_t > subsampleArg (" x" , " subsample" , " Downsample the image by the factor indicated (same in all dimensions)." , false , 0 , " Subsample" );
109110 // /Switches
110111 // /XOR Switches
111112 SwitchArg infoArg (" " , " info" , " Report the image information(s)." , false );
@@ -171,6 +172,7 @@ int main(int argc, char *argv[])
171172 xorlist.push_back (&meanArg);
172173 xorlist.push_back (&castArg);
173174 xorlist.push_back (&flipArg);
175+ xorlist.push_back (&subsampleArg);
174176 // ~ xorlist.push_back(&mseArg);
175177#if (ITK_REVIEW || ITK_VERSION_MAJOR > 3) // Review only members
176178 xorlist.push_back (&labelInfoArg);
@@ -206,6 +208,7 @@ int main(int argc, char *argv[])
206208 size_t OtsuValue = OtsuArg.getValue (); // number of bins
207209 size_t paddingValue = paddingArg.getValue (); // number of bins
208210 size_t flipAxis = flipArg.getValue (); // number of bins
211+ size_t subsampleFactor = subsampleArg.getValue (); // downsample by
209212
210213 std::string maskName;
211214 if (cropArg.isSet ())
@@ -260,7 +263,7 @@ int main(int argc, char *argv[])
260263 }
261264 if ( smoothArg.isSet () || bilateralArg.isSet () || medianArg.isSet () || gradMagArg.isSet () || laplacianArg.isSet () || distancemapArg.isSet () || cropArg.isSet () || maskArg.isSet ()
262265 || resampleArg.isSet () || matchArg.isSet () || checkerArg.isSet () || thresholdArg.isSet () || OtsuArg.isSet () || rescaleArg.isSet () || invertArg.isSet () || relabelArg.isSet () || addArg.isSet ()
263- || diffArg.isSet () || meanArg.isSet () || mergeArg.isSet () || castArg.isSet () || flipArg.isSet () )
266+ || diffArg.isSet () || meanArg.isSet () || mergeArg.isSet () || castArg.isSet () || flipArg.isSet () || subsampleArg. isSet () )
264267 {
265268 // /Check if output argument given and only doing one image
266269 if (filenames.size () == 1 && (addArg.isSet () || diffArg.isSet () || meanArg.isSet () || mergeArg.isSet ()))
@@ -343,6 +346,8 @@ int main(int argc, char *argv[])
343346 operation = cast;
344347 if (flipArg.isSet ())
345348 operation = flip;
349+ if (subsampleArg.isSet ())
350+ operation = subsample;
346351 }
347352 if (aboveArg.isSet () || belowArg.isSet ())
348353 {
@@ -402,6 +407,15 @@ int main(int argc, char *argv[])
402407 exit (EXIT_FAILURE);
403408 }
404409 }
410+ if (subsampleArg.isSet ())
411+ {
412+ if (subsampleFactor < 2 )
413+ {
414+ milx::PrintError (" Argument Error: Incorrect value provided for subsampling." );
415+ milx::PrintError (" Re-run with value correctly set." );
416+ exit (EXIT_FAILURE);
417+ }
418+ }
405419 if (thresholdArg.isSet () || rescaleArg.isSet ())
406420 {
407421 if ( (!aboveArg.isSet () || !belowArg.isSet ()) && rescaleArg.isSet () )
@@ -764,6 +778,10 @@ int main(int argc, char *argv[])
764778 milx::Image<charImageType>::FlipCollection (labelledCollection, false , false , true , true );
765779 break ;
766780
781+ case subsample:
782+ milx::Image<charImageType>::SubsampleCollection (labelledCollection, subsampleFactor);
783+ break ;
784+
767785 case none: // --------------------------------
768786 break ;
769787
@@ -985,6 +1003,10 @@ int main(int argc, char *argv[])
9851003 milx::Image<floatImageType>::FlipCollection (collection, false , false , true , true );
9861004 break ;
9871005
1006+ case subsample:
1007+ milx::Image<floatImageType>::SubsampleCollection (collection, subsampleFactor);
1008+ break ;
1009+
9881010 case none: // --------------------------------
9891011 break ;
9901012
0 commit comments