MATLAB: Remove noise from screw image

image processingImage Processing Toolboxmachine visionnoise removal

The screw image shown below has some dust/fur on the screw thread. What are the ways to remove those noise and produce a new image with clear outline of the screw?
20.bmp
I tried it myself and came out result as shown below.
Some of the noises are still not removed. I have also attached my codes as shown below.
clc
clear
close all
%% Read
A = imread('20.bmp');
%% Turn into grayscale
I0 = rgb2gray(A);
%% Crop
I1 = imcrop(I0,[1,78,710-1,410-78]);
%% Histogram
[pixelCount, grayLevels] = imhist(I0);
%% Adjustment
I2 = imadjust(I1);
I3 = medfilt2(I2);
ThresholdValue = graythresh(I3);
I4 = imbinarize(I3, ThresholdValue);
I5 = edge(I4,'Sobel');

Best Answer

The screw and the threads are the black thing and the dust is the lighter things on it. I think you are just using the wrong threshold. You can adjust it in imbinarize(), or you can do it interactively with my interactive thresholding app in my File Exchange.