How to detect the areas within the curves and remove them from the image?

3 vues (au cours des 30 derniers jours)
I would like to detect the the curves in the attached images and remove the enclosed area from the curve, so that, only the tiny white spots remain in the images. I took an attempt to do the job and come up with the first attachment (detected the curve). I could not remove the marked from the image. Your suggestions is highly appreciated.

Réponse acceptée

Shubh
Shubh le 28 Déc 2023
Modifié(e) : Shubh le 28 Déc 2023
Hi,
I understand that you want to remove the marked spots from the image.
You can follow these steps:
  1. Read the images using "imread".
  2. If the images are not already in grayscale, convert them using "rgb2gray".
  3. Apply a binary threshold using "imbinarize" with Otsu's method.
  4. Remove noise by filtering out small objects with "bwareaopen".
  5. Label the connected components with bwlabel or "bwconncomp".
  6. Identify the largest connected component which is likely to be the curve.
  7. Remove the largest connected component from the binary image.
  8. Display the results using "imshow".
Here's the MATLAB code for processing the images:
% Read the images
image1 = imread('path_to_your_first_image.jpg');
image2 = imread('path_to_your_second_image.jpg');
% Convert images to grayscale if they are in RGB
if size(image1, 3) == 3
image1 = rgb2gray(image1);
end
if size(image2, 3) == 3
image2 = rgb2gray(image2);
end
% Binarize images using Otsu's threshold
bw1 = imbinarize(image1);
bw2 = imbinarize(image2);
% Remove small objects (noise)
cleaned1 = bwareaopen(bw1, 50);
cleaned2 = bwareaopen(bw2, 50);
% Label connected components
[label1, num1] = bwlabel(cleaned1);
[label2, num2] = bwlabel(cleaned2);
% Find the largest component for each image
stats1 = regionprops(label1, 'Area');
stats2 = regionprops(label2, 'Area');
[~, largestIdx1] = max([stats1.Area]);
[~, largestIdx2] = max([stats2.Area]);
% Remove the largest component from the images
final1 = cleaned1;
final2 = cleaned2;
final1(label1 == largestIdx1) = 0;
final2(label2 == largestIdx2) = 0;
% Display the results
figure;
subplot(2,2,1), imshow(final1), title('Final Image 1');
subplot(2,2,2), imshow(final2), title('Final Image 2');
Hope this helps!
  1 commentaire
Debasish Sarker
Debasish Sarker le 11 Jan 2024
Sorry for late response. Yes, it really helps. Thank you very much for the algorithm. I was actually trying to adopt the algorithm for other frames. It successfully keeps the white spots in the images. However, I also need to know the area within the marked spots or area enclosed by the curved line. I have attached a couple of images, if you can help me with them.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by