Binarizing image with single pixels

1 view (last 30 days)
Mat
Mat on 29 Jan 2024
Answered: Animesh on 30 Jan 2024
I have some photos of random pixels marked on a low noisy background. I want to binarize the image, in order to have a clear array of 0s and 1s, and I would like to make each spot as one element of the matrix.
What I did was to grayscale the image, and then try to binarize it. Unfortunately, it is not enough. Adding Adaptive histeresys equalisation (Ae = adapthisteq(Ag);) makes it worst. Maybe strel function could help?
Thanks
This is my code. I think code will be similar to datamatrix and QR code reading.
Thank you
if dim ~= 1
Ag = rgb2gray(photo);
else
Ag = photo;
end
Ab=imbinarize(Ag);

Answers (1)

Animesh
Animesh on 30 Jan 2024
Hi @Mat
If you're working with an image that has random pixels against a faintly noisy background and wish to detect those random pixels, you can employ morphological operations to enhance the features of the spots and distinguish them from the background noise.
A suggested approach you can try is:
Step 1: Convert the image to greyscale (if not already).
Step 2: Apply a filter to reduce noise.
Step 3: Binarize the image using thresholding.
Step 4: Use morphological operations to clean up the image and isolate the spots.
You can refer to the following documentation on morphological operations:

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!