Why do I not get a good binary image with a grey background using the mahotas python module?
Question: I got some problems with image with grey background with mahotas library:

Example:![input image](http://i.stack.imgur.com/e3fWs.jpg)

This is the code:

    
    
    import mahotas as mh
    path ="./imagepath/a.jpg"
    fork = mh.imread(path)  
    bin = fork[:,:,0]
    bfork = bin <230
    

After that i got that: ![output image](http://i.stack.imgur.com/37qgn.png)

What have i do for getting a black background and a white sign? I tried in
opencv module and was good, but i prefer mahotas.

    
    
    import cv2
    path ="./imagepath/a.jpg"
    ow =  int ((oshape[0]/100 )*7 )
    oh =  int ((oshape[0]/100 )*7 )
    gray = cv2.imread(path,0)
    element = cv2.getStructuringElement(cv2.MORPH_CROSS,(ow,oh)) 
    graydilate = cv2.erode(gray, element) 
    ret,thresh = cv2.threshold(graydilate,127,255,cv2.THRESH_BINARY_INV) 
    bin = thresh
    


Answer: You are not doing the same as in the opencv version. If you do, you'll get the
wanted results:

    
    
    fork = mh.imread(path)
    bin = fork[:,:,0]
    bin = mh.erode(bin)
    bin = (bin < 127)
    

The erosion step was missing and the threshold was different.

    
    
    from matplotlib import pyplot as plt
    plt.imshow(bin)
    plt.gray()
    

![Binarized fork](http://i.stack.imgur.com/NwVf4.png)

