MATLAB: Removing unwanted pixels

image processsing

I have an image
in which i need only the text ,i want to remove extra whitr regions around the text.please help

Best Answer

  • Im = imread('Q8.png');
    BW = im2bw(Im,graythresh(Im));
    bw1 = imdilate(BW,[0 0 0 0 1 1 1 1]);
    s = regionprops(bw1,'Area');
    k = sort([s.Area],'descend');
    bw2 = bwareaopen(bw1, k(2)-1);
    bw3 = imfill(bw2,'holes');
    bwOut = bw3 & BW;
    imshow(bwOut)