MATLAB error: subsindex function is not defined for values ​​of class 'struct'

I tried these commands:

im=imread('untitled_test1.jpg'); im1=rgb2gray(im); im1=medfilt2(im1,[15 15]); BW = edge(im1,'sobel'); msk=[0 0 0 0 0; 0 1 1 1 0; 0 1 1 1 0; 0 1 1 1 0; 0 0 0 0 0;]; B=conv2(double(BW),double(msk)); Ibw = im2bw(B); CC = bwconncomp(Ibw); %Ibw is my binary image stats = regionprops(CC,'pixellist'); % pass all over the stats for i=1:length(stats), size = length(stats(i).PixelList); % check only the relevant stats (the black ellipses) if size >150 && size < 600 % fill the black pixel by white x = round(mean(stats(i).PixelList(:,2))); y = round(mean(stats(i).PixelList(:,1))); Ibw = imfill(Ibw, [x, y]); else Ibw([CC.PixelIdxList{i}]) = false; end; end; 

(I have other command lines here, but I think the problem is not because of them.)

 labeledImage = bwlabel(binaryImage, 8); % Label each blob so we can make measurements of it blobMeasurements = regionprops(labeledImage, Ibw, 'all'); numberOfBlobs = size(blobMeasurements, 1); 

I got this error message:

 ??? Error using ==> subsindex Function 'subsindex' is not defined for values of class 'struct'. Error in ==> test2 at 129 numberOfBlobs = size(blobMeasurements, 1); 

What will go wrong?

+6
source share
2 answers

You get this error because you created a variable called "size" that hides the built-in SIZE function. Instead of calling a function to calculate numberOfBlobs , MATLAB instead tries to index the variable using the blobMeasurements structure as an index (which does not work as the error message shows).

In general, you should not specify a variable or function the name of an existing function (unless you know what you are doing ). Just change the name of the variable in your code to something other than "size", enter the clear size command to clear the old size variable from the workspace and repeat your code.

+17
source

The error message states that the error is in numberOfBlobs = size(blobMeasurements, 1); . subsindex most likely used in size(..., 1) to access these elements.

I assume that blobMeasurements is an array of structures (or one structure) for which this operation is not completely defined.

Why don't you use the length command as before? This worked a bit in your code.

+1
source

Source: https://habr.com/ru/post/912681/


All Articles