Blob detection using OpenCV
<p>I am trying to do some white blob detection using OpenCV. But my script failed to detect the big white block which is my goal while some small blobs are detected. I am new to OpenCV, and am i doing something wrong when using simpleblobdetection in OpenCV? [Solved partially, please read below]</p>

<p>And here is the script:</p>

<pre><code>#!/usr/bin/python

# Standard imports
import cv2
import numpy as np;

from matplotlib import pyplot as plt

# Read image
im = cv2.imread('whiteborder.jpg', cv2.IMREAD_GRAYSCALE)
imfiltered = cv2.inRange(im,255,255)

#OPENING
kernel = np.ones((5,5))

opening = cv2.morphologyEx(imfiltered,cv2.MORPH_OPEN,kernel)

#write out the filtered image

cv2.imwrite('colorfiltered.jpg',opening)


# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()

params.blobColor= 255
params.filterByColor = True


# Create a detector with the parameters
ver = (cv2.__version__).split('.')
if int(ver[0]) &lt; 3 :
    detector = cv2.SimpleBlobDetector(params)
else : 
    detector = cv2.SimpleBlobDetector_create(params)


# Detect blobs.
keypoints = detector.detect(opening)

# Draw detected blobs as green circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures
# the size of the circle corresponds to the size of blob

print str(keypoints)

im_with_keypoints = cv2.drawKeypoints(opening, keypoints, np.array([]), (0,255,0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

# Show blobs
##cv2.imshow("Keypoints", im_with_keypoints)

cv2.imwrite('Keypoints.jpg',im_with_keypoints)

cv2.waitKey(0)
</code></pre>

<p><strong>EDIT</strong>:</p>

<p>By adding a bigger value of area maximum value, i am able to identify a big blob but my end goal is to identify the big white rectangle exist or not. And the white blob detection i did returns not only the rectangle but also the surrounding areas as well. [This part solved]</p>

<p><strong>EDIT 2:</strong></p>

<p>Based on the answer from @PSchn, i update my code to apply the logic, first set the color filter to only get the white pixels and then remove the noise point using opening. It works for the sample data and i can successfully get the keypoint after blob detection. 
<a href="http://i.stack.imgur.com/U2TRP.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/U2TRP.jpg" alt="enter image description here"></a></p>

<p>If you just want to detect the white rectangle you can try to set a higher threshold, e.g. 253, erase small object with an opening and take the biggest blob. I first smoothed your image, then thresholding it:</p>

<p><a href="http://i.stack.imgur.com/UrrBT.png" rel="nofollow"><img src="http://i.stack.imgur.com/UrrBT.png" alt="enter image description here"></a></p>

<p>and the opening:</p>

<p><a href="http://i.stack.imgur.com/LNEBf.png" rel="nofollow"><img src="http://i.stack.imgur.com/LNEBf.png" alt="enter image description here"></a></p>

<p>now you just have to use <code>findContours</code> and take the <code>boundingRect</code>. If your rectangle is always that white it should work. If you get lower then 251 with your threshold the other small blobs will appear and your region merges with them, like here:</p>

<p><a href="http://i.stack.imgur.com/GB6iM.png" rel="nofollow"><img src="http://i.stack.imgur.com/GB6iM.png" alt="enter image description here"></a></p>

<p>Then you could still do an opening several times and you get this:
<a href="http://i.stack.imgur.com/oKWJT.png" rel="nofollow"><img src="http://i.stack.imgur.com/oKWJT.png" alt="enter image description here"></a></p>

<p>But i dont think that it is the fastest idea ;)</p>

python opencv