Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
2 views (last 30 days)
Show older comments
%Calculate ncc not working see again
bdiff(k+1, 1) = MatchCostNCC(blockL(:), blockR(:));
But the i have this problem : " Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."
Even if BlockL is 25by25 so BlockR !.
Can anyone help me plz ?
2 Comments
Image Analyst
on 25 Dec 2021
Is MatchCostNCC an array or a function?
Is bdiff 625 rows tall? Because blobL(:) is 625-by-1, so bdiff needs to have the same number of rows.
Answers (1)
Jan
on 25 Dec 2021
Let Matlab stop at the error using the debugger:
dbstop if error
Then run the code again. If it stops, chek the sizes of the used variables:
size(blockR(:))
size(blockL(:))
size(MatchCostNCC(blockL(:), blockR(:)))
size(bdiff(k+1, 1))
Remember, that the readers cannot know or check the sizes, but you can. We could guess, that k is a scalar, but you can clatify this.
My guess:
bdiff(k+1, 1) is a scalar, but MatchCostNCC(blockL(:), blockR(:))) is not. Than the assignment must fail.
2 Comments
Walter Roberson
on 26 Dec 2021
blockR=rightI(i-hb:i+hb,j-hb:j+hb);
That is obviously intended to be a rectangular array.
blockL=leftI(i-hb:i+hb,j-hb+k:j+hb+k);
That is obviously intended to be a rectangular array.
bdiff(k+1, 1) = abs(blockL(:) - blockR(:));
With the variables on the right both being arrays, blockL(:) is a vector and blockR(:) is a vector, and the difference of vectors is a vector, and abs() of a vector is a vector. But you are assigning the result to a scalar location.
bdiff(k+1, 1) = MatchCostNCC(blockL(:), blockR(:));
Okay, you are passing vectors into MatchCostNCC
[nrow2, ncol2, ndim2]=size(img2);
but the code is expecting possibly RGB images
f=fspecial('average', win_size);
mu1=conv2(img1, f, 'same');
mu2=conv2(img2, f, 'same');
but conv2() cannot operate on more than 2 dimensions, so if an RGB image was passed in the code would fail.
for d=1:disp_range
temp=diff1.*diff2_pad(:, d:d+ncol2-1,:);
cost(:,:,d)=-conv2(temp, f, 'same');
end
You construct cost as a multidimensional array.
cost then gets passed back to the call
bdiff(k+1, 1) = MatchCostNCC(blockL(:), blockR(:));
and you then try to assign the multidimensional array to the scalar location bdiff(k+1,1)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!