Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab将图像重塑为原始图像_Matlab_Matrix_Multidimensional Array_Vectorization_Reshape - Fatal编程技术网

Matlab将图像重塑为原始图像

Matlab将图像重塑为原始图像,matlab,matrix,multidimensional-array,vectorization,reshape,Matlab,Matrix,Multidimensional Array,Vectorization,Reshape,我正在尝试将多维数组重塑为原始图像。我使用我找到的伟大解决方案,将512x512像素的图像拆分为8x8像素的子矩阵: 在这种情况下,n=m=8,sub_图像是一个8x4096的阵列。现在的问题是,我想回到原始图像,避免一个for循环,但我不知道怎么做。我知道存在函数colfilt或blockproc,但我不能使用它们。非常感谢您的帮助 只需执行与您以前重塑原始阵列相反的操作即可。排列命令保持不变(切换第一和第二维度),而重塑命令返回到512 reshaped_i_image = reshape(

我正在尝试将多维数组重塑为原始图像。我使用我找到的伟大解决方案,将512x512像素的图像拆分为8x8像素的子矩阵:


在这种情况下,n=m=8,sub_图像是一个8x4096的阵列。现在的问题是,我想回到原始图像,避免一个for循环,但我不知道怎么做。我知道存在函数
colfilt
blockproc
,但我不能使用它们。非常感谢您的帮助

只需执行与您以前重塑原始阵列相反的操作即可。排列命令保持不变(切换第一和第二维度),而重塑命令返回到512

reshaped_i_image = reshape(permute(reshape(permute(sub_images, [2 1 3]), 8, 512, []), [2 1 3]), 512, 512);
你可以用二加一来解决它-

这里需要注意的是,必须尽可能避免
permute
成本高昂


下面列出的是针对目前列出的解决方案方法的指定问题大小的运行时测试-

i_image = rand(512,512);
n = 8; m = 8;
sub_images = permute(reshape(permute(reshape(i_image, size(i_image, 1), ...
                                   n, []), [2 1 3]), n, m, []), [2 1 3]);

func1 = @() reshape(permute(reshape(sub_images,n,m,512/n,512/m),...
                                                      [1 3 2 4]),512,[]);
func2 = @() reshape(permute(reshape(permute(sub_images, [2 1 3]), ...
                                        8, 512, []), [2 1 3]), 512, 512);


>> timeit(func1)
ans =
    0.0022201
>> timeit(func2)
ans =
    0.0046847
out = reshape(permute(reshape(sub_images,n,m,512/n,512/m),[1 3 2 4]),512,[]);
i_image = rand(512,512);
n = 8; m = 8;
sub_images = permute(reshape(permute(reshape(i_image, size(i_image, 1), ...
                                   n, []), [2 1 3]), n, m, []), [2 1 3]);

func1 = @() reshape(permute(reshape(sub_images,n,m,512/n,512/m),...
                                                      [1 3 2 4]),512,[]);
func2 = @() reshape(permute(reshape(permute(sub_images, [2 1 3]), ...
                                        8, 512, []), [2 1 3]), 512, 512);


>> timeit(func1)
ans =
    0.0022201
>> timeit(func2)
ans =
    0.0046847