how to keep track of input entries used to compute output for conv2(.)

2 ビュー (過去 30 日間)
xplore29
xplore29 2013 年 5 月 29 日
I am using conv2(.). I needed to keep track of index of input elements which were used to compute a particular output element. I wrote the following piece of code for this purpose. So far it is working fine but it doesnt look like a smart way of doing it. Can anyone suggest some better approach.
%-------------------------------------------------------------------------
INPUT = rand(5,5); [inrow incol] = size(INPUT); INPUTindexmatrix=reshape(1:numel(INPUT),inrow,incol);
Channel = [1 1;1 1]; OUTPUT = conv2(INPUT,Channel,'valid'); [Outrow Outcol] = size(OUTPUT);
OUTPUTindexmatrix=reshape(1:numel(OUTPUT),Outrow,Outcol)
CellArray = cell(length(OUTPUT(:)),1); k=0;
Mask=Channel; Matrix = INPUTindexmatrix
%Sliding window approach
for j=1:size(Matrix,2)-size(Mask,2)+1 for i=1:size(Matrix,1)-size(Mask,1)+1
k=k+1;
CellArray{k,1}=Matrix(i:i+size(Mask,1)-1,j:j+size(Mask,2)-1);
CellArray{k}
end
end
%-------------------------------------------------------------------------

回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by