Skip to content

Commit d46e8ef

Browse files
committed
Merge branch 'experimental' into topic-qt5
2 parents c8b5ec1 + 0facac0 commit d46e8ef

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

apps/milxImageApp/milxImageApp.cxx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace TCLAP;
2727
typedef 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
3333
typedef 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

include/milxImage.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,11 @@ class SMILI_EXPORT Image : public ImageBase
769769
template<typename TOutImage>
770770
static std::vector< typename itk::SmartPointer<TOutImage> > OtsuMultipleThresholdCollection(const std::vector< typename itk::SmartPointer<TImage> > &images, const int bins, const int noOfLabels);
771771

772+
/*!
773+
\fn Image::SubsampleCollection(std::vector< typename itk::SmartPointer<TImage> > &images, unsigned factor = 2)
774+
\brief Batch process images by downsampling each image by factor provided.
775+
*/
776+
static void SubsampleCollection(std::vector< typename itk::SmartPointer<TImage> > &images, unsigned factor = 2);
772777
#if (ITK_REVIEW || ITK_VERSION_MAJOR > 3)
773778
/*!
774779
\fn Image::MaskAndCropCollection(std::vector< typename itk::SmartPointer<TImage> > &images, itk::SmartPointer<TMaskImage> maskImage, const size_t pixelPadding = 1)
@@ -3373,6 +3378,22 @@ std::vector< typename itk::SmartPointer<TOutImage> > Image<TImage>::OtsuMultiple
33733378
return collection;
33743379
}
33753380

3381+
template<class TImage>
3382+
void Image<TImage>::SubsampleCollection(std::vector< typename itk::SmartPointer<TImage> > &images, unsigned factor)
3383+
{
3384+
const size_t n = images.size();
3385+
3386+
typename TImage::SizeType factors;
3387+
factors[0] = factor;
3388+
factors[1] = factor;
3389+
factors[2] = factor;
3390+
3391+
for (size_t j = 0; j < n; j++)
3392+
{
3393+
images[j] = SubsampleImage(images[j], factors);
3394+
}
3395+
}
3396+
33763397
#if (ITK_REVIEW || ITK_VERSION_MAJOR > 3)
33773398
template<class TImage>
33783399
template<class TMaskImage>

0 commit comments

Comments
 (0)