Is there a way to clean the image such that the smaller pieces are not included?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Teshan Rezel
le 24 Juin 2020
Réponse apportée : Puru Kathuria
le 14 Juil 2020
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;
![Original Image](https://www.mathworks.com/matlabcentral/answers/uploaded_files/321181/Original%20Image.jpeg)
![Image after background thresholding](https://www.mathworks.com/matlabcentral/answers/uploaded_files/321184/Image%20after%20background%20thresholding.jpeg)
![Image I need to clean](https://www.mathworks.com/matlabcentral/answers/uploaded_files/321187/Image%20I%20need%20to%20clean.png)
Réponse acceptée
Puru Kathuria
le 14 Juil 2020
Hi,
I understand what you are trying to achieve, please have a look at this. It might help you filter out the smaller pieces that you dont need.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Computer Vision with Simulink dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!