擅长:python、mysql、java
<pre><code>IT is easy in OpenCV. as mentioned a very common way is defining a threshold, But your result looks like you are allocating random values to your intensities instead of thresholding it.
import cv2
im = cv2.imread('brain.png', cv2.CV_LOAD_IMAGE_GRAYSCALE)
(th, brain_bw) = cv2.threshold(imy, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
th = (DEFINE HERE)
im_bin = cv2.threshold(im, th, 255, cv
cv2.imwrite('binBrain.png', brain_bw)
</code></pre>
<p><a href="https://i.stack.imgur.com/Z3MeS.png" rel="nofollow noreferrer">brain</a></p>
<p><a href="https://i.stack.imgur.com/Wn4te.png" rel="nofollow noreferrer">binBrain</a></p>