bpgeck
bpgeck

Reputation: 1624

Get regions within black border of image

I begin with the following image:

Initial image

I perform local thresholding by comparing a pixel to its neighborhood mean. I also crop out the white border surrounding the image after this local thresholding with the following code:

I = imread('img_path');
N = 21;
localMean = conv2(double(I), double(1/(N^2) * ones(N)), 'same');
BW = I > localMean;
borderSize = ceil(double(N) / 2);
R = [borderSize, borderSize, size(BW, 2) - 2*borderSize, size(BW, 1) - 2*borderSize];
BW = imcrop(BW, R);

This leaves me with the following image:

Segmented Cells

As you can see, there is a clear black border surrounding each of the segmented cells. How do I go about removing all things in this image OTHER than those regions within the black border?

If this is not possible, then are there any other techniques I should take a look at that might make give my local thresholding less noise?

Any help is appreciated.

Upvotes: 0

Views: 74

Answers (1)

user2999345
user2999345

Reputation: 4195

you can use Otsu's thresholding (graythresh) and morphological operations:

im = im2double(imread('cells.png'));
% otsu thresholding
t = graythresh(im);
bw = im > t;
% morphological open to remove small noise
bw = imopen(bw,strel('disk',5,0));
% fill holes to form solid objects
bw = imfill(bw,'holes');
% show
imshow(bw)

enter image description here

Upvotes: 1

Related Questions