Skip to content

Commit

Permalink
added brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashoffmann1979 committed Jun 11, 2015
1 parent b71d5ab commit f9d5c8a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/Matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Matrix::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(ctor, "get", Get);
NODE_SET_PROTOTYPE_METHOD(ctor, "set", Set);
NODE_SET_PROTOTYPE_METHOD(ctor, "put", Put);
NODE_SET_PROTOTYPE_METHOD(ctor, "brightness", Brightness);
NODE_SET_PROTOTYPE_METHOD(ctor, "normalize", Normalize);
NODE_SET_PROTOTYPE_METHOD(ctor, "getData", GetData);
NODE_SET_PROTOTYPE_METHOD(ctor, "pixel", Pixel);
Expand Down Expand Up @@ -310,10 +311,36 @@ NAN_METHOD(Matrix::GetData) {

}

NAN_METHOD(Matrix::Brightness){
NanScope();

if (args.Length() == 2){
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
cv::Mat image = self->mat;
cv::Mat new_image = cv::Mat::zeros( image.size(), image.type() );
double alpha = args[0]->NumberValue();
int beta = args[1]->IntegerValue();
/// Do the operation new_image(i,j) = alpha*image(i,j) + beta
for( int y = 0; y < image.rows; y++ ){
for( int x = 0; x < image.cols; x++ ){
for( int c = 0; c < 3; c++ ){
new_image.at<cv::Vec3b>(y,x)[c] = cv::saturate_cast<uchar>( alpha*( image.at<cv::Vec3b>(y,x)[c] ) + beta );
}
}
}
new_image.copyTo(self->mat);
}else{
NanReturnValue(NanNew("Insufficient or wrong arguments"));
}


NanReturnNull();
}

// @author tualo
// normalize wrapper
NAN_METHOD(Matrix::Normalize) {
NanScope();


if (!args[0]->IsNumber())
NanThrowTypeError("min is required (argument 1)");
Expand Down
1 change: 1 addition & 0 deletions src/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Matrix: public node::ObjectWrap {

JSFUNC(GetData)
JSFUNC(Normalize)
JSFUNC(Brightness)

JSFUNC(Row)
JSFUNC(PixelRow)
Expand Down

0 comments on commit f9d5c8a

Please sign in to comment.