I am new to MATLAB, I am trying to implement flood filling using this algorithm in Matlab, I donโt know what I did wrong, maybe I didnโt use the recursive function correctly, but still Iโm not mistaken, and this code forces my matlab to close I am using the following code, which I am trying to debug in the morning, but could not find the problem.
function [ colored_Image ] = floodFill( image, target_Loc_x, target_Loc_y, targetColor, replacementColor ) colored_Image = image; if (target_Loc_x >= 1) && (target_Loc_x <= size(image,1)) && (target_Loc_y >= 1) && (target_Loc_y <= 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
calling this function with
image = floodFill(im,1,1,0,127); imshow(image);
im is my 200 x 200 matrix image. I want my black color (0) to be gray (127), any help would be appreciated