-2

I'm trying to convert a image to black and white, so that anything not absolutely black is white, and use this as a mask.

+ (UIImage *) getBlackAndWhiteImage:(UIImage *)image;
    {

      IplImage* im_rgb = [self CreateIplImageFromUIImage:image];
      IplImage *im_gray = cvCreateImage(cvGetSize(im_rgb),IPL_DEPTH_8U,1);
     cvCvtColor(im_rgb,im_gray,CV_RGB2GRAY);

     IplImage* im_bw = cvCreateImage(cvGetSize(im_gray),IPL_DEPTH_8U,1);
    cvThreshold(im_gray, im_bw, 127, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); 
//    I have change 127 to 10 :255 that has no effect
    return [self UIImageFromIplImage:im_bw];
  }

How can i get the proper black and whilte image ?

2

1 Answer 1

1

Don't pass CV_THRESH_OTSU to cvThreshold(). If you pass this flag, the provided threshold will be ignored and Otsu's method will be used instead, which automatically selects a threshold.

Your invocation should look like this:

cvThreshold(im_gray, im_bw, 127, 255, CV_THRESH_BINARY);
1
  • Aside: please use the C++ API, not the horrific C one.
    – Aurelius
    Jun 23, 2014 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.