Active Contour run time warning

Why I get a warning while using active contour in MATLAB?
Warning: Iterations terminated prematurely because no part of the contour lies within the image domain. If the range of pixel values in the input image is small (such as 0-1)

8 Comments

The warning tells you why it's appearing. We cannot explain why this is happening without more info such as the image, inputs to activecontour, etc.
Thank you so much for your answer. I am using the following code,
{
mask = logical(Image);
bw = activecontour(Image,mask,500,'Edge','SmoothFactor',1.5);
}
The contour method cannot converge towards the edge of the dark object beacuse of premature termination of the iterations.
What is "Image"? I see that there's an attachment named Image.png and I assume the variable Image stores the image data of that file but how are you reading it in?
Since you're applying logical() I assume the image data are binary.
Thank you so much for your prompt reply and apology for my mistake.
The mask is the bounding box of the dark object and is logical. I want to segment the dark object using active contour segmentation. It works, but due to premature termination of iteration, it can't converge to the object exactly.
mask = logical(BoundingBox);
bw = activecontour(Image,mask,500,'Edge','SmoothFactor',1.5);
Exactly? Do you mean that there is an exact solution? Where exactly is the border of that blurry smooth shape? Can you indicate it in a red curve? It looks like a judgment call to me. What about simply thresholding and calling bwboundary()?
boundary = bwboundaries(grayImage < someGrayLevel);
Now I have the same question for "BoundingBox". What is it? I understand it was created using mask.png and that it's probably a binary matrix but we can't be sure without having the line of code you used to read in that file and create 'BoundingBox'.
The mask is some initial shape for the activecontour() function. See my attached demo.
You've always got great demos, Image Analyst.
I'd like the OP to share how BoundinBox was created to eliminate that step as a possible cause of the problem and to ensure that we're identically replicating the problem. That would only be 2-3 lines from your demo,
grayImage = imread(fullFileName);
mask = grayImage > thresholdValue;
And for the composite mask,
mask = bwconvhull(mask, 'Union');

Sign in to comment.

 Accepted Answer

Tamoor Aziz
Tamoor Aziz on 3 Jan 2021
Edited: Tamoor Aziz on 3 Jan 2021
@Image Analyst, thank you so much for your reply. Exactly, My problem is the same as you described in https://www.mathworks.com/matlabcentral/answers/705903-active-contour-run-time-warning#comment_1240593.
According to my understanding, if you increase the number of iteration then you will get the accurate final outer boundary of the object in the "Original Grayscale Image".
But, I don't have problem about the contour segmentation. Please help me with my problem. If I use 400 number of iterations, the contour segmentation process stops before than 400 iterations and it generates the warning! Why I get a warning while using active contour in MATLAB?
Warning: Iterations terminated prematurely because no part of the contour lies within the image domain. If the range of pixel values in the input image is small (such as 0-1)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!