2 qq 28644255 qq_28644255 于 2016.04.04 23:54 提问

帮忙看看这段程序怎么对图像M进行的分块,谢谢!

function patches= compute_patches(M, block_size,step)
% figure
% imshow(M)
M = M(3:end-2,3:end-2);
% % % figure imshow(M)
[r,c]= size(M);%M的尺寸,
if ~exist('step','var')
step = round(max(r,c)/400*block_size);
end
[xc,yc] = meshgrid(0:step:c,0:step:r);tep:c;
%yc是c+1列,元素是0:step:r;
rm_ind = ((xc+block_size)>c)|((yc+block_size)>r);
xc(rm_ind) = [];
yc(rm_ind) = [];
pathch_num = numel(xc);
patches = zeros(pathch_num,block_size*block_size);
for i = 1:block_size
for j = 1:block_size
ind = sub2ind(size(M),yc+i,xc+j);
patches(:,(i-1)*block_size+j) = M(ind(:));
end
end
patches = patches';

1个回答

zhangshangui_2015
zhangshangui_2015   2016.04.05 13:08
已采纳

其实你只需要理解每个黑白图形都是一个矩阵就行了(0-255),这个Matlab代码都是对矩阵进行各种操作运算。找本Matlab的书看一看吧

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!