Add greyscale option to threshold operation (#480)

This commit is contained in:
Matt Hirsch
2016-07-03 14:32:07 -04:00
committed by Lovell Fuller
parent 4b98dbb454
commit 85f20c6e1b
8 changed files with 55 additions and 3 deletions

View File

@@ -327,4 +327,11 @@ namespace sharp {
);
}
VImage Threshold(VImage image, double const threshold, bool const thresholdGrayscale) {
if(!thresholdGrayscale) {
return image >= threshold;
}
return image.colourspace(VIPS_INTERPRETATION_B_W) >= threshold;
}
} // namespace sharp

View File

@@ -54,6 +54,11 @@ namespace sharp {
*/
VImage TileCache(VImage image, double const factor);
/*
Threshold an image
*/
VImage Threshold(VImage image, double const threshold, bool const thresholdColor);
} // namespace sharp
#endif // SRC_OPERATIONS_H_

View File

@@ -52,6 +52,7 @@ using sharp::Blur;
using sharp::Sharpen;
using sharp::EntropyCrop;
using sharp::TileCache;
using sharp::Threshold;
using sharp::ImageType;
using sharp::ImageTypeId;
@@ -625,7 +626,7 @@ class PipelineWorker : public AsyncWorker {
// Threshold - must happen before blurring, due to the utility of blurring after thresholding
if (shouldThreshold) {
image = image.colourspace(VIPS_INTERPRETATION_B_W) >= baton->threshold;
image = Threshold(image, baton->threshold, baton->thresholdGrayscale);
}
// Blur
@@ -1107,6 +1108,7 @@ NAN_METHOD(pipeline) {
baton->sharpenFlat = attrAs<double>(options, "sharpenFlat");
baton->sharpenJagged = attrAs<double>(options, "sharpenJagged");
baton->threshold = attrAs<int32_t>(options, "threshold");
baton->thresholdGrayscale = attrAs<bool>(options, "thresholdGrayscale");
baton->gamma = attrAs<double>(options, "gamma");
baton->greyscale = attrAs<bool>(options, "greyscale");
baton->normalize = attrAs<bool>(options, "normalize");

View File

@@ -58,6 +58,7 @@ struct PipelineBaton {
double sharpenFlat;
double sharpenJagged;
int threshold;
bool thresholdGrayscale;
double gamma;
bool greyscale;
bool normalize;
@@ -113,6 +114,7 @@ struct PipelineBaton {
sharpenFlat(1.0),
sharpenJagged(2.0),
threshold(0),
thresholdGrayscale(true),
gamma(0.0),
greyscale(false),
normalize(false),