在Matlab中是否可以替代blockproc? [英] Is there a substitute for blockproc in Matlab?

查看:175
本文介绍了在Matlab中是否可以替代blockproc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 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-by-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

输入图像和结果牌:


< img src =https://i.stack.imgur.com/4fAyz.pngalt =tiles>

这篇关于在Matlab中是否可以替代blockproc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