0

John Burkardt によるCONTRAST2_SPMDの修正版を使用して、大きなグレースケール画像で 3x3 分散計算を実行しています。これの利点は、PCT を使用してローカル マシンで 8 コアを使用できることですが、ウィンドウ サイズ (現時点では 3x3) を変更したいのですが、いくつかのウィンドウ サイズを試してみたいと考えています。以下のコードを変更して、可変ウィンドウ サイズを許可するにはどうすればよいですか? (奇数の正方形のウィンドウを使用します。たとえば、3x3、5x5、7x7、9x9 など)。

function y = parwinvar ( x )

%**************************************************************************
%
%
%% PARWINVAR uses MATLAB's SPMD command for parallel windowed variance.
%
%  Discussion:
%    Calculates windowed standard deviation (squared to get variance).
%    Based on CONTRAST2_SPMD by John Burkardt.
%
%
%  Parameters:
%
%    Input, image X, the initial black and white image.
%    Output, image Y, the contrast-enhanced black and white image.
%
%
%
%  Open the matlabpool
%
    matlabpool open local 8
%
% Check image is grayscale, if not covert it
% 
    if ndims(x)>2
         x=rgb2gray(x);
    end
%
%  Since the image is black and white, it is a 2D array.
%  Hence, it will be distributed by columns.
%
  xd = distributed ( x );
%
%  Have each worker enhance the contrast in its portion of the picture.
%
%  You will see lots of meaningless error messages, because NLFILTER
%  wants to put out a "waitbar" telling you to wait.  But the workers
%  don't have an associated display.
%
  spmd

    xl = getLocalPart ( xd );
%
%  In order to use LABSENDRECEIVE, we need to reference the previous
%  and next labindex.
%
    if ( labindex ~= 1 )
      previous = labindex - 1;
    else
      previous = numlabs;
    end

    if ( labindex ~= numlabs )
      next = labindex + 1;
    else
  next = 1;
end
%
%  Each worker sends its first column to the previous worker,
%  and receives corresponding data from the next worker.
%
column = labSendReceive ( previous, next, xl(:,1) );

if ( labindex < numlabs )
  xl = [ xl, column ];
end
%
%  Each worker sends its last column to the next worker,
%  and receives corresponding data from the previous worker.
%
column = labSendReceive ( next, previous, xl(:,end) );

if ( 1 < labindex )
  xl = [ column, xl ];
end
%
%  Now do the enhancement.
%  We can only do a 3x3 neighborhood, because we're only sending
%  one column to the left and right.
%   
xl = nlfilter ( xl, [3,3], @std2 );
%
%  Now strip off the extra columns.
%
    if ( 1 < labindex )
      xl = xl(:,2:end);
    end

    if ( labindex < numlabs )
      xl = xl(:,1:end-1);
    end

   xl = uint8 ( xl );

  end
%
%  We are working with a black and white image, so we can simply
%  concatenate the submatrices to get the whole object.
%
  y = [ xl{:} ];
  y = (y .* y); % square to get variance
% Close matlabpool
matlabpool close
  return
end

助けてくれてありがとう。

4

1 に答える 1

1

labSendReceiveより多くのデータを送信するには、行を変更する必要があります。特に、次のようなものです。

%
%  Each worker sends its first column to the previous worker,
%  and receives corresponding data from the next worker.
%
column = labSendReceive ( previous, next, xl(:,1) );

なる必要があります:

%
%  Each worker sends its first N columns to the previous worker,
%  and receives corresponding data from the next worker.
%
columns = labSendReceive ( previous, next, xl(:,1:N) );

はどこNですか(blocksize-1)/2。右側の「ゴースト セル」を送信するとき、および「余分な列」を削除するときに、対応する変更を行う必要があります。

于 2011-10-18T13:15:37.863 に答える