有没有办法控制blockproc输出的串联? [英] Is there any way to control the concatenation of the blockproc output?

查看:129
本文介绍了有没有办法控制blockproc输出的串联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对问题的跟进:使用blockproc或im2col在图像上重叠滑动窗口?

因此,使用代码:

B = blockproc(A, [1 1], @block_fun, 'BorderSize', [2 2], 'TrimBorder', false, 'PadPartialBlocks', true)

我能够在我的图像上创建一个重叠的滑动窗口并计算 dct2 为每个窗口。但问题是 blockproc 以我无法使用的方式连接输出。输出很大程度上取决于块大小,输出矩阵的大小每次都不同。

I was able to create an overlapping sliding window over my image and calculate the dct2 for each window. But the problem is that blockproc concatenates the output in a way that I cannot use. The output greatly depends on the block size and the size of the output matrix is different because of it every time.

我的 dct2 函数为每个块或窗口创建一个 1 x 200 向量。所以我假设如果有64个块,我应该得到类似 64 x 200 200 x 64 输出,但是我得到类似 64 x 1600 的东西,或者如果是更大的块我得到 15 x 400

My dct2 function creates a 1 x 200 vector for every block or window. So I assumed that if there are 64 blocks I should get something like 64 x 200 or 200 x 64 output, but I get something like 64 x 1600 or in case of larger blocks I get 15 x 400.

查看 blockproc 函数问题是由

% write 4 corner blocks
b(1:ul_output_size(1),1:ul_output_size(2),:) = ul_output;
if ll_processed
    last_row_start = final_rows - size(ll_output,1) + 1;
    last_row_width = size(ll_output,2);
    b(last_row_start:end,1:last_row_width,:) = ll_output;
end
if ur_processed
    last_col_start = final_cols - size(ur_output,2) + 1;
    last_col_height = size(ur_output,1);
    b(1:last_col_height,last_col_start:end,:) = ur_output;
end
if lr_processed
    last_row_start = final_rows - size(ll_output,1) + 1;
    last_col_start = final_cols - size(ur_output,2) + 1;
    b(last_row_start:end,last_col_start:end,:) = lr_output;
end

显然,blockproc进一步将块分为左上,右上,左下并且右下角和连接结果。这就是为什么我得到所有这些混合输出。

Apparently, blockproc further divides the blocks into upper left, upper right, lower left and lower right and concatenates that result. And that is why I am getting all this mixed outputs.

我需要每个窗口的每一行中每个块的输出。每个窗口应该只给我一个 1x200 输出,我可以输入我的分类器。

I need the output of each block in its each row, for each window. Each window should just give me a 1x200 output, that I can feed into my classifier.

我可以强制以我想要的方式输出 blockproc ,只需给出每个块的输出。

Can I force the output of blockproc in the way that I want it, just give the output of each block.

如果没有,我真的很感激在图像上有一个重叠的滑动窗口的替代解决方案。

If not, I would really appreciate an alternative solution to have an overlapping sliding window over the image.

编辑:是否可以保存块数据使用 block_struct.data 将每个块放入函数 block_fun 内的单元格数组中,然后使用该数组提取我的特征?

edit: would it be possible to save the blocks data using block_struct.data for every block into a cell array inside the function block_fun and then use that array to extract my features?

谢谢

编辑:

B = blockproc(images_m{1}, [64 64], @(x)reshape(x.data(:),[1 1 numel(x.data)]), 'BorderSize', [10 10], 'TrimBorder', false, 'PadPartialBlocks', true, 'PadMethod', 'replicate');
imgs = {};
for i = 1:size(B,1)
    for j = 1:size(B,2)
        tempy = squeeze(B(i,j,:));
        tempy2 = reshape(tempy, [84 84]);
        feats{end+1} = block_dct2(tempy2); %calculates dct2 for the block and returns a 1*200 vector

    end
end


推荐答案

也许在第三维中重塑数据?

Maybe reshape you data in the third dimension?

>> A = magic(3)

A =

     8     1     6
     3     5     7
     4     9     2

>> B = blockproc(A, [1 1], @(x)reshape(x.data(:),[1 1 numel(x.data)]), 'BorderSize', [1 1], 'TrimBorder', false, 'PadPartialBlocks', true);

>> whos B
  Name      Size             Bytes  Class     Attributes

  B         3x3x9              648  double  
>> squeeze(B(1,1,:))

ans =

     0
     0
     0
     0
     8
     3
     0
     1
     5

>> 

这篇关于有没有办法控制blockproc输出的串联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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