Jos*_*ino 6 matlab image-processing matrix
我正在MATLAB中开展一个图像处理项目.为了更容易地预处理图像,我将其划分为行和列,因此从原始图像(2D uint8矩阵)开始,现在我有一个3D矩阵,就像堆栈一样.

处理完每个块之后,我想再次重新构图.问题是行数和列数是动态的,所以我不能使用(或者不知道如何在这里使用它)cat命令或[firstsubmatrix secondsubmatrix]语法.
顺便说一句,我这样做了这个部门:
numRows = 3
numCols = 3
blockHeight = originalHeight / numRows;
blockWidth = originalWidth / numCols;
blocks = uint8(zeros(numCols * numRows, blockHeight, blockWidth));
Run Code Online (Sandbox Code Playgroud)
因此,对于每个块,我使用填充其内容
y0 = (row - 1) * rowHeight + 1;
y1 = row * rowHeight;
x0 = (col - 1) * rowWidth + 1;
x1 = col * rowWidth;
blocks(numBlock, :, :) = originalImage(y0:y1, x0:x1);
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法,以及任何方式使块加入?
如果我正确理解你的问题,那么我会这样做:假设我们有一些尺寸为 m × n 的数据矩阵
[m n] = size(data);
rows_wanted = 10;
cols_wanted = 10;
submatrix_rows = rows_wanted*ones(1,m/rows_wanted);
submatrix_cols = cols_wanted*ones(1,n/cols_wanted);
data_cells = mat2cell(data,submatrix_rows,submatrix_cols);
for k1 = 1:submatrix_rows;
for k2 = 1:submatrix_cols;
proc_data_cells{k1,k2} = function_for_matrics(data_cells{k,l});
end
end
proc_data_mtx = cell2mat(proc_data_cells);
Run Code Online (Sandbox Code Playgroud)
将数据转换为单元格,其中单元格的每个元素都是子矩阵,然后遍历每个元素,执行函数并将其输出到新单元格。使用 cell2mat 输出完全连接的处理矩阵。
如果您有权访问图像处理工具箱,我还会查看“blkproc”函数。