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

1 Ansicht (letzte 30 Tage)
xplore29
xplore29 am 29 Mai 2013
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
%-------------------------------------------------------------------------

Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by