Effacer les filtres
Effacer les filtres

Function 'subsindex' is not defined for values of class 'cell'.

1 vue (au cours des 30 derniers jours)
osamah almasiri
osamah almasiri le 7 Mai 2017
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!!!

Réponses (2)

Stephen23
Stephen23 le 7 Mai 2017
Modifié(e) : Stephen23 le 7 Mai 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.

samundeeswari p
samundeeswari p le 8 Août 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..

Community Treasure Hunt

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

Start Hunting!

Translated by