-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 ?

Mahavir
  • 771
  • 3
  • 9
  • 23
  • Could you clarify your question further? I've posted one possible solution, but your question doesn't specify exactly what your problem is. – Aurelius Jun 23 '14 at 19:20
  • possible duplicate of [How to use the OTSU Threshold in opencv?](http://stackoverflow.com/questions/17141535/how-to-use-the-otsu-threshold-in-opencv) – Aurelius Jun 23 '14 at 19:21

1 Answers1

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);
Aurelius
  • 11,111
  • 3
  • 52
  • 69