Hi,
I am working on thresholding an image (code included below). The threshold works well but includes several smaller pieces that are not helpful for the final analysis. Is there a way to get rid of these? Thanks in advance!
img = imread('25_04_2018_102541.JPG');imgGrey = rgb2gray(img);[counts, ~] = imhist(imgGrey, 255);T = otsuthresh(counts);BW = imbinarize(imgGrey, T);BW = bwareaopen(BW, 3000);BW = imfill(BW, 'holes');BW = bwperim(BW);BW = imdilate(BW, ones(5));BW = imerode(BW, ones(3));BW = imfill(BW, 'holes');img(~BW(:,:,[1 1 1])) = 0;baseGray = rgb2gray(img);isoLower = 155;isoUpper = 170;mask = (baseGray > isoLower) & (baseGray < isoUpper);img(~mask(:,:,[1 1 1])) = 0;
Best Answer