1
我正在使用MATLAB R2012a,我試圖讓用戶在不使用內置函數的情況下裁剪圖像。
這裏是我的代碼:
MATLAB幫助裁剪圖像
[x, y] = ginput(2);
m1 = [x(1), y(1)];
m2 = [x(2), y(2)];
m1 = int16(m1);
m2 = int16(m2);
[m, n] = size(manip);
s1 = (m2(1) - m1(1))+1;
s2 = (m2(2) - m2(2))+1;
temp = zeros([s1, s2],('uint8'));
p1 = 0;
p2 = 0;
for c1 = 1:m
if ((c1 <= m1(2)) && (c1 >= m2(2)))
for c2 = 1:n
if ((c2 <= m1(1)) && (c2 >= m2(1)))
temp(p1, p2) = manip(c1, c2);
end
p2 = p2 + 1;
end
end
p1 = p1 + 1;
end
out = temp;
這裏是我的結果:
的我做錯了什麼任何想法,我可以的似乎能看見。謝謝。