Matlab 中是否有 blockproc 的替代品? [英] Is there a substitute for blockproc in Matlab?
问题描述
我一直在使用 blockproc
用于按块处理图像.不幸的是,blockproc
是图像处理工具箱的一部分,我的个人计算机上没有.
I've been using blockproc
for processing images blockwise. Unfortunately, blockproc
is part of the Image Processing Toolbox, which I don't have on my personal computer.
是否有基本 Matlab 中的函数组合可以替代 blockproc
?
Is there a combination of functions in base Matlab that can substitute for blockproc
?
我最初的猜测是使用 im2col
将每个块转换为列,然后使用 arrayfun
处理每一列.然后我意识到 im2col
也是图像处理工具箱的一部分,所以这并不能解决我的问题.
My initial guess was to use im2col
to transform each block into columns, and then arrayfun
to process each column. Then I realized that im2col
is also a part of the Image Processing Toolbox, so that doesn't solve my problem.
推荐答案
这是一个使用 MAT2CELL 的示例.它将图像划分为 N×M 个瓦片,并处理图像大小不能被瓦片数量整除的情况.
Here is an example using MAT2CELL. It dividing the image into N-by-M tiles, and handles the case when the image size is not evenly divisible by the number of tiles.
%# 2D grayscale image
I = imread('coins.png');
%# desird number of horizontal/vertical tiles to divide the image into
numBlkH = 4;
numBlkW = 4;
%# compute size of each tile in pixels
[imgH,imgW,~] = size(I);
szBlkH = [repmat(fix(imgH/numBlkH),1,numBlkH-1) imgH-fix(imgH/numBlkH)*(numBlkH-1)];
szBlkW = [repmat(fix(imgW/numBlkW),1,numBlkW-1) imgW-fix(imgW/numBlkW)*(numBlkW-1)];
%# divide into tiles, and linearize using a row-major order
C = mat2cell(I, szBlkH, szBlkW)';
C = C(:);
%# display tiles i subplots
figure, imshow(I)
figure
for i=1:numBlkH*numBlkW
subplot(numBlkH,numBlkW,i), imshow( C{i} )
end
输入图像和结果图块:
这篇关于Matlab 中是否有 blockproc 的替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!