accumarray error: Second input VAL must be a vector with one element for each row in SUBS, or a scalar

3 views (last 30 days)
Error using accumarray
Second input VAL must be a vector with one element for each row in SUBS, or a scalar.
Error in descriptFPoints (line 160) DescriptVector = accumarray( AngleBinsShifted, SubPatch_norm(IndexMaskOfBlocks), [ NOfBins*NOfWindows^2, 1 ] ); My code segment is given below:
for i = 1:N
%---------------- Data of feature point ---------------%
Scale = HrLOrntPoints(i,3);
MainOrient = deg2rad(HrLOrntPoints(i,6));
row0 = HrLOrntPoints(i,4);
clmn0 = HrLOrntPoints(i,5);
Step = StepSampleFunction( Scale );
%-------------- Neighborhood in new coord -------------%
% new coordinates received from old ones by rotation, and shift by [ row0, clmn0 ]
mx = max( ceil(2*NOfWindows*Step), round(3*Scale) + 1 );
ind = -mx:mx;
% pay attention, that coordinates are taken in column-major order, so
% assignments below of Patch is consistent
[ Clmn, Row ] = meshgrid( ind, ind );
% tmp2 need to be >= 4*NOfWindows, in order to descript point after
% mx, that was choosen before, provide this
tmp2 = 2*mx + 1; tmp = tmp2^2;
Coord_new = zeros( tmp, 2 );
Coord_new( :, 2 ) = Row(:);
Coord_new( :, 1 ) = Clmn(:);
Coord_new = Coord_new';
%------ Converting coordinates to original form -------%
Rotation = [ cos(MainOrient) -sin(MainOrient); sin(MainOrient) cos(MainOrient) ];
% Coord_orig(1,:) - column coord, that correspond to Coord_new( 1, : ).
% Coord_orig(2,:) - rows ...
Coord_orig = round( (Rotation)*Coord_new + repmat( [ clmn0 row0 ]', 1, tmp ) );
%---------- Converting to linear indexes -------------%
IndOfRotatedPatch = sub2ind( [ Nrow, Nclmn ], Coord_orig( 2,: )', Coord_orig( 1,: )' );
%---------- Assigning values to the patch -------------%
Patch = zeros( tmp2 );
Patch(:) = img( IndOfRotatedPatch );
%------------------ Derivative mask -------------------%
ind = -round(3*Scale):round(3*Scale);
[ X, Y ] = meshgrid( ind, ind );
dGdx = -X .* exp(-( X.*X + Y.*Y )/(2*Scale*Scale)) ./ ((Scale^4)*(2*pi));
dGdy = -Y .* exp(-( X.*X + Y.*Y )/(2*Scale*Scale)) ./ ((Scale^4)*(2*pi));
%----------------- Window derivatives -----------------%
% also possible to do convolution, cause gaussian symmetric
Patchx = imfilter(Patch, dGdx, 'same');
Patchy = imfilter(Patch, dGdy, 'same');
%----------------- Norm of gradients ------------------%
gradient_norm = sqrt(Patchx.^2 + Patchy.^2);
%------------- Avaraging norm gradients --------------%
g = fspecial('gaussian',max(1,fix( 6*Scale*Factor )), Scale*Factor);
gradient_norm = imfilter(gradient_norm, g, 'same');
%----------------- Angles of gradients ----------------%
gradient_angles = rad2deg( atan2( Patchy, Patchx ) + pi );
%--------- Taking sub-window for description ----------%
% I'm taking 'center pixel'( Feature point, with coordinates [ row0, clmn0 ] in image ) to be in
% new/sub-patch coordinates at [ p, p ]
% p = round(tmp2/2)
p = mx + 1;
% so I'll have patches of size 4*NOfWindows x 4*NOfWindows
SubPatch_norm = gradient_norm( max(round( (p - ( 2*NOfWindows )*Step):Step:(p + ( 2*NOfWindows -1 )*Step) ), 1), max(round( (p - ( 2*NOfWindows )*Step):Step:(p + ( 2*NOfWindows -1 )*Step)), 1) );
SubPatch_angles = gradient_angles( max(round( (p - ( 2*NOfWindows )*Step):Step:(p + ( 2*NOfWindows -1 )*Step) ), 1), max(round( (p - ( 2*NOfWindows )*Step):Step:(p + ( 2*NOfWindows -1 )*Step)), 1) );
%-------------- Assigning angles 2 bins ---------------%
[tmp, AngleBins] = histc( SubPatch_angles(IndexMaskOfBlocks), Edges4Hist );
%---------------- Shifting angle bins -----------------%
AngleBinsShifted = AngleBins + IndexShiftBins4Accum;
%-------- Accumulating norms 2 according bins ---------%
DescriptVector = accumarray(AngleBinsShifted, SubPatch_norm(IndexMaskOfBlocks), [ NOfBins*NOfWindows^2, 1 ] );
DescriptVector = min( DescriptVector/norm(DescriptVector), Thresh );
DescriptVector = DescriptVector/norm(DescriptVector);
%---------------- Assign values 2 matrix --------------%
DescriptFPVector( i, : ) = (DescriptVector)';
% if strcmp( SwitchWaitbars, 'on' )
% waitbar(i/N)
% end
end
  2 Comments
Jan
Jan on 19 Jan 2018
Edited: Jan on 19 Jan 2018
We cannot run your code. The error message seems to be clear already. So how exactly can we help you?
Set a breakpoint in this line and check the sizes of the vectors. Maybe a transposing is enough already.
K M Ibrahim Khalilullah
K M Ibrahim Khalilullah on 20 Jan 2018
@Jan Simon Thank you very much for your comment. Actually I downloaded the code from Matlab file exchange. Would you please check it from this link? https://uk.mathworks.com/matlabcentral/fileexchange/29004-feature-points-in-image--keypoint-extraction It is not working for all images. My image is greater than 5 MB, so it is not possible to upload.

Sign in to comment.

Accepted Answer

K M Ibrahim Khalilullah
K M Ibrahim Khalilullah on 20 Jan 2018
Solved this problem by avoiding third argument of the function. The program is Ok now. Thank to all

More Answers (0)

Community Treasure Hunt

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

Start Hunting!