Segment Image of Small Elements on Neutral Background

I have a 8 bit gray level image where if the value = 122 it means no information, value = 0 means highly negative, and value = 255 means highly positive. I want to connect as many positive information pixels with each other as possible to form as large an area as possible (and not let accidental negative values affect it), and get all the contour of it (which I will then filter out based on # of positive dots and total area of the contour). The ideal contours are the red lines I have drawn onto the image above, and the full image is below.

What is the best strategy to go about doing this?

The 3rd image is a zoomed in view of the image to show the pixels after filtering / processing just looks like that.

[3

• have you got actual data or just this resampled image? people are going to need something to experiment with, if you don't just want random ideas. -- something based on a median might serve the purpose. I don't mean just applying a median kernel. Commented Jan 11, 2023 at 8:36
• The 2nd png image is the actual data. I normalized the values to 0 - 255, with 0 being definitely negative, 255 being definitely positive, and the middle level being no information. Commented Jan 11, 2023 at 14:41
• those pixels look resampled/resized. is this a screenshot? that picture definitely doesn't just contain three levels (black, white, single middle level) Commented Jan 11, 2023 at 14:46
• Nope this is indeed the actual image, here's a zoomed in view of the actual pixels Commented Jan 11, 2023 at 14:49
• how is this image made? is resizing/resampling happening at any place in the previous processing? Commented Jan 11, 2023 at 14:49

The idea I have is as following:

1. Treat data as a density measure.
2. Values > 122, positive density, Values < 122 negative.
3. Cluster them by threshold.

This is how it goes:

1. Scale image into [0, 1] range.
2. Shift the values by 122 / 255 so zero value are zero.
3. Convolve with Gaussian Kernel.
4. Apply threshold.
5. Clean small artifacts.
6. Do connected components.
7. Draw contour of connected components.

I will show steps 1-4.

• The input image

• The surface after convolution (Hills and valleys)

• Image after thresholding (Basically which have the same baseline of density)

What I'd do next to finish this:

1. Tweak parameters.
2. Clean small artifacts using morphological operations.
3. Draw the contours bases on the connected components.

The MATLAB code:

clear();
close('all');

zeroLvl = 122 / 255;
thrLvl = 0.01;

mI = mI(:, :, 1);
mI = im2double(mI);

figure();
imshow(mI);

mK = fspecial('gaussian', [25, 25], 4.5);

mB = mI - zeroLvl;
mP = imfilter(mB, mK, 'replicate');

figure();
surf(mP, 'EdgeColor', 'none');

mT = mP > thrLvl;

figure();
imshow(mT);

sCC = bwconncomp(mT);
figure();
contour(mP);