Hi Dekel,
It is my understanding that you are working on an image processing application and require guidance to resolve the problem of filtering out white images. The problem you are facing will not be relevant to MATLAB and might be something else. The effectiveness of your code may vary depending on the image characteristics. You may need to adjust the threshold values, morphological operations and other parameters to achieve optimum results.