Integer Operand Warning when casting output of RegionProps

So I am getting the rather common "Integer operands are required for colon operator when used as index" warning, however it is triggering on code that doesn't even use the colon operator.
It triggers on the second line of the code below:
stats = regionprops(double(thisregion),'boundingbox');
bnds = stats.BoundingBox;
Furthermore, the warning is flagged twice on this line, so I am wondering if something is wrong internal to a function? Is there something I can do to fix this, as the code is within a loop so the warning messages cause a serious slowdown.

 Réponse acceptée

Image Analyst
Image Analyst le 20 Nov 2017
Modifié(e) : Image Analyst le 20 Nov 2017
What is thisRegion? I'm guessing it's a binary image. If so, you would not cast it to double when you pass it in to regionprops.
Also, what is the length of stats? Are you SURE it's only 1? If it's multiple, do this
allBoundingBoxes = [stats.BoundingBox];

3 commentaires

Alex Burden
Alex Burden le 20 Nov 2017
Modifié(e) : Alex Burden le 20 Nov 2017
The cast to double is so that regionprops treats the input as a label matrix. Since everything in the image is 0 or 1, even if there were two distinct connected components they would be treated as the same object (as they have the same label). There shouldn't ever be more than one connected component, but I would rather not risk my code crashing because something wonky happened when the binary image was formed (earlier in my code).
I can confirm that there is only a single region when testing this code. When run without the semicolons stats returns as follows:
stats =
BoundingBox: [1x4 double]
I also tried running this written as stats(1).BoundingBox with no effect.
Note that when I run each line individually in command line I get no warnings, it only happens within my GUI.
Well that doesn't make sense. And there is no way for me to figure out what's going on unless you attach the .fig and .m files.
I have identified the problem after running my GUI in Matlab 2017B (I was on 2014B when the problem first occurred).
Apparently, the statement that was triggering the warning was about 10 lines further down, when I assigned the region to a struct
Spaces(i).region = thisregion(bnds(2):bnds(2)+bnds(4),bnds(1):bnds(1)+bnds(3));
For whatever reason, in 2014B the warning pointed to a line about 10 lines further up, however once I added a round() command they have dissipated.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Conway's Game of Life dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by