title: Flood Fill using matlab
body: <p>I am new in MATLAB, I am trying to implement flood filling using this <a href="http://en.wikipedia.org/wiki/Flood_fill#Stack-based_recursive_implementation_.28Four-way.29" rel="nofollow">algorithm</a> in matlab, I dont know what I did wrong may be I didnt used recursive function right, but still I dont whats going wrong and this code make my matlab close
  I am using the following code I am trying to debug it since morning but failed to find the problem</p>
  
  <pre><code>function [ colored_Image ] = floodFill( image, target_Loc_x, target_Loc_y, targetColor, replacementColor )
  colored_Image = image;
  
  if (target_Loc_x &gt;= 1) &amp;&amp; (target_Loc_x &lt;= size(image,1)) &amp;&amp; (target_Loc_y &gt;= 1) &amp;&amp; (target_Loc_y &lt;= size(image,2))
      if image(target_Loc_x,target_Loc_y) == targetColor
          colored_Image(target_Loc_x,target_Loc_y) = replacementColor;
          colored_Image = floodFill(colored_Image,target_Loc_x ,target_Loc_y + 1, targetColor, replacementColor); 
          colored_Image = floodFill(colored_Image,target_Loc_x + 1,target_Loc_y, targetColor, replacementColor);
          colored_Image = floodFill(colored_Image,target_Loc_x,target_Loc_y - 1, targetColor, replacementColor);
          colored_Image = floodFill(colored_Image,target_Loc_x - 1,target_Loc_y, targetColor, replacementColor);
      end
  
  end
  
  
  end
  </code></pre>
  
  <p>calling this function using </p>
  
  <pre><code>image = floodFill(im,1,1,0,127);
  imshow(image);
  </code></pre>
  
  <p>im is my matrix image of 200 by 200 I want my black color(0) to grey color(127), any help will be thankful</p>