필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
osamah almasiri
osamah almasiri 2017년 5월 7일
답변: samundeeswari p 2018년 8월 8일
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!!!

답변 (2개)

Stephen23
Stephen23 2017년 5월 7일
편집: Stephen23 2017년 5월 7일
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 2018년 8월 8일
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