how to fix Cell contents assignment to a non-cell array object.?
조회 수: 2 (최근 30일)
이전 댓글 표시
hallo I'm trying to create a 2D by N dimentions pictures features array to save code running time so i created the next code:
SurfFeatures = {};
folderlisting = dir('C:\Documents\');
for item=3:1:numel(folderlisting)
name = folderlisting(item).name;
Fname = strcat('C:\Documents\',name);
comperimg = imread(Fname);
comperimg = comperimg(:,:,1:3);
I = rgb2gray(comperimg);
points = detectSURFFeatures(I);
[features,valid_points] = extractFeatures(I,points);
SurfFeatures{item-2} = features;
end
save('SurfFeatures.mat','SurfFeatures');
I keep getting the next error right after the code enters the part of the feature assignment "Cell contents assignment to a non-cell array object."
happy for help :) .
댓글 수: 3
OCDER
2017년 10월 20일
편집: OCDER
2017년 10월 20일
I don't see anything wrong, but perhaps the error is in extractFeatures or detectSURFFeatures. Here are some tips to improve the code though.
FolderList = dir(fullfile('C:\Documents\', '*.jpg')); %Use file extensions since dir will also return "." and ".." folders, + other files
SurfFeatures = cell(1, numel(FolderList) - 2); %Preallocate for speed
for item = 3:numel(FolderList)
%name = FolderList(item).name; %Uppercase notation. Also, this isn't needed.
%Fname = strcat('C:\Documents\',name); %fullfile is better
%comperimg = imread(Fname);
%comperimg = comperimg(:,:,1:3); %squeeze will remove singleton dimension
Fname = fullfile('C:\Documents\',FolderList(item).name);
I = squeeze(imread(Fname));
I = rgb2gray(I);
Points = detectSURFFeatures(I);
[Features, ValidPoints] = extractFeatures(I, Points);
SurfFeatures{item-2} = Features;
end
save('SurfFeatures.mat','SurfFeatures');
Be consistent when using camelcase notation to help you determine what is a function vs variable. I noticed a partial implementation, which can get confusing later (ex: valid_points vs ValidPoints). Using uppercase is generally good for variables, to prevent overriding a matlab function by accident. You're function naming scheme is fine
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!