title: selecting pixels randomly and uniformly
body: <p>I have grey image divided into patches, I need to select pixels from each patches randomly and uniformly, so the method of selection should be the same for all patches..
  the uniform pixel selection is critical in my project as I will need to find intensities difference between each two pixels.
  here is the code that I try but it does not give the required result as only 8 pixels is selected where the patches size are [90 X 100]</p>
  
  <pre><code>    I = imread('0001hv1.bmp');
  Rpix = zeros(size(I));
  [m n] = size(I);
  for i = 2:m-1
    for j = 2:n-1
    switch randi(8,1,1)
      case 1
          rpix1 = I(i-1,j-1);
      case 2
          rpix2 = I(i-1,j);
      case 3
          rpix3 = I(i-1,j+1);
      case 4
          rpix4 = I(i,j-1);
      case 5
          rpix5 = I(i,j+1);  %skip i,j as that is the pixel itself
      case 6
          rpix6 = I(i+1,j-1);
      case 7
          rpix7 = I(i+1,j);
      case 8
          rpix8 = I(i+1,j+1);
    end
    %rpix(i,j) = rpix ; 
  
   end
  end
  im_sub1 = rpix1 - rpix2;
  im_sub2 = rpix3 - rpix4;
  im_sub3 = rpix5 - rpix6;
  im_sub4 = rpix7- rpix8;
  </code></pre>
  
  <p>I read about Gaussian distribution where the idea proposed is:" X and Y are randomly sampled using a Gaussian distribution where first X is sampled with a standard deviation of 0.04*S^2 and then the Yi’s are sampled using a Gaussian distribution – Each Yi is sampled with mean Xi and standard deviation of 0.01 * S^2."</p>
  
  <p>is it suitable to my code case and how can I implement it ?
  thank you </p>