您将如何有效地在Matlab中计算图像的邻接矩阵?

时间:2019-01-23 05:24:32

标签: matlab adjacency-matrix

我正在尝试通过使用以下示例代码在matlab中获得邻接矩阵来将图像转换为图形:

im = im2single(imread('cameraman.tif')); 
% It is safe to assume that I need such a small adjacency matrix.
% therefore I resize the image below. 
im = imresize(im,[16 16]);

[rows, cols, bands] = size(im);
imr = reshape(im, rows*cols, bands);
adj_matrix = zeros(rows*cols, rows*cols);
for ind = 1:rows*cols
    dist = sum((imr - imr(ind,:)).^2,2);
    adj_matrix(ind,:) = dist;
end

尽管对于单个图像而言,代码速度很快,但我希望将其缩放到大批量并在GPU上运行。所以我的目标是两方面:

  1. 有没有一种方法可以在没有for循环的情况下运行它?

  2. 有没有一种方法可以批量运行此张量[er xw x H x Num_of_Images]

非常感谢!

0 个答案:

没有答案
相关问题