2012-04-08 12 views
6

मैंने कोशिश के मूल्यों इन आदेशों के लिए निर्धारित नहीं है:MATLAB त्रुटि: समारोह 'subsindex' क्लास 'struct'

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; 

(यहाँ मैं एक कमांड लाइन है, लेकिन मुझे लगता है कि समस्या उनकी वजह से नहीं है ।)

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

मैं इस त्रुटि संदेश मिला:

??? Error using ==> subsindex 
Function 'subsindex' is not defined for values of class 'struct'. 

Error in ==> test2 at 129 
numberOfBlobs = size(blobMeasurements, 1); 

गलत क्या हो रहा है?

उत्तर

17

आप उस त्रुटि हो रही है, क्योंकि आप एक चर बुलाया "आकार" जो निर्मित में छाया समारोहSIZE बनाया है। इसके बजाय गणना करने के लिए numberOfBlobsसमारोह बुलाने की, MATLAB बजाय (, जो काम नहीं करता है के रूप में त्रुटि संदेश से पता चलता) सूचकांक चर एक सूचकांक के रूप में संरचना blobMeasurements का उपयोग कर की कोशिश करता है।

सामान्य रूप से, आपको एक चर नहीं देना चाहिए या पहले से मौजूद फ़ंक्शन का नाम नहीं देना चाहिए (जब तक कि आप know what you're doing)। बस अपने आकार में चर के नाम को "आकार" के अलावा किसी अन्य चीज़ में बदलें, वर्कस्पेस से पुराने आकार चर को साफ़ करने के लिए clear size आदेश जारी करें, और अपना कोड दोबारा शुरू करें।

1

आपका त्रुटि संदेश आपको बताता है कि त्रुटि numberOfBlobs = size(blobMeasurements, 1); में है। subsindex उन तत्वों तक पहुंचने के लिए size(..., 1) में सबसे अधिक उपयोग किया जाता है।

मुझे लगता है कि blobMeasurements structs (या एक एकल संरचना) की एक सरणी है, जिसके लिए वह ऑपरेशन पूरी तरह परिभाषित नहीं है।

आप length कमांड का उपयोग पहले क्यों नहीं करते? यह आपके कोड में थोड़ा पहले काम किया था।

संबंधित मुद्दे