如何从 Matlab 中的矩阵元胞数组创建单个图像?

How to create single image from cell array of matrices in Matlab?

我需要将灰度图像分成等份,所以我使用了函数 mat2cell。然后我必须分别均衡每个部分,为此我使用了函数 histeq。我为此重复使用了相同的元胞数组变量。这是代码:

height=round(size(img,1)/number_of_divisions);
length=round(size(img,2)/number_of_divisions);
M=zeros(number_of_divisions,1);
N=zeros(1,number_of_divisions);
M(1:number_of_divisions)=height;
N(1:number_of_divisions)=length;
aux=mat2cell(img,M,N);

for i=1:size(aux,1)
    for j=1:size(aux,2)
        aux{i,j}=histeq(aux{i,j},256);
    end
end

那么现在如何将每个单元格合并为一个图像?

使用cell2mat

img2=cell2mat(aux);

为了获得更好的性能,请将您的代码替换为 blockproc

blocksize=ceil(size(img)./number_of_divisions);
img2=blockproc(img,blocksize,@(block_struct)histeq(block_struct.data));