【问题标题】:Using parfor in image processing with matrixes在带有矩阵的图像处理中使用 parfor
【发布时间】:2018-06-10 21:39:03
【问题描述】:

我们正在开发一个处理眼睛视网膜医学图像的应用程序。

通常使用直接迭代像素索引。即使图像的大小固定为 1024*768 像素,它也可能是一个消耗 CPU 的操作,例如将某些值分配给我们需要的二值化像素。

lowlayers2 = zeros(img_y_size, img_x_size);
for i=1:numel(lowlayers)
    y = rem(lowlayers(i),img_y_size);
    x = fix(lowlayers(i)/img_y_size)+1;
    lowlayers2(y,x) = 1;
end;

当尝试在调试器类型上方的简单循环中使用parfor 时,循环中的所有变量都必须显示为切片变量。我想这是为了在循环内更原始地划分迭代。

如何修改循环或变量以使用 parfor?是否可以将每个变量都表示为切片变量(意味着更多具有 2 或 3 维的多维矩阵)?

【问题讨论】:

    标签: matlab image-processing multicore parfor


    【解决方案1】:

    切片变量是一个具有 parfor 循环外引用的变量,并且它的每个元素只能由单个工作人员访问(在 parfor 并行工作人员中)

    有时 matlab 无法将 parfor 循环中的变量识别为“切片变量” 所以你可以使用一个临时变量并在 parfor 循环之后收集结果,

    lowlayers2 = zeros(img_y_size, img_x_size);
    parfor i=1:numel(lowlayers)
        y = rem(lowlayers(i),img_y_size);
        x = fix(lowlayers(i)/img_y_size)+1;
        t(i)= sub2ind(size(lowlayers2),y,x);
    end
    
    lowlayers2(t)=1;
    

    注意 1:最好在旧版本中对代码进行矢量化处理,因为在 R2017 中循环使用时不如现在参考 (this)。

    【讨论】:

      猜你喜欢
      • 2018-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多