Efficient way to calculate distance matrix between cells

조회 수: 3 (최근 30일)
Orr Streicher
Orr Streicher 2021년 1월 28일
댓글: Orr Streicher 2021년 1월 28일
Hi,
So i have an image with size of 512x512 pixels
For each pixel i calculte an environment of 11x11 nighbours so now i have matrix of cells in size of 512x512 while each cell contain a matrix in size of 11x11.
i want to calculte in efficient way a distance matrix between the cell's matrix elements, i.e if i organzie the cells marix in colum stack (vector in size of 262144), lets call this vector A , (so A is vector of cells while each cell contain a 11x11 matrix) i would like to create a matrix D in size of 262144x262144 while D(i,j) is the euclidian distance between the matrices in A(i) and A(j),
So far i calculate it with for loops:
function [ D ] = DistanceMatFromPatches( patches )
[patchesH,patchesW]=size(patches);
D=zeros(patchesH,patchesW);
patches_cs=patches(:);
patchesSize=size(patches_cs);
patchesNum=patchesSize(1);
f = waitbar(0);
for i=1:patchesNum-1
first_cs=patches_cs{i}(:);
for j=(i+1):(patchesNum)
waitbar(j/patchesNum,f,sprintf('Calculate Distance matrix: pixels %d and %d from %d',i,j,patchesNum));
%pause(0.1);
sec_cs=patches_cs{j}(:);
D(i,j)=norm(first_cs-sec_cs);
D(j,i)=D(i,j);
end
end
close(f);
end
while patches is 512x512 matrix of cells.
This implementation is not very efficent .. anyone has other idea?

답변 (1개)

Jan
Jan 2021년 1월 28일
편집: Jan 2021년 1월 28일
A 262144 x 262144 matrix of type double needs 550 GB of RAM. I assume that this will exhaust your machine.
You need a different approach, which can run on existing computers.
Blowing up the matrix to a cell matrix, which contains 11x11 submatrices does not add any new information to the data. Then this produced redundancy is a waste of ressources already.
  댓글 수: 1
Orr Streicher
Orr Streicher 2021년 1월 28일
Hi Jan and thanks for your response
Any seggestion how to do it?
In the end i would like to find the distance matrix as i described .. maybe there is an efficient way to do it?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by