这是我们在kWave工具箱中使用的resize函数。

function mat_rs = resize(varargin)

%RESIZE Resize a matrix.

% DESCRIPTION:

% Resize a matrix to a given size using interp2 (2D) or interp3

% (3D).

% Use interpolation to redivide the [0,1] interval into Nx, Ny, Nz

% voxels, where 0 is the center of first voxel, and 1 is the center

% of the last one.

%

% USAGE:

% mat_rs = resize(mat, new_size)

% mat_rs = resize(mat, new_size, interp_mode)

%

% INPUTS:

% mat - matrix to resize

% new_size - desired matrix size in elements given by [Nx, Ny] in

% 2D and [Nx, Ny, Nz] in 3D. Here Nx is the number of

% elements in the row direction, Ny is the number of

% elements in the column direction, and Nz is the

% number of elements in the depth direction.

%

% OPTIONAL INPUTS:

% interp_mode - interpolation mode used by interp2 and interp3

% (default = '*linear')

%

% OUTPUTS:

% mat_rs - resized matrix

% check the inputs for release B.0.2 compatability

if length(varargin{2}) == 1 && nargin >= 3 && length(varargin{3}) == 1

% display warning message

disp('WARNING: input usage deprecated, please see documentation.');

disp('In future releases this usage will no longer be functional.');

% recursively call resize with the correct inputs

if nargin == 3

mat_rs = resize(varargin{1}, [varargin{2}, varargin{3}]);

else

mat_rs = resize(varargin{1}, [varargin{2}, varargin{3}], varargin{4});

end

return

end

% update command line status

disp('Resizing matrix...');

% assign the matrix input

mat = varargin{1};

% check for interpolation mode input

if nargin == 2

interp_mode = '*linear';

elseif nargin ~= 3

error('incorrect number of inputs');

else

interp_mode = varargin{3};

end

% check inputs

if numDim(mat) ~= length(varargin{2})

error('resolution input must have the same number of elements as data dimensions');

end

switch numDim(mat)

case 2

% extract the original number of pixels from the size of the matrix

[Nx_input, Ny_input] = size(mat);

% extract the desired number of pixels

Nx_output = varargin{2}(1);

Ny_output = varargin{2}(2);

% update command line status

disp([' input grid size: ' num2str(Nx_input) ' by ' num2str(Ny_input) ' elements']);

disp([' output grid size: ' num2str(Nx_output) ' by ' num2str(Ny_output) ' elements']);

% check the size is different to the input size

if Nx_input ~= Nx_output || Ny_input ~= Ny_output

% resize the input matrix to the desired number of pixels

mat_rs = interp2(0:1/(Ny_input - 1):1, (0:1/(Nx_input - 1):1)', mat, 0:1/(Ny_output - 1):1, (0:1/(Nx_output - 1):1)', interp_mode);

else

mat_rs = mat;

end

case 3

% extract the original number of pixels from the size of the matrix

[Nx_input, Ny_input, Nz_input] = size(mat);

% extract the desired number of pixels

Nx_output = varargin{2}(1);

Ny_output = varargin{2}(2);

Nz_output = varargin{2}(3);

% update command line status

disp([' input grid size: ' num2str(Nx_input) ' by ' num2str(Ny_input) ' by ' num2str(Nz_input) ' elements']);

disp([' output grid size: ' num2str(Nx_output) ' by ' num2str(Ny_output) ' by ' num2str(Nz_output) ' elements']);

% create normalised plaid grids of current discretisation

[x_mat, y_mat, z_mat] = ndgrid((0:Nx_input-1)/(Nx_input-1), (0:Ny_input-1)/(Ny_input-1), (0:Nz_input-1)/(Nz_input-1));

% create plaid grids of desired discretisation

[x_mat_interp, y_mat_interp, z_mat_interp] = ndgrid((0:Nx_output-1)/(Nx_output-1), (0:Ny_output-1)/(Ny_output-1), (0:Nz_output-1)/(Nz_output-1));

% compute interpolation; for a matrix indexed as [M, N, P], the

% axis variables must be given in the order N, M, P

mat_rs = interp3(y_mat, x_mat, z_mat, mat, y_mat_interp, x_mat_interp, z_mat_interp, interp_mode);

otherwise

error('input matrix must be 2 or 3 dimensional');

end

