Function 'subsindex' is not defined for values of class 'cell'.
1 view (last 30 days)
Show older comments
Hi, I have tried to run my code which is thresholding and segmentation of a BW image and display each object in the image separately :
clear all
close all
clc
I=imread('brain.jpg');
I=rgb2gray(I);
I2=threshold(I);
cc=bwconncomp(I2,8);
n=cc.NumObjects;
area= zeros(n,1);
premimeter=zeros(n,1);
majoraxis=zeros(n,1);
minoraxis=zeros(n,1);
K= regionprops(cc,'Area','Perimeter','MajorAxisLength','MinorAxisLength');
for i=1:n
obj=zeros(size(I2));
obj(cc.PixelIdxList(i))=1;
figure(i);
imshow(obj);
area(i)=K(i).Area;
premimeter(i)=K(i).Perimeter;
majoraxis(i)=K(i).MajorAxisLength;
minoraxis(i)=K(i).MinorAxisLength;
end
however i got an Err messages says :
(Function 'subsindex' is not defined for values of class 'cell'.
Error in Segmentation (line 17)
obj(cc.PixelIdxList(i))=1;)
I have checked cc(struct) and checked the PixelIdxList cell,it is defined and nothing wrong with it !! i am not sure what is the wrong in this code!!!
0 Comments
Answers (2)
Stephen23
on 7 May 2017
Edited: Stephen23
on 7 May 2017
The problem is simple: cc.PixelIdxList(i) is a cell array, and cell arrays cannot be used for indexing.
The bxconncomp documentation clearly shows explains that output: " PixelIdxList 1-by-NumObjects cell array where..."
An index must be numeric or logical: it cannot be of class cell, struct, table, ...
To fix this you will have to decide how you want to process the zero or more identified objects. A loop would be the obvious starting point.
0 Comments
samundeeswari p
on 8 Aug 2018
instead of using this instruction obj(cc.PixelIdxList(i))=1; try this obj(cc.PixelIdxList{i})=1;
for class cell we need to use {} bracket
am sure this will help you..
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!