Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the UnsharpMask Effect #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions effect.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ convolveImage(Image *image, void *data, ExceptionInfo *ex) {
ConvolveData *d = data;
return ConvolveImage(image, d->order, d->kernel, ex);
}

Image *
unsharpMaskImage(Image *image, void *data, ExceptionInfo *ex) {
UnsharpMaskData *d = data;
return UnsharpMaskImage(image, d->radius, d->sigma, d->amount, d->threshold ,ex);
}
14 changes: 14 additions & 0 deletions effect.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ func (im *Image) Convolve(order int, kernel []float64) (*Image, error) {
data.kernel = (*C.double)(unsafe.Pointer(&kernel[0]))
return im.applyDataFunc("convolving", C.ImageDataFunc(C.convolveImage), &data)
}

// UnsharpMask sharpens one or more image channels. We convolve the image
// with a Gaussian operator of the given radius and standard deviation (sigma).
// For reasonable results, radius should be larger than sigma. Use a radius of 0 and
// UnsharpMaskImage selects a suitable radius for you.
func (im *Image) UnsharpMask(radius float64, sigma float64, amount float64, threshold float64) (*Image, error) {
var data C.UnsharpMaskData
data.radius = C.double(radius)
data.sigma = C.double(sigma)
data.amount = C.double(amount)
data.threshold = C.double(threshold)

return im.applyDataFunc("unsharp_mask", C.ImageDataFunc(C.unsharpMaskImage), &data)
}
8 changes: 8 additions & 0 deletions effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ typedef struct {
double *kernel;
} ConvolveData;

typedef struct {
double radius;
double sigma;
double amount;
double threshold;
} UnsharpMaskData;

Image * convolveImage(Image *image, void *data, ExceptionInfo *ex);
Image * unsharpMaskImage(Image *image, void *data, ExceptionInfo *ex);

#endif