How to solve this error (index must be a positive integer or logical)?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
function s = subim(f, m, n, rx, cy)
%SUBIM Extracts a subimage, s, from a given image, f.
%The subimage is of size m-by-n, and the coordinates of its top, left corner are (rx, cy).
s = zeros(m, n);
rowhigh = rx + m - 1;
colhigh = cy + n - 1;
xcount = 0;
for r = rx:rowhigh
xcount = xcount + 1;
ycount = 0;
for c = cy:colhigh
ycount = ycount + 1;
s(xcount, ycount) = f(r, c);
end
end
I am try to run the code, but this got error. Attempted to access f(0,0); index must be a positive integer or logical.
f = imread('13100.jpg');
[m,n]=size(f);
s = zeros(m, n);
rx = 0;
cy = 0;
s = zeros(m, n);
rowhigh = rx + m - 1;
colhigh = cy + n - 1;
xcount = 0;
for r = rx:rowhigh
xcount = xcount + 1;
ycount = 0;
for c = cy:colhigh
ycount = ycount + 1;
s(xcount, ycount) = f(r, c);
end
end
%
1 Commento
Stephen23
il 13 Apr 2017
@Mei Synn Tan: rather than doing this in a loop you should use indexing with vectors. Also note that images are often 3D, which your code does not take into account.
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Satellite Mission Analysis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!