detect lines in image matlab

794 views Asked by At

Hello I have a work on this image:

example image containing sperm

My objective is to count all the sperm in this image .for this I'm thinking to detect just the lines so it make my work easy. because I am beginner, in this step I am completely lost there are any algorithms can help me to detect lines?? ( I have seen that there are hough transformation and scan line algorithm) I don't which algorithm can help me and if there are others

1

There are 1 answers

2
Nino Pereira On

Here's a piece of code that might help you getting started. By looking at the image it seems very difficult to label sperms by looking at straight lines and hence using Hough transform won't help a lot. In the example below I focused on filtering the image and counting the number of blobs. The code is commented and should be easy to understand.

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