|
"Roger Stafford" wrote in message <j0244j$rg1$1@newscl01ah.mathworks.com>...
> "patricia " <tishi@live.co.uk> wrote in message <j0205b$f2k$1@newscl01ah.mathworks.com>...
> > .........
> > for c=size(A,2) % Number of columns
> > for r=size(A,1); %Number of rows
> > R = A(r:r+2, c:c+2);
> > %Extract the features
> > FM(regionNum, 1) = mean(mean(I));
> > FM(regionNum, 2) = std2(I);
> > regionNum = regionNum +1;
> > end
> > end
> > .........
> - - - - - - - - - -
> I see at least three problems here:
>
> 1. When c is equal to size(A,2) then A(~,c+1) and A(~,c+2) are outside its range. The same is true when r is equal to size(A,1).
>
> 2. The indices c and r are clearly intended to range starting from 1, but this code just uses the end value for each one.
>
> The problems in 1. and 2. would be corrected by writing:
>
> for c = 1:size(A,2)-2
> for r = 1:size(A,1)-2
>
> 3. After obtaining the 3 x 3 region in R, the subsequent code does not use R but references a matrix called 'I', so no use is made of R in the for-loops.
>
> Roger Stafford
Hi Roger
Thanks for your help, i am newto matlab and just trying to get my head round it all. I have changed the start of the for loop to what you suggested. so my code is now the following, so im i right in thinking this is now calculating the features for the region?
clear;
A=getImageFunction;
regionNum=1;
for c = 1:size(A,2); % Number of columns
for r = 1:size(A,1); %Number of rows
R = A(r:r-2, c:c-2);
%Extract the features
FM(regionNum, 1) = mean(mean(A));
FM(regionNum, 2) = std2(A);
regionNum = regionNum +1;
end
end
Regions_Calculated=regionNum;
|