matlab 调整矩阵形状,在MATLAB中调整3D矩阵(图像)的大小相关推荐

  1. c++矩阵转置_线性代数中的向量矩阵

    目录 前言 符号约定 向量的基本性质 [定义,基向量,线性相关/无关*,向量点积] 矩阵的基本性质 [转置,广播,线性变换] 矩阵基本运算 [矩阵相乘,矩阵点积] 行列式 [概念,性质,右手法则,行列 ...

  2. 在Matlab中可视化3D体积图像数据,例如MRI图像

    转载自Binlin Wu (2020). Visualize 3D volumetric image data such as MRI images in Matlab (https://www.ma ...

  3. 混淆矩阵评价指标_机器学习模型评价指标 -- 混淆矩阵

    机器学习模型评价指标 – 混淆矩阵 在机器学习领域中,混淆矩阵(confusion matrix)是一种评价分类模型好坏的形象化展示工具.其中,矩阵的每一列表示的是模型预测的样本情况:矩阵的每一行表示 ...

  4. matlab 调整矩阵形状,matlab对矩阵/向量的常用操作(拼接矩阵、向量逆序、改变矩阵形状、求行阶梯形矩阵、提取矩阵的一部分等)...

    几乎所有变量在matlab中都可以视为矩阵(1 x 1元素,1 x n向量,m x n矩阵等),matlab中对矩阵/向量的操作非常多,个人认为对矩阵的操作是体现matlab功底的地方:灵活搭配使用这 ...

  5. 怎样对三维切片 MATLAB,绘制切片中的三维矩阵 - MATLAB

    我想绘制我的三维矩阵的每个切片,以显示第三维的差异.然而,我只能设法将它们彼此打成一片,我想要一个3D图,其中明确表示矩阵的切片实际上是堆叠的.我为两层到目前为止的代码是绘制切片中的三维矩阵 - MA ...

  6. matlab三维数组的输出,八度 – Matlab中的三维(3D)矩阵插值

    你几乎把它弄好了.您需要定义坐标的3D网格.创建单个向量不是正确的方法.你当然可以在这里使用interp3.尝试做: [X,Y,Z] = meshgrid(1:213, 1:100, 1:140); ...

  7. MATLAB笔记1:sub2ind;ind2sub;删除矩阵某行或者某列元素;改变矩阵的形状reshape函数

    重点 MATLAB中的矩阵元素按列存储,其序号即是矩阵元素再内存中的排列顺序.例如: >> A=[1,2;3,4]A =1 23 4>> A(2)ans =3 sub2ind函 ...

  8. 【MATLAB实验】MATLAB矩阵与数组及改变矩阵形状(rot90函数逆时针旋转、矩阵转置)

    目录 Matlab矩阵 矩阵除法 矩阵乘方 数组的乘和除 数组的乘方 数据的输出格式 常用函数的应用 矩阵的建立 冒号表达式 结构矩阵和单元矩阵 结构矩阵: 单元矩阵: 矩阵元素的引用方式 利用冒号表 ...

  9. 如何用MATLAB把一个三维矩阵里的数据中的一页画成三维图并加密网格

    2019年4月24日 关于如何把一个三维矩阵里的数据中的一页画成三维图并加密网格. 已经很久没有用过MATLAB了,话说之前也没处理过三维数据...所以还是花了一点时间找资料的.废话少说... 首先因 ...

最新文章

  1. dropout是什么?为什么dropout管用?测试集上是否需要使用dropout?说明为什么神经网络中的dropout可以作为正则化?
  2. “ld: symbol(s) not found for architecture i386“错误解决方法
  3. JVM调优总结 -Xms -Xmx -Xmn -Xss等
  4. Notepad++插件总结
  5. UnaryOperator函数式接口
  6. framebuffer驱动详解0——framebuffer介绍
  7. java 栈 先进后出_栈先进后出,堆先进先出
  8. HTML5游戏-看你有多色
  9. hdu 1802 Black and white painting(置换群)
  10. 报错:error while loading shared libraries: libz.so.1: cannot open shared object file
  11. Ios开发之Category
  12. 开坑,写点Polymer 1.0 教程第2篇(上)——hello world篇
  13. 怎样在 Ubuntu Unity Dash 添加关机、重启选项
  14. cognos java,cognos10用JAVA如何获取passPortID(即实现单点登录)
  15. Windows内核学习------双机调试的安装(物理机win10,虚拟机win7,虚拟机软件vmware)
  16. MYSQL-Front新手连接数据库总结
  17. Python 输入整数进行排序
  18. C语言调用函数流程图怎么画,【C语言】求教这个流程图怎么画啊
  19. 网页加速系列(六)、 网页加速之进阶下篇
  20. 支付宝 微信 内购 支付

热门文章

  1. C语言学习书籍推荐《学通C语言的24堂课》下载
  2. 2023最新SSM计算机毕业设计选题大全(附源码+LW)之java后台投票网站系统9h37l
  3. 绘制巴厘岛Barong蒙版– Photoshop教程
  4. 23种设计模式——JDK动态代理(AOP)
  5. 【视频课】行为识别课程更新!CNN+LSTM理论与实践!
  6. 记一次Linux被入侵,服务器变“矿机”全过程
  7. D. Colored Rectangles
  8. 基于域的无线安全认证方案
  9. logi k380 蓝牙键盘 与macbook 连接断开
  10. 浙大愤青郑强教授的演讲(大学生都来看看吧)