mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add greyscale option to threshold operation (#480)
This commit is contained in:
committed by
Lovell Fuller
parent
4b98dbb454
commit
85f20c6e1b
@@ -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
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user