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

  • SEARCH
  • Home
  • 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 9115765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:30:34+00:00 2026-06-17T04:30:34+00:00

I am new in MATLAB, I am trying to implement flood filling using this

  • 0

I am new in MATLAB, I am trying to implement flood filling using this algorithm 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

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 using

image = floodFill(im,1,1,0,127);
imshow(image);

im is my matrix image of 200 by 200 I want my black color(0) to grey color(127), any help will be thankful

  • 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-06-17T04:30:36+00:00Added an answer on June 17, 2026 at 4:30 am

    You are probably hitting Matlab’s recursion limit. My computer doesn’t crash, but generates this error:

    Maximum recursion limit of 500 reached. Use set(0,’RecursionLimit’,N)
    to change the limit. Be aware that exceeding your available stack
    space can crash MATLAB and/or your computer.

    The way around this is to rewrite floodFill so it does not use recursion. There are some alternative algorithms on Wikipedia.

    Also: aardvarkk’s answer makes an important point about Matlab’s column-major indexing. You can fix your function by swapping all x and y variables.

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

Sidebar

Related Questions

I am new to using Matlab and am trying to follow the example in
I am new to MATLAB so I don't even know if this is possible,
I am new to matlab and I want to implement the fast KL transform.
I'm completely new to MATLAB and I want to know what my options are
Hello I am new to MATLAB , I wanted to know how can I
Apologies if this is a stupid question, I'm relatively new to Matlab. I've got
I'm very new to MATLAB and I was trying to display a real time
I am new to MATLAB, and I can't fathom this from the documentation. function
I am new to MatLab. I am trying to do some work on image
I'm trying to run a program originally tested on Matlab 6.5 on a new

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.