|
Hi Lee,
imclose may get you a little nearer - it should close up the circles that are almost complete, but it won't help with the others.
You're right about complete edges and regionprops. If bw is your binary image containing outlines, you can use something like:
bw = imclose(bw, ones(3));
im_lab = bwlabel(~bw);
regionprops(im_lab, [whatever properties you need]);
Note that the background will also be given a label this way, which probably won't be very useful - so you'll need to find and disregard it. An alternative to imfill to see which complete cells have been found is to look at
imshow(label2rgb(im_lab, 'jet', 'w', 'shuffle'));
Sorry I don't have anything ingenious or sophisticated to suggest for the main problem of the circles with big gaps. To get something usable more quickly, you could perhaps allow the user to draw in extra lines to complete the cells. Some rather inglorious code for that might be:
bw = imclose(bw, ones(3));
% Loop until the user double clicks the same place rather than draws a line
while true
% Show the detected cells
im_lab = bwlabel(~bw, 4);
imshow(label2rgb(im_lab, 'jet', 'w', 'shuffle'));
% Get the end points of a line from the user
% (should add some check to make sure the line is within the image bounds)
[x, y] = getline;
% Check for double click
if numel(x) == 1
break;
end;
% Only keep the first two points (this is cheating)
x = x(1:2);
y = y(1:2);
% Calculate the line length
len = ceil(hypot(diff(x), diff(y)));
% Figure out the linear indices of the pixels in the edge image that need set to 1
% (doubles length just to be very sure no gaps in the line... inefficiently)
cols = round(linspace(x(1), x(2), len*2));
rows = round(linspace(y(1), y(2), len*2));
inds = sub2ind(size(bw), rows, cols);
% Update the image
bw(inds) = true;
end
There are, no doubt, many better ways to achieve that goal. I tested it briefly - while the code isn't great, the initial results seemed ok. It could be very much improved, for example, by allowing the user to add multiple line segments (not just one at a time), relating the line to image pixels more efficiently, and storing the coordinates of manually added line segments to allow for an 'undo' option.
Pete
|