Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6701531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:56:43+00:00 2026-05-26T06:56:43+00:00

I am using a modified version of CONTRAST2_SPMD by John Burkardt to run a

  • 0

I am using a modified version of CONTRAST2_SPMD by John Burkardt to run a 3×3 variance calculation on a large grayscale image. The advantage of this is that I can use the PCT to use 8 cores on my local machine, however I would like to change the window size (at the moment its 3×3), but I would like to try several window sizes. How would I modify the code below to allow for variable window sizes? (I will be using odd, square windows, e.g. 3×3,5×5,7×7,9×9 etc.)

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

Thanks in advance for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:56:43+00:00Added an answer on May 26, 2026 at 6:56 am

    You need to modify the labSendReceive lines to send more data. In particular, something like this:

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

    Needs to become:

    %
    %  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) );
    

    where N is (blocksize-1)/2. There’s a corresponding change to be made when sending the right-hand-side ‘ghost cells’, and when stripping off the ‘extra columns’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a modified version of light house from this page. I want
I am using a slightly modified version of this code . to create a
I'm using jQuery (1.6.4) and using a slightly modified version of this method to
I'm using a modified version on juno ( http://github.com/breily/juno/ ) in Google App Engine.
I using a vendor modified version Linux which is based on a 2.6.14.* (more
I am running a local instance of HTTP::Daemon using a modified version of the
I'm trying to append rows upon scrolling of a table using a modified version
I am using a highly modified version of the jqueryFileTree plugin, that is able
I am using a slightly modified version of the Sun's example JTreeTable backed by
I am using a modified version of blank_seo theme for Magento with the ES_ES

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.