检测图像matlab中的线条

时间:2016-12-28 10:11:38

标签: matlab count lines detect

你好,我有关于这张图片的工作:

example image containing sperm

我的目标是计算这张图片中的所有精子。为此,我想要只检测线条,以便让我的工作变得轻松。因为我是初学者,在这一步我完全迷失了有什么算法可以帮我检测线路? (我已经看到有hough变换和扫描线算法)我不知道哪种算法可以帮助我,如果还有其他算法

1 个答案:

答案 0 :(得分:0)

这是一段可能有助于您入门的代码。 通过观察图像,通过观察直线来标记精子似乎非常困难,因此使用霍夫变换不会有太大帮助。 在下面的例子中,我专注于过滤图像和计算blob的数量。代码已注释,应易于理解。

img = imread('d9S3Z.png');
figure, imshow(img)

% convert to binary image
[X,map] = rgb2ind(img,0.0);
img = ind2gray(X,map);    % Convert indexed to grayscale
level = graythresh(img);   % Compute an appropriate threshold
% or use your own, e.g. level = 0.46
img_bw = im2bw(img,level);% Convert grayscale to binary

% create mask to remove edge interference
mask = zeros(size(img_bw));
mask(2:end-2,2:end-2) = 1;
img_bw(mask<1) = 1;

%invert image
img_inv =1-img_bw;

% find blobs
img_blobs = bwmorph(img_inv,'majority',10);
figure, imshow(img_blobs);

% count blobs
CC = bwconncomp(img_blobs);
num_sperm = CC.NumObjects # sperm count